Elasticsearchã«fluentdããè¨å®ã¨ãlabelã®è©±
ã¨ãã£ã¦ãè¨å®ã¯ãã»ã©é£ãããªãã§ãã
åéç®æããç´æ¥éä¿¡ããå ´åã¯コチラãåç
§ããã¨ãããããªæãã
èªåã®å ´åãåéç®æã¨éè¨ãµã¼ã両æ¹ã«td-agentå
¥ãã¦ã¦ã
åéç®æã¯tail_exã¨forwardãéè¨ãµã¼ãã§éè¨ãã¦growthforecastã«æãã¦ããã
ä»åã®å ´åãå¾ããElasticsearchè¨å®è¿½å ããããã¦ã¾ãã
æ¬çªã§growthforecastã¨Elasticsearchãåããµã¼ãã«å
¥ããªãã¨æããã©ã
ä»ã¯ãã¹ãç°å¢ã¨ãããã¨ã§ã
以ä¸ã¯éä¿¡å´è¨å®ã
<source> type tail_ex format /(æ£è¦è¡¨ç¾)/ path /path/to/apache.log.%Y%m%d tag apache.${HOSTNAME} pos_file /path/to/apache.pos </source> <match apache.*> type forward flush_interval 1s <server> host ${FORWARD_HOST} </server> </match>
éä¿¡å´ã¯ãªãã¦ãã¨ã¯ãªãè¨å®ãªãã§ããããã¤ã³ãã¯tagã®HOSTNAMEãªã®ããªã¨ã
Elasticsearchå
ã§hostæ¯ã«æ¤ç´¢ãããå ´åã¯tagããlog_nameã«å
¥ãããã
record-modifierã§é
ç®ã®ä¸ã¤ã¨ãã¦å
¥ãã¦ãã¾ããã©ã£ã¡ãã«ãªãã¨æãã¾ãã
éè¨ãµã¼ãã¿ãããªæ§æã®å ´åãtagã«ã¤ãã¦ãã¨matchã§å¯¾è±¡ãå¶å¾¡ãã§ããã®ã§ãããã
ãªãã${HOSTNAME}ã¨${FORWARD_HOST}ã¯ã·ã§ã«ã¨ãChefã§åãã¦ã¾ãã
tail_exã®æ©è½ï¼ã§${hostname}ã£ã¦tagã«ä½¿ããã®ã§ããã
å å·¥ããhoståã使ãããã£ãã®ã§è¨å®æã«åããããã«ãã¾ããã
éè¨ãµã¼ãå´ã®è¨å®ã¯ä»¥ä¸ã
<source> type forward </source> <match apache.**> type copy <store> type forest subtype elasticsearch remove_prefix apache <template> type_name apache include_tag_key true tag_key @log_name host localhost port 9200 logstash_format true flush_interval 10s </template> </store> </match>
å®éã«ã¯storeãã£ã¨ãããã©ãElasticsearchã«é¢ä¿ãªãã¨ããã¯çç¥ãã¾ããã
転éå
ããã¯tagããapache.hostãã®å½¢ã§æµãã¦ãã¦ã
remove_prefixããã¦@log_nameã«ã¯ãhostãã®å½¢ã§ç»é²ããã¾ãã
ããã«ããElasticsearchä¸ã§ã@log_name="host"ããªæ¤ç´¢ãã§ãã¾ãã
ã¾ããããã¾ã§ããªãã¦ãElasticsearchã¯å
¨ææ¤ç´¢ã¨ã³ã¸ã³ãªã®ã§ã
ãapache.hostãã®ã¾ã¾ã§ç»é²ããã¦ãã@log_name="host"ãã§çµãè¾¼ã¿åºæ¥ãã¯ãã
ãããªæãã§fluentdã§ç°¡åã«Elasticsearchã«ãã¼ã¿æå
¥ã§ãã¾ãã
Elasticsearchã«ã¯bulk_importããæ¹æ³ãç¨æããã¦ããã®ã§ããã
JSONã§indexæå®ãidä»ä¸ããå½¢ã«æ´å½¢å¿
è¦ã ã£ããã¨ããããã£ã¦ã¾ããã
éå»ãã°ã§ãfluentdçµç±ã§å
¥ãã¦ã¾ããfluentd便å©ï¼
ãã¨fluentd-plugin-elasticsearchæ¸ãã¦ããã人ã®ãããã
ã¨ããã§ãElasticsearchã«é¢ããããã°è¨äºæ¸ãã¦ãéä¸ã«æ°ã¥ãããã§ããã©ã
èªåã®labelåããã¾ãæ¨æºçã§ã¯ãªããã®ã«ãªã£ã¦ãæ°ãããã
å
ã
ã¯fluentdå
¬å¼ã®apache2ã®æ¸å¼ããã¼ã¹ã«æ£è¦è¡¨ç¾ãæ¸ãã¦ã¾ãã
ï¼http://docs.fluentd.org/ja/articles/in_tailãã®ä¸ã»ã©ã®ãapache2ãï¼
ããã«å¯¾ãã¦è¿½å ãã©ã¡ã¼ã¿ã®ä¸é¨ã®é
ç®åãä¼¼ããããªã®ããã£ãé¨åãè£
飾ãããã
timeã®ãã¼ã¹ããã¾ããããªãã¨èª¤è§£ããããã«request_timeã«ãããã
ã¨ãããæè¿LTSVお勧めã¨ããã®ããããã¨ãç¥ãã¾ããã
æ¯è¼ãã¦ã¿ã¾ãã¨ã
apache2ã§ã®log_format | èªåã®label | fluentdãµã¤ãã®label | ltsv.orgã®recommended label |
---|---|---|---|
%t | request_time | time | time |
%>s | code | code | status |
%b | res_size | size | size |
%{User-agent}i | agent | agent | ua |
%l | req_size | - | reqsize |
%D | response_time | - | reqtime_microsec |
%T | - | - | reqtime |
ç¹ã«request_timeãéãç¨éãªã®ã«è¢«ã£ã¦ãã®ãæ³£ãããã
ã¨ãã£ã¦ãæ¥ã«å¤ããããªãã®ã§ã¹ãã¼ãã®è¨å®ã¯æ°ãã¤ãã¾ãããã
ã¨ããæ®å¿µãªãªãã
ç§ã®Elasticsearchã®è¨äºãè¦ãéã«ã¯ãã©ã¡ã¼ã¿ã«ã¯ã注æãããã
ï¼è¿½è¨ï¼「fluentd-plugin-elasticsearchでのログ時刻の扱い」