Header RSS Feed
If you only want to see the articles of a certain category, please click on the desired category below:
ALL Android Backup BSD Database Hacks Hardware Internet Linux Mail MySQL Monitoring Network Personal PHP Proxy Shell Solaris Unix Virtualization VMware Windows Wyse

Monitoring nginx web server with check_nginx_status.pl
Friday - Nov 1st 2013 - by - (3 comments)

Whenever I had to check a web server in the past, I used the check_http Nagios plugin, which, well, does the job. No website shown = Problem.

This works fine on classical web server setups, but in the past months I have built more and more proxied web solutions. As reverse proxy I tend to use Nginx for speed and "smallness".

Instead of checking a website/URL on the Nginx reverse proxy, it makes more sense to actually check the Nginx status and retrieve the live status data from Nginx. Like Apache, Nginx has an embedded "server status" feature, which can be activated like this:

server {
  listen 80 default_server;
  location /nginx_status {
    stub_status on;
    access_log   off;
    deny all;

Note that I'm using the "default server" for the nginx status here. To do that in a virtual host server wouldn't make much sense.

The output of this status looks like this:

Active connections: 2
server accepts handled requests
 31302 31302 58730
Reading: 0 Writing: 1 Waiting: 1

This week I came across check_nginx_status.pl which is easy to understand, simply works, and outputs performance data gathered from the Nginx status page.
A requirement is of course, that the IP address of the server on which check_nginx_status.pl is launched, is allowed to access the status page. That's why I added "allow;" into the Nginx config. Yes, you guessed correct - that's my Nagios server. You may of course also launch the plugin on the same host as Nginx and use the plugin through NRPE but I prefer to do all checks from a remote site, if possible. 

Let's take a look what the plugin is doing:

./check_nginx_status.pl -H mynginx.example.com
NGINX OK -  0.031 sec. response time, Active: 3 (Writing: 1 Reading: 0 Waiting: 2) ReqPerSec: 0.250 ConnPerSec: 0.250 ReqPerConn: 1.556|Writing=1;;;; Reading=0;;;; Waiting=2;;;; Active=3;;;; ReqPerSec=0.250000;;;; ConnPerSec=0.250000;;;; ReqPerConn=1.556139;;;;

Of course the plugin also supports thresholds:

./check_nginx_status.pl -H mynginx.example.com -w 10000,100,200 -c 20000,200,300
NGINX OK -  0.031 sec. response time, Active: 2 (Writing: 1 Reading: 0 Waiting: 1) ReqPerSec: 0.067 ConnPerSec: 0.067 ReqPerConn: 1.556|Writing=1;;;; Reading=0;;;; Waiting=1;;;; Active=2;;;; ReqPerSec=0.066667;;;; ConnPerSec=0.066667;;;; ReqPerConn=1.555996;;;;

Unfortunately the thresholds are not (yet) represented in the performance output. But hey, the plugin is on github, so development is open for everyone!

And this is how the graphs look in Nagiosgraph:

Nginx Status Graph

And for a reverse proxy with more traffic:

Nginx Status Graph

To sum this all up: check_nginx_status.pl is definitely a better way to check an Nginx reverse proxy than if I'd use check_http. It also gives performance data which are then shown in the graphs. These graphs can then be quickly verified for troubleshooting reasons, e.g. to see if a DDOS occurs.


Add a comment

Show form to leave a comment

Comments (newest first):

Deepanjan from india wrote on May 23rd, 2018:
i have installed Nagios XI and i want to monitor my webserver which use nginx service

How to configure so that i can monitor nginx from my NagiosXi server

Thanks in Advance

ck from Switzerland wrote on Mar 2nd, 2017:
Luv, you usually save monitoring plugins (check_nginx_status.pl is such a monitoring plugin) in the folder /usr/lib/nagios/plugins (Debian, Ubuntu, SuSE) or /usr/lib64/nagios/plugins (Centos, RHEL) or /usr/local/nagios/libexec (self-compiled) or wherever you have saved the other monitoring plugins.

Luv wrote on Mar 2nd, 2017:
Where to store this check_nginx_status.pl file ?

Go to Homepage home
Linux Howtos how to's
Monitoring Plugins monitoring plugins
Links links

Valid HTML 4.01 Transitional
Valid CSS!
[Valid RSS]

6938 Days
until Death of Computers