LoginSignup
0
0

More than 5 years have passed since last update.

nginxのerror.logをtd-agentを使用してtreasure data送る

Last updated at Posted at 2016-09-06

環境

  • OS:Amazon Linux AMI release 2016.03
  • td-agent:td-agent 0.12.26
  • nginx:nginx version: nginx/1.10.1

概要

/var/log/nginx/error.logをtd-agentを使用してtreasure dataに送りたい。その際、error.logのformat指定方法で四苦八苦したのでメモする。

nginxのerror.logのサンプル

/var/log/nginx/error.log
[ 2016-09-06 18:01:55.4569 31618/7ff7ec8ce840 age/Wat/WatchdogMain.cpp:1291 ]: Starting Passenger watchdog...
[ 2016-09-06 18:01:55.4698 31624/7f6b03425840 age/Cor/CoreMain.cpp:982 ]: Starting Passenger core...
[ 2016-09-06 18:01:55.4699 31624/7f6b03425840 age/Cor/CoreMain.cpp:235 ]: Passenger core running in multi-application mode.

設定した内容

/etc/td-agent/td-agent.conf
抜粋)
## tail nginx log
<source>
  type tail
  path /var/log/nginx/access_log
  format ltsv
  time_format %d/%b/%Y:%H:%M:%S %z
  tag <タグ名>
  pos_file /var/log/td-agent/nginx_access.pos
</source>

<source>
  type tail
  path /var/log/nginx/error.log
  pos_file /var/log/td-agent/nginx_error.pos
  tag <タグ名>
  format /^\[ (?<time>[^\.]+)\.[^ ]+ (?<pid>\d+)\/(?<tid>\w+) (?<path>[^ ]+) \]: (?<message>.*)$/
  time_format %Y-%m-%d %H:%M:%S
</source>

便利だったこと

以下サイトで正規表現を試せるので便利だった。
http://fluentular.herokuapp.com/

やり残したこと

18:01:55.4569

ミリ秒をうまく指定することができなかったので、良い方法があれば教えてください。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0