The stub_status module provides a simple and efficient way to obtain real-time information about the server's current status and performance. This module generates a small, text-based status page that can be accessed through a web browser or programmatically. This page provides key metrics that are useful for monitoring and analyzing the server's behavior.
I. Setup the status page metric
To enable the stub_status module, you need to include its configuration within a location block in your Nginx configuration file :
1. Update Nginx configuration:
Open your Nginx configuration file (commonly located at /etc/nginx/nginx.conf or /etc/nginx/sites-available/default) in a text editor with superuser privileges.
2. Add the status module configuration:
Inside the location block, add the following lines to enable the status module:
location /nginx_status {
stub_status on;
access_log off; # Optionally turn off access logs for this endpoint
allow 127.0.0.1; # Adjust this to allow specific IP addresses
deny all;
}
- allow and deny: these directives control access to the status page. In the example, access is allowed only from the IP address 127.0.0.1. You should adjust this to allow access from your own IP addresses.
- stub_status on;: Enables the stub_status module for the specified location.
- access_log off;: Optionally turns off access logging for this specific endpoint. This can be useful to prevent the status page requests from being logged, especially if the status page is accessed frequently.
3. Restart Nginx:
After saving the configuration file, restart Nginx to apply the changes:
sudo service nginx restart
4. Accessing the Nginx status page:
Once the status module is enabled, you can access the live status page by navigating to http://your_server_ip/nginx_status in a web browser.
II. Interpreting Nginx status page metrics:
Active connections:
The current number of client connections that are actively being processed by the server. A high number of active connections may indicate a busy server, potentially reaching its capacity.
Server requests:
The total number of client requests that the server has accepted since it started. This provides a sense of the overall workload the server has handled.
Reading, writing, and waiting:
The number of connections in different states : reading a request from a client, writing a response to the client, or waiting. Monitoring these states helps identify where the server is spending most of its time. A high number of connections in the "waiting" state may indicate a bottleneck.
Requests per second:
The average number of client requests the server is handling per second. This metric gives an idea of the server's throughput. Sudden spikes or drops may require further investigation.
Connection states:
A breakdown of connections based on their states, such as established, accepted, or handled.
Understanding the distribution of connection states helps diagnose issues. For example, a high number of "accepted" connections without a corresponding increase in "handled" connections may indicate a bottleneck.
Nginx version and uptime:
Information about the Nginx version and how long the server has been running.
Useful for confirming the server's version and uptime, which can be helpful for troubleshooting and maintenance.
When interpreting these metrics, it's crucial to establish a baseline and monitor changes over time. Sudden spikes, drops, or unusual patterns may indicate issues that require attention. Additionally, understanding the relationship between metrics (e.g., high active connections and low requests per second) can provide insights into potential performance bottlenecks.
As you gain more experience with Nginx and server administration, you'll develop a more intuitive understanding of these metrics and their implications for server performance. Regularly reviewing the status page helps in proactive monitoring and ensures the server is operating optimally.