Menu
Index

Contact
LinkedIn
GitHub
Atom Feed
Comments Atom Feed



Tweet

Similar Articles

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

Recent Articles

17/07/2016 15:23
AWS ssh known_host sync
11/07/2016 08:42
File integrity and log anomaly auditing Updated (like fcheck/logcheck)
30/05/2016 13:09
Xenial LXC Container on Debian
12/03/2016 15:33
PHP Zend opcache on Cacti via SNMP
11/03/2016 13:11
Git on (Smart) HTTP with read/write authentication

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;
        allow 127.0.0.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

 

Comments:

brosky Image  14/08/2015 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  13/10/2015 16:45 :: madhatter

I,

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

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?

Thanks

Glen Pitt-Pladdy Image  14/10/2015 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  15/10/2015 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.

Thanks

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

Hi!

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

Cacti version: 0.8.7i

Thanks!

Glen Pitt-Pladdy Image  12/04/2016 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  13/04/2016 13:45 :: Jose

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

Glen Pitt-Pladdy Image  13/04/2016 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  15/11/2016 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  16/11/2016 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  07/12/2016 06:46 :: John

I'm getting nan values with this error: "WARNING: SNMP Get Timeout for Host:'127.0.0.1', 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 127.0.0.1 1.3.6.1.4.1.2021.11.52.0
.1.3.6.1.4.1.2021.11.52.0 = Counter32: 511018

Any advice ?

John Image  07/12/2016 07:26 :: John

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




Are you human? (reduces spam)
Note: Identity details will be stored in a cookie. Posts may not appear immediately