Beyond simply checking error logs, advanced monitoring involves tracking key performance indicators (KPIs) and metrics that provide deep insights into Nginx's behavior and your application's health. This proactive approach allows you to identify bottlenecks, anticipate issues, and ensure optimal performance.
Nginx exposes a wealth of information through its stub_status module. When enabled, this module provides a simple text-based overview of your server's current operational state. To enable it, you'll need to add the ngx_http_stub_status_module to your Nginx build (it's usually compiled by default) and then configure a location in your nginx.conf file.
http {
# ... other http configurations ...
server {
# ... other server configurations ...
location /nginx_status {
stub_status;
# Optional: restrict access for security
# allow 127.0.0.1;
# deny all;
}
}
}Once configured and reloaded, accessing /nginx_status in your browser or via curl will yield output similar to this:
Active connections: 1
server accepts handled requests
100 100 100
Reading: 0 Writing: 1% 0% Waiting: 1Let's break down these key metrics:
- Active connections: The current number of open connections being handled by Nginx. A consistently high number might indicate a need for more worker processes or that clients are not closing connections properly.
server accepts: The total number of accepted client connections since Nginx started. This is a cumulative count.
server handled: The total number of connections that have been handed over to Nginx's worker processes. In most cases, this should be equal toserver accepts.