Skip to content

Instantly share code, notes, and snippets.

@l2dy
Created August 9, 2019 05:16
Show Gist options
  • Save l2dy/099ea49ac8733aa1345086e3b2c2f0db to your computer and use it in GitHub Desktop.
Save l2dy/099ea49ac8733aa1345086e3b2c2f0db to your computer and use it in GitHub Desktop.

Additional NGINX Metrics

NGINX Amplify Agent can collect a number of additional useful metrics described below. To enable these metrics, please make the following configuration changes. More predefined graphs will be added to the Graphs page if the agent finds additional metrics. With the required log format configuration, you'll be able to build more specific custom graphs.

  • The access.log log format should include an extended set of NGINX variables. Please add a new log format or modify the existing one — and use it with the access_log directives in your NGINX configuration.
log_format  main_ext  '$remote_addr - $remote_user [$time_local] "$request" '
                        '$status $body_bytes_sent "$http_referer" '
                        '"$http_user_agent" "$http_x_forwarded_for" '
                        '"$host" sn="$server_name" '
                        'rt=$request_time '
                        'ua="$upstream_addr" us="$upstream_status" '
                        'ut="$upstream_response_time" ul="$upstream_response_length" '
                        'cs=$upstream_cache_status' ;
  • Here's how you may use the extended log format with your access log configuration:
access_log  /var/log/nginx/access.log  main_ext;

Note. Please bear in mind that by default the agent will process all access logs that are found in your log directory. If you define a new log file with the extended log format that will contain the entries being already logged to another access log, your metrics might be counted twice. Please refer to the agent configuration section above to learn how to exclude specific log files from processing.

  • The error.log log level should be set to warn.
error_log  /var/log/nginx/error.log warn;

Note. Don't forget to reload your NGINX configuration with either kill -HUP or service nginx reload.

See: https://github.com/nginxinc/nginx-amplify-doc/blob/master/amplify-guide.md#additional-nginx-metrics

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment