以åã«ãã¼ã¿ãå¯è¦åããæ段ã®ä¸ã¤ã¨ãã¦InfluxDB+Grafanaã«ã¤ãã¦èª¿ã¹ã¦ããããã©ã ãã®æã¯å°å ¥ãã¦ãã¼ã¿æå ¥ãã¦åãã段éã§æºè¶³ãã¦ãã¾ã£ã¦ããã
ãããããã¦ããéã«ãã¼ã¸ã§ã³ã¯1.0ãåããã¡ããã©ä½¿ãããæ¡ä»¶ããã£ãã®ã§ã æ¹ãã¦ããå°ãçé¢ç®ã«ä½¿ãæ¹ã調ã¹ã¦ã¿ãã
ããããæç³»åãã¼ã¿ãã¼ã¹ãªããã®ã¯ä½ãã®ãªã®ã
ãã¡ããæç³»åãã¼ã¿ãæ±ããããããããã¨ã¯ååããæããã ãã©ã å ·ä½çã«ã©ã便å©ãªã®ãã¨ããé¨åãæ£ç´ãªã¨ããç解ãã¦ããªãã£ãã
ã©ãã¾ã§æç³»åãã¼ã¿ãã¼ã¹ä¸è¬ã®è©±ãã¯åãããªããã InfluxDBãå®éã«ä½¿ã£ã¦ã¿ã¦ããããªãã»ã©ãããã便å©ã ãã¨æã£ãã®ã
- ã¹ãã¼ãã¬ã¹ãªã®ã§è¦ç´ ã®å¢æ¸ã«æè»ã«å¯¾å¿ã§ãã
- æç³»ã§å¤åãããã¼ã¿ãéè¨ããã®ã«ä¾¿å©ãªæ©è½ãæã£ã¦ãã
- å¤ããã¼ã¿ãèªåã§åé¤ãã¦å®¹éãåæ¸ã§ãã
- æéãã¨ã®å¦çãå®ç¾©ã§ãã
ãããã ãããã
ã¹ãã¼ãã¬ã¹
InfluxDBã¯JSONã®å½¢ã§ãã¼ã¿ãæå ¥ããã
å®å ¨ãªèªç±å½¢ã¨ããããã§ã¯ãªãã
- ãã¼ã¿ã®ã¿ã¤ã ã¹ã¿ã³ã
- æ ¼ç´ããã·ãªã¼ãºï¼RDBMSã§ãããã¼ãã«ã¿ãããªæ¦å¿µï¼
- ä¿åãããå¤
- å¿ è¦ã«å¿ãã¦ã¿ã°ï¼åã¯ã¤ã³ãã£ãã¯ã¹ã«ã©ã çãªãã®ã ã¨æã£ã¦ãï¼
ãå«ãã ãã¼ã¿ãæ¿å ¥ãããã¨ã«ãªãã
ï¼çã®APIããæãè¾¼ããªããã®ããããåèã«ãªãã ããã Querying Data with the HTTP API | InfluxData Documentation ï¼
ãªã®ã§NoSQLçã«é©å½ã«æ¾ãè¾¼ãã§OKã¿ãããªãã®ã§ã¯ãªãã¦ããç¨åº¦æ´å½¢ãã¦ããå¿ è¦ããããã å¤ãã¿ã°ã«é¢ãã¦ã¯éä¸ãã追å ãããã¨ãã§ããã
RDBMSã§ãã°åéã¿ãããªãã¨ããããã¨ããã¨è¨è¨æã«ã¯æ³å®ãã¦ããªãã£ããã©ã¡ã¼ã¿ãåºã¦ããã¨ãã«é ãçãã£ããããã®ã ãã ãã®ãããã®æ©ã¿ããéæ¾ãããã
æç³»åã§ã®éè¨æ©è½
InfluxDBã¯SQLã©ã¤ã¯ãªã¯ã¨ãªãçºè¡ãã¦æè»ã«ãã¼ã¿ã®æä½ãè¡ããã®ã ãã ããã§æç³»åãã¼ã¿ãæ±ãéã«ä¾¿å©ãªã³ãã³ããå¤ãç¨æããã¦ããã
以ä¸ã®ãããªãã¼ã¿ãæ³å®ããã
ä¾ãã°30ç§ãã¨ã®å¹³åå¤ã®æ¨ç§»ãå¾ããã¨æã£ãã¨ãã ãããMySQLãªãçµæ§é¢åãªã¯ã¨ãªãè¨è¿°ãããã ãããã¯æ¾ã£ããã¼ã¿ãå å·¥ããã¹ã¯ãªãããæ¸ãå¿ è¦ãããã ããã
ã ããInfluxDBã§ããã°ä»¥ä¸ã®ã¯ã¨ãªã§äºè¶³ããã
SELECT mean(value) FROM series WHERE time >'2016-07-03T15:00:00Z' and time < '2016-07-03T16:00:00Z' GROUP BY time(30s)
æ´ã«ã空ç½ã«ãªã£ã¦ãã¾ãæéãåããå¿
è¦ãããå ´åãªã©ã¯GROUP BY 30m FILL(previous)
ã¨è¨è¿°ããã¨ã
åã®æéã®æ°å¤ã§åãã¦ãããã
ä¸å®æãªææ¨ãçµ±è¨ãã¼ã¿ã¨ããéã«é常ã«å½¹ã«ç«ã¤ã ããã
ãã¼ã¿ã®èªååé¤
InfluxDBã§ã¯ã·ãªã¼ãºãã¨ã«Retention Policyã¨ããæ©è½ãç¨ãã¦ãã¼ã¿ã«æéãæããã èªåçã«å®¹éãåæ¸ãããã¨ãã§ããã
ä¾ãã°ä»¥ä¸ã®ãããª1æ¥çµéã§ãã¼ã¿ãæ¶ããããªããªã·ã¼ãä½æããã¨ããã
CREATE RETENTION POLICY "rp_daily" ON "db_name" DURATION 1d REPLICATION 1
ããã¨ãrp_daily.hogehoge
ã«æ¸ãè¾¼ã¾ãããã¼ã¿ã¯ãã¿ã¤ã ã¹ã¿ã³ãã1æ¥åã«ãªã£ããã®ããèªåã§æ¶ãããã¨ã«ãªãã
ï¼å ã«ã·ãªã¼ãºããã¼ãã«ã¿ãããªãã®ã¨è¨ã£ãããæ£ç¢ºã«ã¯ããªã·ã¼ã¨ã»ããã§ãããããªã·ã¼é¨åãçç¥ããã¨ãããã©ã«ãã®ããªã·ã¼ã®ãã®ãåç §ããããï¼
RDBMSã§ãã°çãªãã®ã管çãããã¨ããã¨ã å¢ãç¶ããã¬ã³ã¼ãã«å¯¾ãã¦å®æçã«åæ¸ãããããªããããåãï¼ãããã¯ææã§å®¹éãå¢ãã¦è§£æ±ºãããï¼ãã¨ã«ãªããã ãããInfluxDBå ã§å®ç¾©ãããã¨ãå¯è½ãªã®ã ã
ãã¼ã¿ã®èªåéè¨
é次éç´ãã¦ããçãã¼ã¿ãå®æçã«éè¨ããããªã©ã¨ãããã¨ããµã¼ããµã¤ãã§ã¯ãããã¡ãªä»äºã ãã ãããInfluxDBã®Continuous Queryã¨ããæ©è½ãç¨ãããã¨ã§èªåã§ããªãã¦ãããã
( Continuous Queries | InfluxData Documentation )
ä¸è¨ã®ãããªã¯ã¨ãªã«ããå®ç¾©ãä½æããã
CREATE CONTINUOUS QUERY "cq_summary" ON "database" BEGIN SELECT mean("value") INTO "rc_long"."summary_data" FROM "rc_short"."row_data" GROUP BY time(30m) END
å ã«è¿°ã¹ããããªGROUP BYãç¨ããéç´ã¯ã¨ãªãINTOå¥ã§æå®ããã·ãªã¼ãºã«æ¿å ¥ããã
ä¾ãã°çãã¼ã¿å´ã«çãã®Retention Policyãéç´å´ã«é·ãã®Retention Policyãé©ç¨ãããã¨ã§ã ãæè¿ã®ãã¼ã¿ã¯è©³ç´°ãç¥ããããã©ãæã®ãã¼ã¿ã¯å¤§ä½ã®å¾åãåããã°è¯ããã¿ãããªè¦ä»¶ã«å¯¾å¿ã§ããã
ãããªãããªã§åèªèº«ãã¾ã 使ãå§ããã°ãããªã®ã ãã©ã InfluxDBã®ä¾¿å©ãã«é©ãããæåãããããã¦ããä»æ¥ãã®é ã
éå»ãæ¯ãè¿ãã¨ãä»ãªãInfluxDBãé©ç¨ããã°è§£æ±ºã§ããããªæ¡ä»¶ãããã¤ãæãå½ããã
ãªããªã便å©ãããªãããã¯ããªã®ã§ãå人çã«ã¯ã©ãã©ã使ã£ã¦ãã£ã¦ã¿ããã