• Print
  • Share
  • Dark
    Light

Collecting Nginx Logs

  • Updated on 27 Sep 2018
  • 1 minute to read
  • Contributors

The Retrace Monitoring Agent can monitor the health of your web application, including Requests/min vs Average Page Load time, HTTP Request Error Rate, and Apdex Satisfaction Score.

To enable Retrace to monitor your Nginx web application from the Monitoring Agent, there are a couple of things to make sure of.

Enable Nginx Discovery

Nginx 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.

Configuring Access Logs and Log Formats

The Retrace Monitoring Agent needs the following information to be present in access logs:

  • time taken
  • request path
  • response status
  • log event date

You can configure what is written to access logs using log format directive. This directive supports multiple Nginx variables available at the time of a log write.

You need to make sure the following variables for log format are used:

  • time taken: $request_time
  • request path: $request or $request_uri
  • response status: $status
  • log event date: $time_local or $time_iso8601 or $msec

If log format is omitted for access log directive, the default log format will be used. The default log format does not contain all the required fields, so the monitoring agent will not be able to obtain information.

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.

Configuration Example

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

The final step is to 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.