How to watch nginx server status and connections requests per second under Linux or Unix like operating systems? For such a task nginx server has a module called HttpStubStatusModule. This module provides the ability to get some status from nginx. You will get the following information:
- Number of all open connections.
- Stats about accepted connections.
- Connections per second and so on.
Configure HttpStubStatusModule
Edit nginx.conf file:
# vi nginx.conf
Add or append the following in context location:
1 2 3 4 5 6 7 8 |
location /nginx_status { # Turn on stats stub_status on; access_log off; # only allow access from 192.168.20.20 # allow 192.168.20.20; deny all; } |
Save and close the file. Reload nginx server:
# service nginx reload
OR
# nginx -s reload
Watch Nginx Active Connections
Open a web-browser and type the following url:
http://your-domain-name-here/nginx_status
OR
http://ip.address.here/nginx_status
Where,
586 = Number of all open connections
9582571 = Accepted connections
9582571 = Handled connections
21897888 = Handles requests
How to calculate connections per second?
Requests per connection = handles requests / handled connections
Requests per connection = 21897888/9582571 (pass this to bc -l using echo ‘21897888/9582571’ | bc -l command)
Requests per connection = 2.28