Esper入門紹介:四、上編の三人で簡単なアラーム効果を実現しましょう。

6334 ワード

/**
	 * Chapter 3. Processing Model
	 * 3.7. Aggregation and Grouping
	 *        
	 * 
	 * @see http://www.espertech.com/esper/release-5.2.0/esper-reference/html_single/index.html#processingmodel_aggregation
	 *      http://www.espertech.com/esper/release-5.2.0/esper-reference/html_single/index.html#config-variables
	 *      http://www.espertech.com/esper/release-5.2.0/esper-reference/html_single/index.html#variable_using
	 *      http://www.espertech.com/esper/release-5.2.0/esper-reference/html_single/index.html#config-engine-variables
	 * 
	 * @param eventBean
	 * @return
	 * @throws InterruptedException
	 */
	@Test
	public void test_() throws InterruptedException {
		HttpLog httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now());
		esperTemplateBean.sendEvent(httpLog);
		httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now());
		esperTemplateBean.sendEvent(httpLog);
		httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now());
		esperTemplateBean.sendEvent(httpLog);
		httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now());
		esperTemplateBean.sendEvent(httpLog);
		httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now());
		esperTemplateBean.sendEvent(httpLog);
		httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now());
		esperTemplateBean.sendEvent(httpLog);
		TimeUnit.SECONDS.sleep(10);

		httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now());
		esperTemplateBean.sendEvent(httpLog);
		httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now());
		esperTemplateBean.sendEvent(httpLog);
		httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now());
		esperTemplateBean.sendEvent(httpLog);
		httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now());
		esperTemplateBean.sendEvent(httpLog);
		httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now());
		esperTemplateBean.sendEvent(httpLog);
		httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now());
		esperTemplateBean.sendEvent(httpLog);
		httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now());
		esperTemplateBean.sendEvent(httpLog);
	}
Esperのプロファイルには次のような変数が定義されています。



	
	
	
	
	
		
			
				
			

			

		
		
	
	
s
    変数を定義します。
esper-springプロファイル:
	
上のEPL表式は、10秒以内のHttp Logを分析し、この10秒でIDが6回出たらモニターを起動し、ここでは予約者を使って、警報を出す。ここではログでしか出力しない。
出力内容:
06-20 18:03:11.027 main  WARN  c.d.e.s.HttpLog Subscriber-    アラームしきい値httplog{id}:1、「Machinese Id」:「2891816 a-9272-c 11-b 510-8481 ea 829778」、「referereer」:「www.baidu.com」、「requestPath」:「www.baidu.com/tiebaba」、「tiemame」21.0:「2015-2018 T 066アクセス」  WARN  c.d.e.s.HttpLog Subscriber-    アラームしきい値httplog{id}:1,“machinese Id”:“830 bf 9 a-b 625-4 a 38-9 e 61-367 a 1 a 661”,“refererererereferer”:“www.baidu.com”、“requestPath”:“www.baidu.com/21.01”、“time 06”、“time”、“T 066”を超えます。  WARN  c.d.e.s.HttpLog Subscriber-    アラームしきい値httplog{id}:1,“machinese Id”:“571 c 8281-7 a 1 e-48 bd-a 10 b-200 b 0726 fe”、“referer”:“www.baidu.com”、“request Path”:“www.baidu.com/tiebaba”、“tieba”、“time”:“2035-2015”、“T 067” 
解析:6つのHttpLogと同じイベントを送信すると、予約者を触発し、警報情報を出力し、その後10秒の休止状態になる。時間ウィンドウ内のイベントは期限が切れました。そして私たちは7つの同じイベントを送り続けます。最後の二つは必ず警察に通報します。
使用しましたhttps://github.com/opencredo/opencredo-esper/tree/master/esper-template のesper-springはコードを結び付けます(そして小さい部分の調整をして、そのXMLの配置の方式を使いません)。
ここで、Esperに関するウェブサイトを共有します。
esper-2015
エスパー学習
http://www.espertech.com/esper/
http://josh-persistence.iteye.com/category/307677
https://github.com/opencredo/opencredo-esper
https://github.com/opencredo/esper-custom-aggregator
https://github.com/opencredo/opencredo-esper
https://github.com/pulsarIO/jetstream-esper
https://github.com/pulsarIO
https://github.com/tomdz/storm-esper
https://github.com/corsoft/esper-demo-nuclear
https://github.com/hellojinjie/storm-esper-example
http://esper.13850.n7.nabble.com/Esper-User-list-f3.html (これらは全部私のgithubに保存されました)