Monitoring NGINX

Configure the Server Density agent to monitor your NGINX server to:

• Collect important metrics, such as connections and requests per second
• Identify overall server slowdowns caused by the web server

Monitored metrics

  • Connections Opened Per Second
  • Writing
  • Connections
  • Waiting
  • Connections Dropped Per Second
  • Reading
  • Request Per Second

Installing the Nginx plugin package

Install the Nginx plugin on Debian/Ubuntu:

sudo apt-get install sd-agent-nginx

Install the Nginx plugin on RHEL/CentOS:

sudo yum install sd-agent-nginx

Read more about agent plugins.

Configuring the agent to monitor NGINX

The agent can parse the Nginx HttpStubStatusModule output to show the current requests per second and number of connections. It also requires some additional configuration of your nginx server.

1. You first need to ensure the HttpStubStatusModule module is installed. This is not available by default and must be compiled in with the configure line:

--with-http_stub_status_module

Or by installing the 'nginx-extras' package on Debian/Ubuntu systems.

  • You can check whether HttpStubStatusModule is installed with the following command:
nginx -V 2>&1 | grep -o with-http_stub_status_module

If you get a result you've got it installed already.

2. Adding the following line to your /etc/nginx/nginx.conf file within a http { } block:

server {
        listen       127.0.0.1:80;
        listen       [::1]:80;
        server_name  localhost;

        location /nginx_status {
                stub_status on;
                access_log off;
                allow 127.0.0.1;
                allow ::1;
                deny all;
        }
   }
  • This will allow the status output to be accessed from http://localhost/nginx_status

You will now need to restart your nginx web server to allow the changes to take effect.

3. The config file /etc/sd-agent/conf.d/nginx.yaml.example will already be configured to use http://localhost/nginx_status as the status URL so you'll just need to copy the contents of that file to /etc/sd-agent/conf.d/nginx.yaml. If you have configured the nginx status on another URL, you should amend as necessary.

4. Restart the agent

sudo /etc/init.d/sd-agent restart

Verifying the configuration
Execute info to verify the configuration with the following:

sudo /etc/init.d/sd-agent info 

If the agent has been configured correctly you’ll see an output such as:

nginx
-----
  - instance #0 [OK]
  - Collected 4 metrics, 0 events & 1 service check

You can also view the metrics returned with the following command:

sudo -u sd-agent /usr/share/python/sd-agent/agent.py check nginx

NGINX Plus

Nginx Plus customers can use the extended http_status_module for more insightful metrics. Server Density supports parsing the data here, as long as you have followed the above steps the agent will automatically collect these metrics with no further configuration required.

Configuring Graphs

Click the name of your server from the Devices list in your Server Density account then go to the Metrics tab. Click the + Graph button on the right then choose the Nginx metrics to display the graphs. The metrics will also be available to select when building dashboard graphs.

Further Reading

We have a detailed blog post on how to monitor nginx.

Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

  • Avatar
    Guy Ro
    Edited by Guy Ro

Monday  —  Friday.

10am  —  6pm UK.

Dedicated Support.