Nginx: Show active connections

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

(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/

Add this into the server block

Save and restart nginx. Test it


And some explanation of the output

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

  1. SplitIce
    August 11, 2013 at 10:23

    If you need access to the data for use in rrdtool or other pieces of monitoring software a script like the following could help (and doesn’t require perl!).

    Replace $1 with the IP and $2 with the Port

    wget -O- -q $1:$2 | awk ‘/^Active/ {print $NF}’
    wget -O- -q $1:$2 | awk ‘/Reading/ {print $$2}’
    wget -O- -q $1:$2 | awk ‘/Writing/ {print $$4}’
    wget -O- -q $1:$2 | awk ‘/Waiting/ {print $$6}’
    wget -O- -q $1:$2 | awk ‘/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $$1}’
    wget -O- -q $1:$2 | awk ‘/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $$2}’
    UserParameter=nginx.requests[*],wget -O- -q $1:$2 | awk ‘/^[ \t]+[0-9]+[ \t]+[0-9]+[ \t]+[0-9]+/ {print $$3}’

    Or in the format needed for a Zabbix configuration file:

    This assumes you have a specific IP:Port combination (e.g that you use for revealing status information in a secure manner.

    I hope this helps.

  2. SplitIce
    August 11, 2013 at 10:24

    Correction remove “UserParameter=nginx.requests[*],” as that is zabbix specific.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.