Skip to content

Instantly share code, notes, and snippets.

@y-ken
Last active November 19, 2019 08:11
Show Gist options
  • Save y-ken/5012985 to your computer and use it in GitHub Desktop.
Save y-ken/5012985 to your computer and use it in GitHub Desktop.
流れに乗ってnginxのログフォーマットにLTSVを採用しました。 2013/03/05リリースのfluentd-0.10.32.gemなら標準のin_tailで、format ltsvとする事でそのまま読み込めます。 proxy先からの応答時間や送出したcookieも記録する汎用的な設定です。
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format ltsv 'domain:$host\t'
'host:$remote_addr\t'
'user:$remote_user\t'
'time:$time_local\t'
'method:$request_method\t'
'path:$request_uri\t'
'protocol:$server_protocol\t'
'status:$status\t'
'size:$body_bytes_sent\t'
'referer:$http_referer\t'
'agent:$http_user_agent\t'
'response_time:$request_time\t'
'cookie:$http_cookie\t'
'set_cookie:$sent_http_set_cookie\t'
'upstream_addr:$upstream_addr\t'
'upstream_cache_status:$upstream_cache_status\t'
'upstream_response_time:$upstream_response_time';
access_log /var/log/nginx/access.log ltsv;
...snip...
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $http_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
include /etc/nginx/conf.d/*.conf;
}
<source>
type tail
path /var/log/nginx/access.log
format ltsv
time_format %d/%b/%Y:%H:%M:%S %z
tag td.nginx.access
pos_file /var/log/td-agent/nginx_access.pos
</source>
<source>
type tail
path /var/log/nginx/error.log
format /^(?<time>.+) \[(?<level>[^\]]+)\] *(?<message>.*)$/
time_format %Y/%m/%d %H:%M:%S
tag td.nginx.error
pos_file /var/log/td-agent/nginx_error.pos
</source>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment