Fluentdを通じてNginxのロッグを一箇所に集中しビジュアルにしたいです。
参考資料にこう書いてあルのは多いです:
<source>
type tail
format nginx
path /var/log/nginx/access.log
pos_file /var/log/td-agent/nginx-access.pos
tag nginx.access
</source>
実はこうしてパータンは認識されていません。(エラーログが出ています)
2015-04-03 10:55:49 +0000 [warn]: pattern not match: "192.168.33.1 - - [03/Apr/2015:10:55:49 +0000] \"GET /js/header.js HTTP/1.1\" 200 2988 \"http://gg.dev.com/\" \"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.101 Safari/537.36\" \"-\""
その[warn]: pattern not matchはエラーです。
NginxのローグフォーマットはApacheと異なり、そのまま解析できないらしいです。
こう修正すれば問題解消します。
...
pos_file /var/log/td-agent/nginx-access.pos
format /^(?<remote>[^ ]*) (?<host>[^ ]*) (?<user>[^ ]*) \[(?<time>[^\]]*)\] "(?<method>\S+)(?: +(?<path>[^ ]*) +\S*)?" (?<code>[^ ]*) (?<size>[^ ]*)(?: "(?<referer>[^\"]*)" "(?<agent>[^\"]*)" "(?<forwarder>[^\"]*)")?/
time_format %d/%b/%Y:%H:%M:%S %z
...