Collecting Nginx Logs
  • Updated on 06 Feb 2020
  • 1 minute to read
  • Contributors
  • Print
  • Share
  • Dark
    Light

Collecting Nginx Logs

  • Print
  • Share
  • Dark
    Light

To enable Retrace to monitor your Nginx web application access logs:

Enable Log Collection

In Retrace Server Settings, enable the Nginx Access Logs option found under Log Collectors.

Configure LogFormat

Adjust your Nginx configuration to include the following:

Add stackify log_format.

log_format stackify `'$remote_addr $msec "$request" $request_time $status "$http_user_agent"'`;

Note: Nginx allows you to configure multiple access logs for one application. They all will be processed. Nginx also allows you to disable access logs for an application, but enable access logs for particular locations or cases. The monitoring agent will only obtain data from the available logs, so this will not be a real statistic for the whole application.

Update your application's access_log to reference the stackify log_format.

http {
    log_format stackify '$remote_addr $msec "$request" $request_time $status "$http_user_agent"';
    server {
        …
        access_log /var/log/nginx/application_access_log.log stackify;
    }
}

Check Permissions

Ensure that the log file and directory are accessible by the monitoring agent.

  • chmod 755 on the log file directories
  • chmod 744 or similar on the log files

Note: If you use something like logrotate, be sure to specify the permissions (mode) of the new log file that is created after rotating the old log file out and replacing it.

Configure Applications

Depending on your setup, use either Auto Discovery or Manual Configuration.

Auto Discovery

Auto Discovery option will scan /var/log/nginx for Nginx access logs:

Auto discovery can be enabled in /usr/local/stackify/stackify-agent/stackify-agent.conf.

discovery.nginx=true

This can automatically be enabled with the Linux Installer argument --discovery-nginx.

Manual Configuration

Use Manual Configuration if auto discovery does not find your access logs or you want to define specific Application and Environment labels.

Configuration should be added to: /usr/local/stackify/stackify-agent/stackify-agent.conf.

For each access log setup the following parameters, [application] should be replaced w/ a unique key to group the configuration items together.

stackify.nginx.[application].app=Sample Application
stackify.nginx.[application].env=Production
stackify.nginx.[application].accessLog=/var/log/custom/nginx/access.log
Was this article helpful?