Monitoring nginx Server Statistics With rrdtool

This script is very easy to install and configure. You can use following steps to get pretty stats graph for your nginx-powered server:

  • Modify your nginx config file and add following location to it:
http {

server {
listen SOME.IP.ADD.RESS;

location /nginx_status {
stub_status on;
access_log   off;
allow SOME.IP.ADD.RESS;
deny all;
}

}

}
 * Test your config file with following command:
 # /your/installation/sbin/nginx -t
2006/04/29 04:24:36 [info] 31676#0: the configuration file /opt/nginx/conf/nginx.conf syntax is ok
2006/04/29 04:24:36 [info] 31676#0: the configuration file /opt/nginx/conf/nginx.conf was tested successfully
#
If you will get error about stub_status directive, check your nginx – it should be configured with —-with-http_stub_status_module option.

  • If your configuration is OK, you can restart nginx and test it:
  •  # GET http://your-domain.com/nginx_status
    Active connections: 1492
    server accepts handled requests
    2124355 2124355 8278635
    Reading: 6 Writing: 405 Waiting: 1081
     Download  perl script: rrd_nginx.pl and make it executable with
    # chmod +x rrd_nginx.pl
     Change settings in rrd_nginx.pl to let script know where it will save rrd-base and images:
     #!/usr/bin/perl
    use RRDs;
    use LWP::UserAgent;

    # define location of rrdtool databases
    my $rrd = ‘/opt/rrd’;
    # define location of images
    my $img = ‘/opt/rrd/html’;
    # define your nginx stats URL
    my $URL = http://your-domain.com/nginx_status”;

     Last step is to insert following string to /etc/crontab file and to restart cron daemon:
    * *     * * *   root    /some/path/rrd_nginx.pl  When all preparations will be finished, you get  images in your $img directory: ---------------------  Quoted from blog.kovyrin.net

    Leave a comment