Enable NGINX stub_status module
NGINX provides ngx_http_stub_status_module module which allows us to access status data about NGINX itself. We are going to set up our monitoring by using metrics provided by this module.
Update NGINX config expose an endpoint for stub_status
Update your NGINX config file to add a server stanza as follows:
server {
location = /basic_status {
stub_status;
allow 127.0.0.1; #only allow requests from localhost
deny all; #deny all other hosts
}
listen 81;
}
Above config allows us to access metrics maintained by the stub_status module. The /basic_status
endpoint is only accessible from the server itself. This is because we are going to set up prometheus on the same instance where NGINX is running. If you prefer to keep the monitoring server separate from the NGINX server, please update the allow
section with your monitoring server's IP.
Start/Restart NGINX
Restart NGINX to pick up the updated config file:
$ sudo nginx -t && sudo nginx -s reload
If you currently don't have NGINX running, use following command to start NGINX:
$ sudo nginx -t && sudo nginx
Verify /basic_status endpoint
The /basic_status
endpoint should be up and running after you restart NGINX. You can access the endpoint from your monitoring host as follows:
$ curl http://127.0.0.1:81/basic_status
Your output should like something like below:
Active connections: 2335
server accepts handled requests
287245223 287245223 382246503
Reading: 91 Writing: 153 Waiting: 232
Have any feedback?
If you have any feedback regarding this article or need a tutorial on any specific topic, please submit this feedback form.