こんにちは! JQです。
前回は『OSS編~Fluentdでexec_filterを試してみる~』と題して、Fluentdでexec_filterを試してみました。
今回は『OSS編~Fluentdでrewrite_tag_filterを試してみる~』と題して、Fluentdでrewrite_tag_filterを試してみたいと思います。
rewrite_tag_filter
1. Fluetnd設定
今回はrewrite_tag_filterを利用してステータスコードをタグに設定して分けてみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
<source> type tail path /var/log/httpd/access_log format apache2 pos_file /var/log/td-agent/apache.pos tag apache.access </source> <match apache.**> type rewrite_tag_filter rewriterule1 code (.*) $1.${tag} </match> <match 200.**> type file path /var/log/td-agent/ok__ time_slice_format %Y%m%d%H%M time_slice_wait 60s time_format %Y%m%dT%H%M%S%z compress gzip utc </match> <match **.**> type file path /var/log/td-agent/error_ time_slice_format %Y%m%d%H%M time_slice_wait 60s time_format %Y%m%dT%H%M%S%z compress gzip utc </match> |
2. 再起動
再起動をして設定を反映させます。
1 2 3 |
$ sudo /etc/rc.d/init.d/td-agent restart Shutting down td-agent: [ OK ] Starting td-agent: [ OK ] |
3. 確認
それでは確認してみましょう。
実際に200のステータスが出るページと404等が出るページにアクセスしてみます。
正しければ下記のようにログが別れた状態で出力されます。
1 2 3 4 5 6 7 8 9 10 |
$ ls -l total 80 -rw-r--r-- 1 td-agent td-agent 52 Jul 30 17:07 apache.pos drwxrwxrwx 2 td-agent td-agent 4096 Jul 24 16:13 buffer -rw-r--r-- 1 td-agent td-agent 295 Jul 30 17:08 error_.201407300806_0.log.gz -rw-r--r-- 1 td-agent td-agent 222 Jul 30 17:09 error_.201407300807_0.log.gz -rw-r--r-- 1 td-agent td-agent 207 Jul 30 17:09 ok__.201407300807_0.log.gz -rw-r----- 1 td-agent td-agent 43945 Jul 30 17:06 td-agent.log -rw-r--r-- 1 td-agent td-agent 4405 Jul 30 14:12 td-agent.log-20140728.gz -rw-r----- 1 td-agent td-agent 2381 Jul 30 14:12 td-agent.log-20140730 |
中身も正しいか見てみます。
1 2 3 |
$ sudo gunzip ok__.201407300807_0.log.gz $ tail ok__.201407300807_0.log 20140730T080720+0000 200.apache.access {"host":"192.168.0.4","user":null,"method":"GET","path":"/test.html","code":200,"size":null,"referer":null,"agent":"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0"} |
こちらも確認してみます。
codeが200以外がまとめられてます。
1 2 3 4 5 6 7 |
$ sudo gunzip error_.201407300806_0.log.gz $ sudo tail error_.201407300806_0.log 20140730T080645+0000 403.apache.access {"host":"192.168.0.4","user":null,"method":"GET","path":"/","code":403,"size":3839,"referer":null,"agent":"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0"} 20140730T080645+0000 304.apache.access {"host":"192.168.0.4","user":null,"method":"GET","path":"/icons/apache_pb2.gif","code":304,"size":null,"referer":"http://54.210.121.125/","agent":"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0"} 20140730T080646+0000 403.apache.access {"host":"192.168.0.4","user":null,"method":"GET","path":"/","code":403,"size":3839,"referer":null,"agent":"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0"} 20140730T080647+0000 304.apache.access {"host":"192.168.0.4","user":null,"method":"GET","path":"/icons/apache_pb2.gif","code":304,"size":null,"referer":"http://54.210.121.125/","agent":"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0"} 20140730T080651+0000 404.apache.access {"host":"192.168.0.4","user":null,"method":"GET","path":"/index.html","code":404,"size":288,"referer":null,"agent":"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:30.0) Gecko/20100101 Firefox/30.0"} |
いかがでしたでしょうか?
次回もお楽しみに!!!