Glen Pitt-Pladdy :: BlogNginx 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 URLLike 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 { 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 Restart snmpd and you should be able to get basic stats via SNMP. Cacti TemplatesI 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
|
|||
Disclaimer: This is a load of random thoughts, ideas and other nonsense and is not intended to be taken seriously. I have no idea what I am doing with most of this so if you are stupid and naive enough to believe any of it, it is your own fault and you can live with the consequences. More importantly this blog may contain substances such as humor which have not yet been approved for human (or machine) consumption and could seriously damage your health if taken seriously. If you still feel the need to litigate (or whatever other legal nonsense people have dreamed up now), then please address all complaints and other stupidity to yourself as you clearly "don't get it".
Copyright Glen Pitt-Pladdy 2008-2023
|
Comments:
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 :)
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
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.
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
Hi!
When import the template cacti got this error: "Error: XML: Hash version does not exist."
Cacti version: 0.8.7i
Thanks!
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.
I use 0.8.7 version, this is not an old one.
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
I'm following your tutorial, but still empty graphs. MY cacti version is 0.8.8.b , any suggestions? Thanks.
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.
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 ?
Fixed it ! For anyone who has the same error as me:
apt-get install snmp-mibs-downloader
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
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.
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
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?
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
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.
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.