netdata による nginx のためのモニタリング設定


nginxのモニタリングに関連するプラグインは以下の2つです。

  • nginx
  • web_log

nginxプラグイン

nginxのアクティブコネクション等のチャートを表示できます。 設定次第で、リモートで稼働しているnginxのチャートを表示させることも可能です。

nginxの設定

location /stub_status {
    stub_status;
    allow 127.0.0.1;
    deny all;
}

netdataの設定(python.d/nginx.conf)

localhost:
  name : 'local'
  url  : 'https://localhost/stub_status'

以上の設定により、ダッシュボードにnginx localのチャートグループが追加されます。


web_logプラグイン

nginxのアクセスログをモニタリングするプラグインです。

web_logプラグインはnginxだけでなくapachelighttpd,gunicornのログをモニタリングできます。

nginxの設定

log_format netdata '$remote_addr - $remote_user [$time_local] '
                   '"$request" $status $body_bytes_sent '
                   '$request_length $request_time '
                   '"$http_referer" "$http_user_agent"';

access_log  /var/log/nginx/access.log  netdata;

上記の設定をすることで、nginx規定のログフォーマットでは表示させることの出来ないtimings等のチャートも表示出来るようになります。

netdataの設定(python.d/web_log.conf)

nginx_log:
  name: 'nginx'
  path: '/var/log/nginx/access.log'
  all_time: no

アクセス数の多いサーバではメモリを多く消費するのでall_time: noを追加して、クライアントIPアドレスのチャートを無効化しています。