@acidlemonã«ã¤ãã¦
|'-')/ acidlemonã§ããéåå¸å¨ä½ã§ãéåã§åãæ®éã®ITã¨ã³ã¸ãã¢ã§ãã
30å¹´å¼±ä½ãã åæµ·éãé¢ããéåã§ã¾ã£ããã½ãã½ããã¦ãã¾ãã
ã©ã¼ãããããã§ããã¿ãªããNorikra使ã£ã¦ã¾ãã? ãã£ä½¿ã£ã¦ãªã? ã¾ãã¹ããªã¼ã éè¨å¦çã£ã¦ããã®ããªããªã使ãã©ããé£ããã§ããã®ãã¼ããã£ã½ã©éå ±å¤ãå¿ è¦ãªå ´é¢ãããªãã¨åºçªããªãããã¼ããã¤ã³ã¹ãã¼ã«ãããã©ã»ã¼ä½¿ã£ã¦ãªãã¨ããä»æ¥ãã®é ã§ãã
ã¨ãããã¨ã§! ä»åã¯Norikraã使ãã¨ã£ãããã¨ãã¦ãæè¿ãªãªã¼ã¹ãããµã¼ãã¹ã®ã¦ãã¼ã¯ã¦ã¼ã¶æ°ããªã¢ã«ã¿ã¤ã ã«åºããããªãã¨ãããé¡ãNorikraã§ãã£ã¦ã¿ããã¨ã«ãã¾ããã
ãã¨ãã¨ãã®ãµã¼ãã¹ã§ã¯ãã¤ãã£ãã¢ããªã«Google Analytics SDKãå ¥ã£ã¦ã¦ããã使ãã°ç´è¿5åã®ãªã¢ã«ã¿ã¤ã ã¦ãã¼ã¯ã¦ã¼ã¶æ°ã¯è¦ãã¦ããã®ã§ããããµã¼ãå´ã§ããããè¨æ¸¬ãããã¨ãããã¨ã§ããããNorikraã§ãã£ã¦ã¿ããã¨ã«ãã¾ããã
çç±ã¯ãããåºæ¥ãã¢ããªã ã¨å¹¾ã¤ãç»é¢ãé·ç§»ãã¦ãã¦ãéä¿¡ããªãã¦ããããã«ä½ããã¦ãã¦ãã¯ã©ã¤ã¢ã³ããµã¤ãã®ãªã¢ã«ã¿ã¤ã è¨æ¸¬ã¨ãµã¼ããµã¤ãã®ãªã¢ã«ã¿ã¤ã è¨æ¸¬ã¯ããç¨åº¦å·®ãã§ãã®ã§ã¯? ã¨ãããã¨ã§ãããå¯è¦åãããã¨ããã¨ããã§ãã
ããããã¯å®ä¾ã交ãã説æã«å ¥ãã¾ãã
ã¾ããWebã¢ããªããFluentdçµç±ã§Norikraã¸ãã°ãæµãã·ã¹ãã ãããã¾ãã®ã§ãããã«ã¯ã¨ãªãä»æãã¦ãªã¢ã«ã¿ã¤ã ãªUUè¨æ¸¬ãããã¾ããFluentå¨ãã¯ãã£ããã¨ãããªæãã«ãªã£ã¦ãã¾ã(å®éã®ã·ã¹ãã ã¨ã¯ã¿ã°åçãã¡ãã£ã¨ç°ãªãã¾ã)ã
app.activity
ã¨ããtagã§user_id: 42
ãå«ããããªã¬ã³ã¼ããæµããã¦! ãã¨ã¯Sliding Time Windowã®ã¯ã¨ãªãæ¸ãã¦Norikraã«è¨å®ããã°OKã§ãããããªæãã®ã¯ã¨ãªãæ¸ãã¾ãããã©ãããGoogle Analyticsã®ãªã¢ã«ã¿ã¤ã UUã¯éå»5åã§åã£ã¦ãããããã®ã§ãSliding Time Windowã®å¹ ã¯5åã«ãã¾ãã
SELECT COUNT(DISTINCT user_id) AS active_user FROM activity.win:time(5min)
ã§ããããin_norikraã§åãè¾¼ãã°OKã§ãã
å®éã«ãã£ã¦ã¿ãã¨ããã¼ãããããããã¡ããã¨countãä¸ãã£ã¦ãããã¼ãGoogle Analyticsã®æ°åã¨åããããã«ãªã£ã¦ãã大ä¸å¤«ã£ã½ããªã¼ã¨ããæãã§ãã
ã! ãã®æ¹æ³ã«ã¯é大ãªåé¡ãããã®ã§ãâ¦
ããã¯ä½ãã¨ããã¨ãããã¥ã¡ã³ãã®win:time
ã«ãæ¸ããã¦ããã¨ãããOutput events are generated for every input events.
ã¨ãããã¨ã§å¤§éã®ã¦ã¼ã¶ãã¬ã³ã¬ã³ãããµã¼ãã¹ã ã¨å
¥åã®ãã£ãã¤ãã³ãæ°ã¨åãã ãã®ã¤ãã³ãæ°ã§active_userã®ã¬ã³ã¼ããåãåºããã¦ãã¾ãã®ã§ãâ¦ã
ãã®ã¾ã¾æ¾ç½®ãã¦ãã£ã¹ã¯å®¹éã®ã¢ã©ã¼ããä¸ãã£ã¦ã¤ã³ãã©ãã¼ã ã«è¦ã¤ãã£ããæ¤ åãé£ã¶å¯è½æ§ãããã®ã§ãããã¯ã©ããã¦ãéå¼ãããã§ãã5minã®windowãslideããã¤ã¤10ç§ã«1åã1åã ãã¬ã³ã¼ããã§ããããªã¯ã¨ãªã«åºæ¥ãªãããªãã¨ãããã調ã¹ã¦ã¿ãã®ã§ãããã©ããããã£ã½ãæ¹æ³ãè¦ã¤ããã¾ãããã¨å°ã£ã¦Twitterã§ã¤ã¶ããã¦ã¿ãã¨ãããã¢ãªã¹ããããç確ãªå©è¨ã!
@acidlemon ã¼ã¼ã£ã¨ãã¦ã¦èªã¿éã£ã¦ã¾ãããtime_accum ã¯ãã¡ã§ãããLOOPBACK ã«ã㦠time_batch + LIMIT 1 ãããã®ããª
— tagomoris (@tagomoris) 2014, 10æ 8
ãªãã»ã©! LOOPBACKã£ã¦ä½ã«ä½¿ãã®ãããããããã®ã§å®å ¨ã«ã¹ã«ã¼ãã¦ããã®ã§ããããããã使ãæ¹ããã£ããã§ããã
ã¨ãããã¨ã§ãæçµçã«ä½ã£ãã®ã¯ãããªã¯ã¨ãªã®2æ¬ç«ã¦ã§ãã
SELECT COUNT(DISTINCT user_id) AS active_user FROM activity.win:time(5min)
LOOPBACK(active_user_5min)
sliding_active_user.5min
(ãªãã§ããã)SELECT MAX(active_user) AS active_user FROM active_user_5min.win:time_batch(10sec)
app
suppress_active_user.5min
(fluentã§åãè¾¼ãã¿ã°ã®ä¸é¨ã«ãªã)å¾è ã®ã¯ã¨ãªã10ç§ã«1åã®ãã¼ã¹ã§ç¾å¨ã®5åéUUãåºãã¦ãããã®ã§ããããin_norikraã§åãè¾¼ã¿ã¾ãã
<source>
type norikra
norikra my-norikra:26571
<fetch>
method sweep
target app
tag query_name
tag_prefix norikra.app
interval 5s
</fetch>
</source>
ãã®è¨å®ã§ãFluentã«norikra.app.suppress_active_user.5min
ã¨ããã¿ã°ã§{"active_user": 1234}
ã¨ãããããªã¬ã³ã¼ããæµãã¦ãã¾ãããã¨ã¯ãããé©å½ãªã¨ããã¸æµãã¦ããã°OKã§ãã!
æµãå ã¯ããããããã¨æãã¾ãããRedisã«setããã¨ãWebSocketã«æ¸ãåºãã¨ãzabbixãnagiosãGrowthForecast or Forecuslightã«æããã¨ãMackerelã«æãã¤ããã¨ããããªæãã§ãããã(ã¾ã ããä½ã£ã¦ãªãã®ã§ãã®è¾ºã®ç¥è¦ã¯ããã¾ãã)ã
ä»åã®ã¾ã¨ã: Norikraã§Sliding Time Windowã使ãã¨ãç´è¿âåãã¨ããéè¨ãã§ãã¦ä¾¿å©ã ãã©ãã¬ã³ã¼ãéã大å¤ãªãã¨ã«ãªãã¾ããããã§ãSliding Time Windowã®ã¯ã¨ãªçµæãLOOPBACKã§ä¸åº¦å¥ã¿ã¼ã²ããã«æµãããã®ã¿ã¼ã²ããã«time_batchã¯ã¨ãªãå®æçã«åãã¦ã¤ãã³ãæ°ãéå¼ãã¨ç°å¢ã«åªããéè¨ã§ãã¾ãã!