Atom Feed
Comments Atom Feed

Similar Articles

2015-01-08 22:59
php-fpm on Cacti via SNMP
2015-05-14 22:35
PHP APC on Cacti via SNMP
2016-03-12 15:33
PHP Zend opcache on Cacti via SNMP
2009-11-14 13:46
Apache stats on Cacti (via SNMP)
2015-02-13 22:51
opendkim on Cacti via SNMP

Recent Articles

2019-07-28 16:35
git http with Nginx via Flask wsgi application (git4nginx)
2018-05-15 16:48
Raspberry Pi Camera, IR Lights and more
2017-04-23 14:21
Raspberry Pi SD Card Test
2017-04-07 10:54
DNS Firewall (blackhole malicious, like Pi-hole) with bind9
2017-03-28 13:07
Kubernetes to learn Part 4

Glen Pitt-Pladdy :: Blog

Nginx on Cacti via SNMP

In recent years Nginx has come to the fore as higher scale has become necessary on the web. Nginx is specifically designed to be extremely efficient at serving large numbers of concurrent requests where traditional Apache setups would have huge memory requirements to serve the same number of concurrent clients.

While monitoring Apache is well catered for, this article following on from my previous one on SNMP basics aims to provide the necessary Cacti graphs for monitoring Nginx.

Nginx Stats URL

Like with Apache, Nginx has an easy to configure status URL which provides the few statistics about Nginx that we monitor here. This is rather simple to configure and all that was needed is in one vhost to put:

location /nginx_status {
        stub_status on;
        access_log off;
        allow ::1;
        deny all;

After reloading the configuration a request to http://localhost/nginx_status should provide a basic text output that with a bit of processing with grep and sed can easily be turned into a list of numbers for snmpd to digest. Fortunately I've done that for you :-)

Download: snmpd extension script and Cacti for Nginx on GitHub

I put the extension script nginx-stats in /etc/snmp/ and set it executable then add the following lines to /etc/snmp/snmpd.conf to call the script for appropriate SNMP requests:

# Nginx
extend nginx /etc/snmp/nginx-stats

Restart snmpd and you should be able to get basic stats via SNMP.

Cacti Templates

I have generated some basic Cacti Templates for Nginx.

Simply import the template cacti_host_template_nginx.xml, and add the graphs you want to the appropriate device graphs in Cacti. It should just work if your SNMP is working correctly for that device (ensure other SNMP parameters are working for that device).

Graph Screen Shots

Nginx Connections on Cacti

Nginx Handled Connections on Cacti

Nginx Requests per Connections on Cacti

Nginx Requests on Cacti

Nginx Status on Cacti

Nginx Unhandled Connections on Cacti



brosky Image  2015-08-14 16:14 :: brosky

Thank you, this is the second script that I try and finally it's working.

Just don't forget to edit the nginx-stats file :)

madhatter Image  2015-10-13 16:45 :: madhatter


I've configured everythinh, but my graphs in cacti are empty... calling http://localhost/nginx-status works on the client giving:

And cacti is showing other graphs (for cpu load, bandwith, etc) for that client... it's just the nginx graphs that show empty.

How do I test on the cacti server that it's all working for nginx data retrieval?


Glen Pitt-Pladdy Image  2015-10-14 17:27 :: Glen Pitt-Pladdy

The important thing is to determine where in the process the problems occur.

1. Running the nginx-stats script manually should verify that data is being collected from Nginx.

2. Using snmpwalk (see linked SNMP Basics article) against snmpd should verify that snmpd is correctly configured to provide the data.

3. Increasing the logging in Cacti should show details on what stats are being collected, and why others are not (eg. with large amounts of requests with insufficient threads/processes and/or too short timeouts)

Check these and hopefully that will tell you where in the process the problem is.

madhatter Image  2015-10-15 14:19 :: madhatter

It's working now... I needed an iptables rule on the cacti server to allow communication with the client in udp:161...

Using the snmpwalk command really helped.


Jose Image  2016-04-12 21:14 :: Jose


When import the template cacti got this error: "Error: XML: Hash version does not exist."

Cacti version: 0.8.7i


Glen Pitt-Pladdy Image  2016-04-12 22:41 :: Glen Pitt-Pladdy

This is normally caused by having a very old version of Cacti which does not know about the version that the template was created for. If you search for "cacti forward compatibility" on this site you will find a way of updating a file in your version which might help, but given that there have been security problems along the way, I think it would be wise to consider updating your Cacti to a recent version instead.

Jose Image  2016-04-13 13:45 :: Jose

I use 0.8.7 version, this is not an old one.

Glen Pitt-Pladdy Image  2016-04-13 18:51 :: Glen Pitt-Pladdy

0.8.7i was 2011, with 0.8.7 starting in 2007

Cacti might not have the version number inflation of other projects, but there's been plenty happened since then

ben Image  2016-11-15 12:56 :: ben

I'm following your tutorial, but still empty graphs. MY cacti version is  0.8.8.b , any suggestions? Thanks.

Glen Pitt-Pladdy Image  2016-11-16 07:13 :: Glen Pitt-Pladdy

There's a number of steps in the process of getting data through to having graphs. First you need to determine what step(s) are failing. I would generally start roughly mid-way and use snmpwalk to see if I've got snmpd providing the data. If that fails I'd try running the extension script manually (as the snmpd user) or if it succeeds I'd look at the Cacti side (turn the log level up and see what you get). By breaking the problem down you can determine exactly what part is not working.

John Image  2016-12-07 06:46 :: John

I'm getting nan values with this error: "WARNING: SNMP Get Timeout for Host:'', and OID:'NET-SNMP-EXTEND-MIB::nsExtendOutLine."nginx".3'"

Generic snmpwalk is able to get OIDs:

/etc/snmp# snmpwalk -Cc -On -v 1 -c public
. = Counter32: 511018

Any advice ?

John Image  2016-12-07 07:26 :: John

Fixed it ! For anyone who has the same error as me:
apt-get install snmp-mibs-downloader

Shankar Image  2017-08-08 14:37 :: Shankar


Thanks for the article. I have configured the cacti based on your instructions my nginx server is in AWS ec2 instance. I have enabled snmp port &  I am able to get other status like CPU Load etc. But I am not getting Nginx status graphs are showing blank.
I am getting below warning message.

WARNING: Result from SNMP not valid. Partial Result: U
08/08/2017 02:35:14 PM - CMDPHP: Poller[0] WARNING: SNMP Get Timeout for Host:'Hostname', and OID:'NET-SNMP-EXTEND-MIB::nsExtendOutLine."nginx".7'

Please help me regarding this issue.

Thanks & Regards,

Glen Pitt-Pladdy Image  2017-08-09 06:29 :: Glen Pitt-Pladdy

Most problems turn out to be easily solved. Take a look at my other article "Debugging Cacti Problems" and also ensure you've verified the snmpd data collection script works (can you run it manually). Also try using snmpwalk as described in SNMP basics linked above.

Metrics like CPU are often available to all users, but extended items (like this) might require the user/community you are using has extra permissions set. Break the problem up into steps and test up to each step which will tell you where the problem occurs.

Shankar Image  2017-08-18 06:47 :: Shankar

I have ran the script manually & check snmpwalk i am getting the data but data is not showing in graph. I have installed latest version 1.1.17 cacti. In Log file i am getting below message kindly help me.
2017/08/18 06:40:25 - BOOST NOTE: Updating Local Data Id:'22', Template:nginx_rd, Output: 1503038401:U
2017/08/18 06:40:24 - BOOST NOTE: Updating Local Data Id:'21', Template:nginx_req, Output: 1503038401:U


Glen Pitt-Pladdy Image  2017-08-19 12:49 :: Glen Pitt-Pladdy

Since I'm not using the latest Cacti (I use well proven versions in distros) I can't tell if your version introduces new bugs, incompatibilities or requires different configuration that may be impacting you. That's something you will have to work out.

The log does suggest there is a problem with data - "U" normally means an undefined or invalid value. Are you performing the checks from the cacti server? Are you using exactly the same configuration for the checks as you have for cacti? Are you able to see snmp information picked up in cacti from the target server you are monitoring?

Sérgipo Rosa Image  2017-09-05 08:41 :: Sérgipo Rosa

I have several nginx servers and one cactiu server.
What do I need to change in order to plot graphs for each of the nginx servers?
I'm assuming that this files are aimed to graph for the host himself.
Thank you and thank you for this awesome simple scripts

Glen Pitt-Pladdy Image  2017-09-05 19:32 :: Glen Pitt-Pladdy

Each server is normally added to Cacti as a "device" and in this case configured with SNMP. Then you can add graphs to each device, or define a host template to easily apply many graphs to larger numbers of servers on each.

Sérgio Rosa Image  2017-09-06 08:57 :: Sérgio Rosa

thank you for taking time to answer a nonsense question. I figure it out after looking at the conf files.
I'm truly thankful to you, because you solved an issue I was having.
All servers are plotting as announced and better than expected.
Thank you.

Note: Identity details will be stored in a cookie. Posts may not appear immediately