User Tools

Site Tools


Monitor the statistics of Nginx with Cacti

First, add the next lines to configuration file of nginx

 location /server_status {
    stub_status on;
    access_log off;
    # Only me can access this
    #deny all;

Run nginx -t to make sure the configuration file is correct. Then run kill -1 nginx_pid, nginx will reload the configuration. After nginx reload it, try to access the url: http://server/server_status/, the browser will display like this:

 Active connections: 303 
 server accepts handled requests
  6314384 6314384 34931986 
 Reading: 3 Writing: 5 Waiting: 295 

Next, create the script to get the status data from the nginx server. I wrote a python tool to get these data.
It's better that putting this command in <path_cacti>/scripts/

 #!/usr/bin/env /usr/bin/python
 import sys,os,commands
 import re
 import urllib2,urllib
 p = re.compile('\n')
 st = []
     url = ''
     s = urllib.urlopen(url)
     s =
     s = s.split('\n')
     a = s[0].split(' ') 
     if sys.argv[1] == 'actconns':
     elif sys.argv[1] == 'requests':
         a = s[2].split(' ')
     elif sys.argv[1] == 'rqrw':
         a = s[2].split(' ')
         str = 'request:' + str(float(a[3]) / float(a[1]))
         a = s[3].split(' ')
         str = str + ' read:' + a[1] + ' write:' + a[3]
 except Exception, err:

Now, login cacti, to setup the new graph. Click Data Input Methods, add a new data input method

Then create Data Templates

Ok, let create Graph Templates

That' OK!


Enter your comment. Wiki syntax is allowed:
mirnshi/monitor_the_statistics_of_nginx_with_cacti.txt · Last modified: 2009/11/21 07:25 by mirnshi