Here is something I stumbled upon some time ago and did put it on my “To do later when I have more time” list.
It’s nothing that will change the world as we know it, but it will give you some statistics about your NGINX server.
NGINX has a module called HttpStubStatusModule which provides you statistics about number of requests handled and connections made to your nginx server.
Today I got a few minutes over and I decided it was time to test it on one of my Virtual Private Servers.
First of all you need to check if your nginx installation has the module compiled, check it by running “nginx -V
“:
if you have this “–with-http_sub_module” option in configure arguments, you are good to go. The results might look something like this
1 2 3 4 5 |
# nginx -V nginx version: nginx/1.2.7 TLS SNI support enabled configure arguments: --with-http_sub_module |
(the configure arguments part above is incomplete, it should contain alot more. I’ve shortened it for readability).
So, now that we have established that the module is available it’s time to edit your nginx configuration file.
In my case, using debian and MINSTALL, I decided to add it to the default.conf file found in /etc/nginx/hosts.d/
1 |
nano /etc/nginx/hosts.d/default.conf |
Add this into the server block
1 2 3 4 5 6 7 8 9 10 |
location /nginx_status { stub_status on; access_log off; #If you want to secure access to this virtual directory allow 192.168.1.100; #Change this to your IP #Uncomment the next line if you want to allow access to this from anywhere #allow all; deny all; } |
Save and restart nginx. Test it
1 2 3 4 5 6 |
curl http://localhost/nginx_status Active connections: 6 server accepts handled requests 31 31 202 Reading: 0 Writing: 1 Waiting: 5 |
And some explanation of the output
1 2 3 4 5 6 |
active connections -- number of all open connections server accepts handled requests -- nginx accepted 5 connections, handled 5 connections (no one was closed just it was accepted), and handles 8 requests (1.6 requests per connection) reading -- nginx reads request header writing -- nginx reads request body, processes request, or writes response to a client waiting -- keep-alive connections, actually it is active - (reading + writing) |
So what can we do with this information? It’s not that interesting when presented as pure text.
While reading about the HttpStubStatusModule module I noticed a link to a webpage that took advantage of this status module and used rrdtool to create some nice graphics from the result.
Now that is something all people love, graphs!
Read the instruction on how to use rrdtool here.
2 comments for “Nginx: Show active connections”