fluentd-plugin-elasticsearchã§ã®ãã°æå»ã®æ±ã
ããã¾ã§ã®èªåã®Elasticsearché¢é£ã®è¨äºã§ã¯"request_time"ã¨ãã
ç¬èªã«å®ç¾©ããã©ãã«ãç¨ãã¦ç»é²ãè¡ã£ã¦ãã¾ããã
ä¸æ¹ãfluentdã¯"time"ã¨ããã©ãã«ãç¨ããã¨ãã°ã®æå»ãfluentdå
ã§æ±ãã¤ãã³ãã¿ã¤ã ã¨ã¿ãªãã¾ãã
"time"ã¨ããå ´åã¨ããã以å¤ã§fluentd-plugin-elasticsearchã®åä½ã«
éããè¦ãããã®ã§ã¡ã¢ãã¦ããã¾ãã
ã¨ããã§"request_time"ã¨ããã®ã«ã¯çç±ããã£ãã®ã§ããã
ãã®çç±ã¯æ¬çã§ã¯ãªãã®ã§æå¾ã«æ¸ããã¨ã«ãã¾ãã
â ãã°æå»ãé常ã®ã©ãã«ãç¨ãã¦ç»é²ããå ´å
ãã®å ´åã¯ã©ãã«åã"time"以å¤ã«ãã¦ãã¼ã¹ãã¾ãã
ã¤ã¾ãããã¾ã§ã®å ´åã¯"request_time"ã¨ãã¦ãã¾ããã
ãã®æç¹ã§ã¯ä»ã®é
ç®ã¨åãJSON(MessagePack)ã®ä¸é
ç®ãªã®ã§æååã§ãã
ããã¦ãã®ã©ãã«ã«å¯¾ãã¦Elasticsearchのフィールドを日付型としてMappingããã¾ãã
ããã«ããElasticsearchå
ã§"request_time"ã¯æ¥ä»åãã£ã¼ã«ãã¨ãã¦æ±ãããããã«ãªãã¾ããã
å¾ã¯ãã®"request_time"ãã£ã¼ã«ããKibana3ã§time fieldã¨ãã¦è¨å®ãã¾ãã
ä¾ãã°timepickerã®è¨å®ç»é¢ã§ã¯ä»¥ä¸ã«ãªãã¾ãã
indexä½æã«logstashå½¢å¼ãæå®ãã¦ããå ´å(logstash_format true)
logstashå½¢å¼indexã®æ¥ä»ã¯ãã°ãimportããfluentdã§èªã¿è¾¼ãã æ¥ä»ã«ãªãã¾ãã
ã¨ããã§ä¸è¨ç»åã®time fieldã«ã¯ããã©ã«ãã§ã¯"@timestamp"ãè¨å®ããã¦ãã¾ãã
@timestampãã£ã¼ã«ãã¯ã©ããã£ãã使ããã®ã§ããããï¼
â¡fluentdã§"time"ã©ãã«ã使ã
ãã®çãã¯fluentdã®"time"ã©ãã«ã«ããã¾ããã
fluentdã®ãã¼ã¹ã以ä¸ã®ããã«è¨å®ããã¨ãã¾ãã
format /^(?<host>[^ ]*) [^ ]* (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)")?$/ time_format %d/%b/%Y:%H:%M:%S %z
ãã®å ´åãè¨äºã®åé ã§ãæ¸ãã¾ããããã°æå»ã¯fluentdã®ã¤ãã³ãã¿ã¤ã ã¨ãã¦æ±ããã¾ãã
詳ããã¯æ¸ãã¾ãããJSONããã£é¨ã¨ã¯ç°ãªãæ±ãã«ãªãã¾ãã
ããã¦fluentd-plugin-elasticsearchã§logstashå½¢å¼ã«è¨å®ããã¨ã
"time"ã"@timestamp"ãã£ã¼ã«ãã«ç»é²ããã¾ãã
æ´ã«ãã®å ´åãlogstashå½¢å¼indexåããã°æ¥ä»ã«è¿½éãã¾ãã
ã¤ã¾ãããã°æ¥ä»ã¨åãæ¥ä»ã§lostash-YYYY.MM.DDãªindexãä½æããã¾ãã
fluentdã®ãã¼ã¹ã®æç¹ã§ã¡ããã¨è¨å®ãã¦ããã°ã
èªåçã«ãã°ã®å
容ã«ãã£ãç»é²ããããã¨ãããã¨ã§ããã
ãªããlogstashå½¢å¼ã§ã¯ãªãèªåã§indexåãæå®ããå ´åã¯
"@timestamp"ãã£ã¼ã«ãã¯åºæ¥ã¾ããã§ããã
ãã 以åã«è©¦ããæã¯ãã°ç»é²æå»ã§è¨å®ããã¦ãæ°ãããã®ã§ã³ã³ã¯æªããã§ãã
ï¼è¿½è¨ï¼ç¢ºèªãã¾ãããlogstash_format trueãªãï¼ timestampãã£ã¼ã«ããä½ããããã
ããã§ãªãå ´åã¯@timestampãã£ã¼ã«ãã¯ä½ãããªããã§ãã
ããããããªãæåãã"time"ã使ãã"request_time"ã«ãã¦ãã®ãã§ããã
fluentdã®æ£è¦è¡¨ç¾ãæ¸ãã®ã«@tagomorisさんのサイトãåèã«ãã¹ããã¦ããã®ã§ããã
ãrequire 'time'ããè¦è½ã¨ãã¦è¨å®ãã¦ãªãã£ãã°ã£ããã«
ããããã£ã¦ã"time"ã¨ãã¦ãã¼ã¹ããã®ã«å¤±æããã®ã§
諦ãã¦æååãªãã£ã¼ã«ãã¨ãã¦åå¾ããããã«ãã¡ãã£ãã¨ãããªãã§ããã
éæãããã¦ã©ããããããªãã§ããããã