6
6

More than 5 years have passed since last update.

opsworksでnginxのログをltsvで出力する

Posted at

場面

  • nginxのログをtd-agentでtailするときにltsvにしたい

見るところ

やってみる

stack settingsのcustom jsonいじるだけでできる。必要なのは2点。

  • node[:nginx][:log_format]["<my_log_format_name>"] = "<my_log_format_definition>" に値を入れてlog_formatを定義する

  • @application[:log_format] = ["<my_log_format_name>"] に値を入れて、定義したlog_formatを利用する

{
  "nginx": {
    "log_format": {
      "ltsv": "'time:$time_iso8601\\trequest_method:$request_method\\trequest_uri:$request_uri\\tstatus:$status\\tbody_bytes_sent:$body_bytes_sent\\trequest_time:$request_time\\thttp_referer:$http_referer\\thttp_user_agent:$http_user_agent\\thttp_x_forwarded_for:$http_x_forwarded_for'"
    }
  },
  "deploy": {
    "<my_application>": {
      "log_format": ["ltsv"],
      ...
    }
  }
}

これでnginxのログをltsvで出力できる

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