Learn how to configure Grafana with PNP4Nagios on CentOS 7 to enhance your network monitoring and visualization capabilities. Step-by-step guide for seamless integration. #centlinux #linux #grafana #nagios
Table of Contents
What is Grafana ?
Grafana is a free and open source software to create graphs of numeric time-series data such as performance data of computer systems. Grafana is biggest alternative visualization tool for Graphite today. Grafana can collect data from various data sources like Elastic Search, InfluxDB, CloudWatch, etc. Grafana support different types of graphical panels including Graphs, Heatmaps and Tables.
Before moving forward, it is required to have basic concepts of Nagios Core 4. Therefore, it is highly recommended that you should have Learning Nagios – Third Edition (PAID LINK) by Packt Publishing. It will be really helpful for you during your Nagios journey.
System Specification
In this article, we will install Grafana on CentOS 7 and integrate Grafana with Nagios Core via PNP4Nagios plugin.
For Simple Grafana PNP4Nagios configuration, we are installing Nagios and Grafana on same machine, however, each of them can be installed on individual machine if required.
We have provisioned a CentOS 7 virtual machine with following specifications:
- Hostname – nagios-01.example.com
- IP Address – 192.168.116.143/24
- Operating System – CentOS 7.6
- Nagios Version – Nagios Core 4.4
Read Also: How to install NagiosQL on CentOS 7
Install Nagios on Linux Server
First of all, we required to configure a Nagios Core server to collect performance data from network and computers.
The procedure of installing Nagios Core is already described in our previous article Install Nagios on CentOS 7.
Therefore, instead of reinventing the wheel, we are moving to next step.
Install PNP4Nagios on CentOS 7
We have already wrote an article Install PNP4Nagios on CentOS 7. Therefore, you should follow it to install and configure PNP4Nagios.
Install Grafana on CentOS 7
Browse URL http://docs.grafana.org/installation/rpm/ and download Grafana according to your operating system and platform.
# wget https://dl.grafana.com/oss/release/grafana-5.4.3-1.x86_64.rpm --2019-02-17 20:56:42-- https://dl.grafana.com/oss/release/grafana-5.4.3-1.x86_64.rpm Resolving dl.grafana.com (dl.grafana.com)... 151.101.26.217, 2a04:4e42:6::729 Connecting to dl.grafana.com (dl.grafana.com)|151.101.26.217|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 55015322 (52M) [application/x-redhat-package-manager] Saving to: âgrafana-5.4.3-1.x86_64.rpmâ 100%[======================================>] 55,015,322 174KB/s in 4m 45s 2019-02-17 21:01:28 (188 KB/s) - âgrafana-5.4.3-1.x86_64.rpmâ saved [55015322/55015322]
Install Grafana using yum command.
# yum install -y grafana-5.4.3-1.x86_64.rpm
Start and enable Grafana service.
# systemctl daemon-reload # systemctl enable grafana-server.service Created symlink from /etc/systemd/system/multi-user.target.wants/grafana-server.service to /usr/lib/systemd/system/grafana-server.service. # systemctl start grafana-server.service
Configure Linux Firewall
Allow Grafana service port in Linux Firewall.
# firewall-cmd --permanent --add-port=3000/tcp success # firewall-cmd --reload success
Grafana PNP4Nagios Configuration
Install PNP plugin for Grafana.
# grafana-cli plugins install sni-pnp-datasource installing sni-pnp-datasource @ 1.0.5 from url: https://grafana.com/api/plugins/sni-pnp-datasource/versions/1.0.5/download into: /var/lib/grafana/plugins â Installed sni-pnp-datasource successfully Restart grafana after installing plugins . <service grafana-server restart>
Download Grafana API.
# cd /usr/local/pnp4nagios/share/application/controllers/ # wget -O api.php "https://github.com/lingej/pnp-metrics-api/raw/master/application/controller/api.php" --2019-02-17 21:30:26-- https://raw.githubusercontent.com/lingej/pnp-metrics-api/master/application/controller/api.php Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 151.101.8.133 Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|151.101.8.133|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 11418 (11K) [text/plain] Saving to: âapi.phpâ 100%[======================================>] 11,418 --.-K/s in 0.01s 2019-02-17 21:30:26 (1.12 MB/s) - âapi.phpâ saved [11418/11418]
Restart Grafana service.
# systemctl restart grafana-server.service
Allow Access to PNP4Nagios web service by Grafana execute following or manually edit /etc/httpd/conf.d/pnp4nagios.conf file.
# sed -i '/Allow from all/a Allow from 127.0.0.1 ::1' /etc/httpd/conf.d/pnp4nagios.conf # sed -i '/Require valid-user/a Require all granted' /etc/httpd/conf.d/pnp4nagios.conf # sed -i 's/Allow from all/#&/' /etc/httpd/conf.d/pnp4nagios.conf # sed -i 's/AuthName/#&/' /etc/httpd/conf.d/pnp4nagios.conf # sed -i 's/AuthType Basic/#&/' /etc/httpd/conf.d/pnp4nagios.conf # sed -i 's/AuthUserFile/#&/' /etc/httpd/conf.d/pnp4nagios.conf # sed -i 's/Require valid-user/#&/' /etc/httpd/conf.d/pnp4nagios.conf
Restart Apache service.
# systemctl restart httpd.service
Test PNP4Nagios web service is locally accessed without authentication.
# curl http://localhost/pnp4nagios <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="http://localhost/pnp4nagios/">here</a>.</p> </body></html>
We have obtained a 301 redirection error, it means that our configurations are OK.
Configure PNP4Nagios as a Data Source for Grafana
Browse the URL https://nagios-01.example.com:3000.
Login with default username admin and password admin.
Since, we are login for the first time on Grafana, therefore it will ask you to change the admin user’s password.
Set a new password and click on Save.
You are now at the Grafana Dashboard.
Click on Add Data Source.
Choose the data source type here as PNP.
Enter configurations as above and click on Save & Test.
If the configurations are correct then Grafana will display “Data source is working”.
We have defined a data source PNP-1, now we have to create a dashboard for the data from our data source.
Click on the left toolbar to create a dashboard.
When click on Dashboard, it will ask you for the Panel type that we want to add in our Dashboard.
Let’s add a graph panel by clicking on Graph.
Click on Edit to add a data query.
We have defined a sample data query above.
Click on Save icon on top toolbar.
Enter a Dashboard Name and click on Save.
Grafana has been collecting data from Nagios Core via PNP and display it in our Panel.
In this guide, you have learned about Grafana PNP4Nagios configuration. Although this article demonstrates a single type of Dashboard and Panel but you can experiment on your own to explore and design custom dashboards according to your requirement.
Recommended Online Training: Setting up Nagios 4 monitoring
Final Thoughts
Configuring Grafana with PNP4Nagios on CentOS 7 can significantly improve your network monitoring and data visualization capabilities. By following this guide, you should have a smooth integration, leading to more efficient and insightful monitoring solutions.
If you need further assistance or prefer to have an expert handle the setup for you, I offer professional services for Grafana and PNP4Nagios configuration. Visit my Fiverr profile for more details and to get started: Linux System Engineer
Optimize your monitoring with a seamless Grafana and PNP4Nagios integration today!
hi, i can't see the imagen of data source type here as PNP.
Hi, Please ensure that you have installed PNP data source using following command.
# grafana-cli plugins install sni-pnp-datasource
As mentioned before, your procedure says "Enter configurations as above and click on Save & Test" but clicking on the image above only shows a thumbnail and not a full size picture. Therefore, we cannot see the settings defined.
Hi, Please install PNP data source.
# grafana-cli plugins install sni-pnp-datasource
No, he means on this website. All the pictures are just thumbnails, it is impossible to see the configuration. I have tried zooming in but since the pictures are just thumbnails the quality is to low to be able to see anything.
Pictures has been updated to normal sizes. Inconvenience is regretted please.
Hi Ahmer,
thanks for posting this tutorial.
I would like to know if the Grafana plugin will work if I use Nagios XI (instead of Nagios Core) and Grafana running on two different servers.
Does the Nagios server have an extra workload sending metrics to Grafana or does Grafana just "read" from Nagios without overloading it?
Thanks in advance,
Nita
Hi,
– Grafana can be used with Nagios XI as well.
– Grafana fetches metrics via PNP data source. Therefore, Nagios server observes a minor overhead while entertaining service requests by Grafana servers.
Thank you a lot for your fast reply.
Can I also retrieve BPI from the PNP datasource? Or maybe the Host/Service Status Summary?
What I need to achieve is some sort of "Status Panel" in Grafana showing information about my system's health status.
It would be even better if I could have Nagios' alerts on my Grafana dashboard somehow.
Can you give me some tips?
Nita
By using Grafana you can set more advanced alerts.
Hello, thank you for your effort writing this post.
I installed grafana and checkmk with nagios core and managed to install and configure datasource from grafana. It was verified successfully but when open new panel and try to add new query from this datasource nothing appears in grafana.
Any idea where the problem would be ?
This error is too generic. Please look for errors in the log files.
is it mandatory for grafana to be installed on the same machine as nagios is running?
Certainly not. You can install Grafana on a separate machine and then specify a remote data source therein.
Hi Ahmer Mansoor, i have followed all the steps, i am able to see data of all my linux hosts on pnp4nagios browser portal, but on grafana i can see only local host data, for other hosts i an not able to get the data.(service field is data is coming automatically but Label is not coming).
datasource is working properly.
Please help me.
Please contact me at our Facebook page.
Hello, Ahmer M.
I was following the steps but, when I installed PNP plugin, I had to make a different step because the firewall rules (I can't modify it now, unfortunately, work rules). The way I've done, I could see on Grafana plugins that PNP was installed, but when I arrived to the step "Download Grafana API" I couldn't access > /pnp4nagios/share/application/controllers/, I don't have this directory.
Can you help me? It was the install method of PNP plugin?
Hi,
New versions of PNP use different locations for installation. Locate the installed directory of PNP and then download Grafana API therein.
Could you pls provide the Nagiosxi and grafana integration for the graphs and dashboards
Unfortunately, I don't have work on the commercial edition i.e. Nagios XI. However, the vendor should provide the Grafana integration process.
Support/vendor team confirmed that they are not support to integrate nagiosxi to grafana. We should only show the created dashboard graphs into grafana. Is that possible from Nagiosxi ??
I Did not get positive response from vendor and they are not going to support to integrate from Nagiosxi to grafana.
Hi, if the vendor doesn't offer Grafana and Nagios XI integration, then working on it would be a nightmare. Because you won't get any help from anywhere and have to work on your own.
However, if you really want to work on it then you can try the same steps (above). It may be worked or not. Nobody guarantees.
(Nagios XI) – (Customer Support) = Nagios Core
Therefore, Switch to Nagios Core.