Help us understand the problem. What is going on with this article?

nginx のログを fluentdに流す(pattern not match対策)

More than 3 years have passed since last update.

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
...

参考資料:http://bynatures.net/wordpress/1951/

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした