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 16:02
LM Sensors stats on Cacti (via SNMP)
31/10/2009 14:46
SMART stats on Cacti (via SNMP)

Recent Articles

23/04/2017 14:21
Raspberry Pi SD Card Test
07/04/2017 10:54
DNS Firewall (blackhole malicious, like Pi-hole) with bind9
28/03/2017 13:07
Kubernetes to learn Part 4
23/03/2017 16:09
Kubernetes to learn Part 3
21/03/2017 15:18
Kubernetes to learn Part 2

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 17: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 17: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 18: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 15: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 22: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 23: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 14:45 :: Jose

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

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

Shankar Image  08/08/2017 15:37 :: Shankar

Hi,

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,
Shankar

Glen Pitt-Pladdy Image  09/08/2017 07: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  18/08/2017 07: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

Regards,
Shankar   

Glen Pitt-Pladdy Image  19/08/2017 13: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  05/09/2017 09:41 :: Sérgipo Rosa

Hi,
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  05/09/2017 20: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  06/09/2017 09:57 :: Sérgio Rosa

Glen,
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.




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