KibanaåãFluentdè¨å®ä¾â ã¢ã¯ã»ã¹ãã°å¯è¦å
ã©ã¡ããã¨ããã¨Fluentdã®è¨å®ã®è©±ãªã®ã§ããã
Kibanaä¸ã§ãã¼ã¿ãæ±ããã¨ãèæ
®ãã¦ããããã®æãã§ã
ã¢ã¯ã»ã¹ãã°ã®å¯è¦åã¯ãããããã¤ãªã®ã§ç´°ããæã¯é£ã°ãã¾ãã
1段ç®ï¼ãã°åéå ããã®è»¢éè¨å®
<source> type tail path /path/to/apache_access.log format /(?<message>.*)/ pos_file /var/log/td-agent/apache_access.pos tag apache.access.HOSTNAME </source> <match **> type forward flush_interval 1s <server> host FORWARD_HOST </server> </match>
以前の記事ã§ã¯in_tail
ã«ãã¼ã¹ãæ¸ãã¦ãã¾ãããã
ãã©ã¡ã¼ã¿ãå¢æ¸ããã®ã«æ¯å対å¿ãããããã¼ã¹ããããã®è² è·ãããããã¨ãèããã¨ã
ãã°åéãã¹ãä¸ã®in_tail
ã§æ£è¦è¡¨ç¾ãã´ãªã´ãªæ¸ãã®ã¯ãã¾ãå¾çãããªãæ°ããã¦ãã¾ãã
ããã§1è¡ã1ã¡ãã»ã¼ã¸ã¨ãã¦éããããªè¨å®ã«ãã¦ãã¾ãã
fluentdã0.10.39以éã§ããã°format none
ã¨ãããã¨ã§åæ§ã®ãã¨ãåºæ¥ã¾ãã
åéãã°ã«æ¥ä»ãä»ä¸ããå ´åã¯in_tail
ã®å¤ããã«fluent-plugin-tail-ex
ã使ãã¨ããã§ããã
2段ç®ï¼ãã°åä¿¡å´ãã¼ã¹
<source> type forward </source> <match apache.access.**> type parser add_prefix parsed format /(æ£è¦è¡¨ç¾)/ time_format %d/%b/%Y:%H:%M:%S %z key_name message </match>
ããããã¯ãã°è§£æãµã¼ãä¸ã§ãã
forwardãããã¤ãã³ããfluent-plugin-parser
ã§ãã¼ã¹ãã¾ãã
key_name
ã«ã¯è§£æããããã£ã¼ã«ãåãããã§ã¯messageã«ãªãã¾ãã
format
ã«ã¯æ£è¦è¡¨ç¾ãæ¸ãã¾ããããã°ãã©ã¼ãããå´ã§LTSV
ã«ãã¦ããã°
format ltsv
ããã ãã§ããã¦æ¥½ã§ããã
3段ç®ï¼ãã¼ã¿å å·¥
<match parsed.apache.access.**> type record_reformer output_tag reformed.${tags[1]}.${tags[2]} ip ${forwardedfor[/([^,]*),*/,1]} method ${req[/^([^ ]*) .*$/,1]} uri ${req[/^[^ ]* ([^ ]*) .*$/,1]} sessionId ${req[/^[^ ]* \/path\/to\/api\?sessinId\=(.*?)(\¶m\=[^ ]*)? .*$/,1]} log_host ${tags[3]} </match>
2段ç®ã®æç¹ã§çã®ãã¼ã¿ãæ±ãåã«ã¯ååãªã®ã§ããã
æã«ã¯ãã¼ã¿å å·¥ãããå ´åããããfluent-plugin-record-reformer
ã便å©ã§ãã
æ´å½¢ãããã¼ã¿ãçã®ã¬ã³ã¼ãã«ï¼Î±ãã¦ãããã®ãè¯ãã§ãã
ãããè¤æ°é
ç®æ¸ãã¾ãã
ä¾ãã°ãreq (refereræ
å ±)ãã«ãGET /path/to/api?sessionId=10000001¶m=1 HTTP/1.0ã
ã¨ããæ
å ±ãå
¥ã£ã¦ããã¨ãã¦ã1ã¤ç®ãmethodã2ã¤ç®ã®é¨åãuriã¨ãã¦åãåºãã¦ãã¾ãã
ãããã¯uriå
¨ä½ã§ã¯ãªããgetãã©ã¡ã¼ã¿ã«å
¥ã£ã¦ããsessionIdãåãåºããããã¾ãã
ã¾ãforwardedforã«ã¯proxyãéãã¨ã«ã³ãåºåãã§è¤æ°ã®ã¢ãã¬ã¹ãå
¥ã£ã¦ããã®ã§ã
1çªå
é ã ããåãåºãã¦ç¶ãgeoipã®å¤å®ã«ä½¿ãã¾ãã
æ´å½¢ã¯${ãã£ã¼ã«ãå[/(æ£è¦è¡¨ç¾)/,n]}
ã®ããã«æ¸ãã¦åãåºãããé¨åãã°ã«ã¼ãåãã¦
nã§ä½çªç®ã®ã°ã«ã¼ããåãåºãããããæå®ãã¾ãã
ãã®è¾ºãã¯rubyã®æ£è¦è¡¨ç¾ã®ã¨ãæ±ãã«ãªãã®ã§ã
rubyã®ã³ã³ã½ã¼ã«ã¨ãã§å°ã試ãã¦ã¿ãã°ãããããã¨æãã¾ãã
log_hostã¯以前の記事ã§fluent-plugin-elasticsearch
ä¸ã§tag_key @log_name
ã§è¡ã£ã¦ãã
åéå
ãã¹ãã®ç»é²ãããã§è¡ãããã«å¤æ´ãããã®ã§ãã
fluent-plugin-elasticsearch
ã®tag_key
ã ã¨tagãããªããã¾ããã¨ç·¨éããå¿
è¦ãããã¾ãããã
tags
使ãã¨ç°¡åã«å¿
è¦ãªé¨åã ãåãåºãã¾ããã
${tags[3]}
ã¯tagãã«ã³ãã§åå²ãã4çªç®ãåå¾ãã¦ãã¾ãã
ãªããfluent-plugin-record-reformer 0.1.1
ããã¯fluent-plugin-forest
ã¨è¡¨è¨ãåããã¦
tag_parts
ã使ããããã«ãªãã¾ãã
ä»åã®è¨äºã®ãã¤ã³ãã¯ã»ã¼3段ç®ã«éç´ããã¾ãã
methodãuriã¯ãã°ãã©ã¼ãããã§ç´æ¥æå®ããã°å å·¥ããªãã¦ãæ¸ã¿ã¾ããã
æ¢ã«éç¨ããã¦ãããããªå ´åã«åºåå
ã«å¤æ´ãå ããã®ãç°¡åãããªãå ´åãå¤ããã
ããããå ´åã«åãåã£ãå
ã§ç°¡åã«å å·¥ã§ããã¨ããä¾ã§ãã
4段ç®ï¼
<match reformed.**> type geoip geoip_lookup_key ip enable_key_country_code geoip_country add_tag_prefix es. </match>
fluent-plugin-geoip
ç¨ã®è¨å®ã
pluginã¨ã¯å¥ã«ã©ã¤ãã©ãªã®ã¤ã³ã¹ãã¼ã«ãå¿
è¦ãªã®ã§æ³¨æãã¦ãã ããã
ããã¾ã§è¦ã¦ãã¦pluginæ¯ã«tagã®æ±ãæ¹ãç°ãªãã®ã§è¥å¹²æ··ä¹±ãã¾ããã
5段ç®ï¼
<match es.reformed.**> type forest subtype elasticsearch remove_prefix es.reformed <template> type_name ${tag} host localhost port 9200 logstash_format true logstash_prefix logstash flush_interval 10s </template> </match>
fluent-plugin-elasticsearch
ã¯placeholderã«å¯¾å¿ãã¦ãªãã®ã§fluent-plugin-forest
æ¨å¥¨ã
fluent-plugin-record-reformer
ã§ã®output_tag
ã¨ã®çµã¿åããã«ãã
type_name
ã«å
¥ãå¤ã¯ä»åã®ä¾ã§ã¯ãapache.accessãã¨ãªãã¾ãã
以åã¯type_nameãhoståãªãããç»é²ããã®ã«tagæä½ãçµæ§å¤§å¤ã§ãããã
tagã®placeholderã便å©ã«ãªã£ããé°ã§ããªã楽ã«ãªãã¾ããã
fluentdã§ã¯ãããªæãã§ãã°åºåãããæãã«å å·¥ãã¦ãã¼ã¿ã¹ãã¢ã«æå
¥ã§ãã¾ãã
Kibanaé¢ä¿ãªããããªããã£ã¦è¨ããããã§ãããKibanaã§è¡¨ç¤ºããå
容ãèããçµæã
fluent-plugin-record-reformer
ã§éä¸ã§å å·¥ããã®ã便å©ã£ã¦ãã話ã§ãã
Kibanaã§è§£æããã¨ãã«ã¦ã¼ã¶IDãã»ãã·ã§ã³IDã¿ãããªã®ãfacetéè¨ãããäºä¾ã¯ããããã¨æãã®ã§ã
åãåºãã¦ããã¦mappingãnot_analyzed
ã§ç¨æããã¨ã©ã³ãã³ã°éè¨ããããã§ããã
Kibanaä¸ã§ã¯terms
ããã«ã§å¯¾è±¡é
ç®ãæå®ããã ãã§è¡¨ç¤ºã§ãã¾ãã
ããã©ã«ãã§5é
ç®ã«ãªã£ã¦ããã©æ°åãå¢ããã°ãã£ã¨è¡¨ç¤ºå¯è½ã
ï¼1000ãããã«ã¯ãããã¨ããï¼
åèä¾ãæ¬å½ã¯ãã£ã¨ã©ã³ãã³ã°ã½ãã®åºãããã£ããã©æå
ã«åºãããã¼ã¿ããªãã
3ã¤ä¾ãæ¸ãã¤ããã ã£ããã©ã調æ»ä¿®æ£ãã¦å確ãã¦ããããã£ã¦æéããã£ã¦ãã¾ã£ãã
record_reformerã¯åã«è¨å®æ¸ããæç¹ã§ã¯tag_parts
使ãã¦ããã ãã©ã
æå
ã§å®æ½ããã0.1.1ã§ã¯ãªã0.1.0ãå
¥ã£ã¦ãã¾ã£ã¦ä½¿ããªãã£ããã
Elasticsearch-1.0.0.Beta2ã使ã£ãã0.90.7ã§åãã¦ãmapping templateãåããªãã£ãã
è¨äºã¯æ¸ãããã®ã®è²ã
ã¨èª¿æ»ãããã®ãå¢ãã¦ãã¾ã£ãã»ã»ã»