Nginx

NGINX is a high-performance web server, reverse proxy, and load balancer known for its ability to handle thousands of concurrent connections efficiently with minimal resource usage. Its widespread adoption makes it a cornerstone of modern web infrastructure.

Monitoring NGINX's performance metrics is essential for maintaining reliable web services. Through metrics like connection states, request rates, response codes, and upstream response times, operators can quickly identify issues, optimize performance, and ensure high availability of their web services.

Prerequisites

1 MW Host Agent

Middleware Host Agent (MW Agent) v1.6.1+ must be installed on your local machine. To install the MW Agent, see our Installation Guide.

2 Expose Nginx Metrics

To collect metrics from NGINX, your server must expose a local status endpoint which requires the NGINX binary to be compiled with the status module enabled. This module is crucial for the monitoring solution to scrape and report NGINX metrics.

There are two module which can expose these metrics.

Nginx Status Stub

This collects very basic level metrics and mostly enabled by default in your nginx installation. To check if it is available try the following command:

This should output

Most standard NGINX distributions include this module by default, but if you're using a custom build, you'll need to compile it from source.

DEB
RPM

DEB: Compatible with Debian or Debian-based operating systems. For AWS instances this includes Ubuntu and Debian.

RPM: Compatible with Red Hat Package Manager and operating systems like Red Hat or CentOS. Use this for AWS instances using Amazon Linux.

To enable stub status monitoring, add this to your NGINX configuration. This is generally at /etc/nginx/nginx.conf

Nginx virtual host traffic status module

To check if VTS module is installed:

This should output:

If the module isn't present, you have to install manually:

DEB
RPM
Docker

DEB: Compatible with Debian or Debian-based operating systems. For AWS instances this includes Ubuntu and Debian.

To install manually first check nginx version.

This outputs:

Before we download and install nginx from source, we need to remove the current installation

Check if nginx is removed:

Now we need to download Nginx source, depending on our Nginx version.

Clone the VTS module repository:

Download Nginx Source Code

Run the configure script, including the path to the VTS module:

Build and install Nginx with the VTS module:

Verify Installation:

Add nginx to PATH. Open your .bashrc and add the following line.

Source the .bashrc file

RPM: Compatible with Red Hat Package Manager and operating systems like Red Hat, CentOS or Fedora. Use this for AWS instances using Amazon Linux.

First, remove any pre-installed version of Nginx:

Check if Nginx is removed:

Update your system and install necessary build tools:

Clone the VTS module repository:

Visit nginx.org/download to find the version of Nginx that matches your needs. For example:

Run the configure script with the necessary flags and modules:

Build and install Nginx:

Check if Nginx is installed with the VTS module:

Add nginx to PATH. Open your .bashrc and add the following line.

Source the .bashrc file

Dockerfile: If you want to run Nginx inside a docker container.

To enable vts, add this to your NGINX configuration. This is generally at /etc/nginx/nginx.conf

This will expose nginx metrics.

3 Access Integrations

Log in to Middleware, navigate to the Installations Page in the bottom left corner, select Integrations and click Nginx:

To configure the integration of your Nginx Web Server with our platform.

Enter Server Details:

  • Endpoint: Provide the endpoint URL of the server status for the http status stub. This is generally <SERVER-URL>:<NGINX-PORT>/nginx_status

  • VTS Endpoint: Provide the endpoint URL of the server status for the VTS Endpoint . This is generally <SERVER-URL>:<NGINX-PORT>/status/format/json

  • Collection Interval: Specify the interval at which telemetry data is collected.

Apache Integration Screen

Metrics collected

Metrics

MetricDescriptionUnitType
nginx.requestsTotal number of requests made to the server since it startedrequestscumulative (int)
nginx.connections_acceptedThe total number of accepted client connectionsconnectionscumulative (int)
nginx.connections_handledThe total number of handled connectionsconnectionscumulative (int)
nginx.connections_currentThe current number of nginx connections by stateconnectionscumulative (int)
nginx.load_timestampTime of the last reload of configuration (time since Epoch)msgauge (int)
nginx.upstream.peers.response_timeThe average time to receive the last byte of data from this servermsgauge (int)
nginx.net.readingCurrent number of connections where NGINX is reading the request headerconnectionsgauge (int)
nginx.net.writingCurrent number of connections where NGINX is writing the response back to the clientconnectionsgauge (int)
nginx.net.waitingCurrent number of connections where NGINX is waiting for a responseconnectionsgauge (int)
nginx.server_zone.responses.1xxThe number of responses with 1xx status coderesponsesgauge (int)
nginx.server_zone.responses.2xxThe number of responses with 2xx status coderesponsesgauge (int)
nginx.server_zone.responses.3xxThe number of responses with 3xx status coderesponsesgauge (int)
nginx.server_zone.responses.4xxThe number of responses with 4xx status coderesponsesgauge (int)
nginx.server_zone.responses.5xxThe number of responses with 5xx status coderesponsesgauge (int)
nginx.server_zone.receivedBytes received by server zonesBycumulative (int)
nginx.server_zone.sentBytes sent by server zonesBycumulative (int)
nginx.upstream.peers.requestsNumber of requests made to upstream serversrequestscumulative (int)
nginx.upstream.peers.receivedBytes received from upstream serversBycumulative (int)
nginx.upstream.peers.sentBytes sent from upstream serversBycumulative (int)
nginx.upstream.peers.responses.1xxNumber of responses from upstream with 1xx status codesresponsescumulative (int)
nginx.upstream.peers.responses.2xxNumber of responses from upstream with 2xx status codesresponsescumulative (int)
nginx.upstream.peers.responses.3xxNumber of responses from upstream with 3xx status codesresponsescumulative (int)
nginx.upstream.peers.responses.4xxNumber of responses from upstream with 4xx status codesresponsescumulative (int)
nginx.upstream.peers.responses.5xxNumber of responses from upstream with 5xx status codesresponsescumulative (int)
nginx.upstream.peers.weightWeight of upstream serverweightgauge (double)
nginx.upstream.peers.backupWhether upstream server is a backup server{state}gauge (int)
nginx.upstream.peers.health_checks.last_passedBoolean indicating if the last health check request was successful and passed tests{status}gauge (int)