Author Photo

Being a Linux Enthusiast and a Fan of Open Source Software, I created Ahmer’s SysAdmin Recipes blog to share my experiences with other System Administrators. The curiosity doesn’t let me stop; therefore, I am constantly trying to learn new software tools and techniques. Whereas I also have the passion and the patience to teach the others.

I am always ready to accept new challenges and wish to explore the areas, that I haven’t worked on. Please give me your feedback and help me improve this blog.

Tuesday, 19 February 2019

Install Grafana with PNP4Nagios on CentOS 7

install-grafana-with-pnp4nagios-on-centos-7Grafana 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.

In this article, we will install Grafana on CentOS 7 and integrate Grafana with Nagios Core via PNP4Nagios plugin.

For Simplicity, we are installing Nagios Core and Grafana on same machine, however, Nagios Core and Grafana can be installed on individual machines if required.

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. It will be really helpful for you during your Nagios journey.


System Specification:

We have provisioned a CentOS 7 virtual machine with following specifications:

IP Address:
Operating System: CentOS 7.6
Nagios Version: Nagios Core 4.4


Installing Nagios Core on CentOS 7:

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 & Configure Nagios Core 4.4 on CentOS 7.

Therefore, instead of reinventing the wheel, we are moving to next step.


Installing PNP4Nagios Plugin for Nagios Core on CentOS 7:

We have already wrote an article Install PNP4Nagios on Nagios Core over CentOS 7. Therefore, you should follow it to install and configure PNP4Nagios.


Installing Grafana on CentOS 7:

Browse URL and download Grafana according to your operating system and platform.

[root@nagios-01 ~]# wget --2019-02-17 20:56:42-- Resolving (, 2a04:4e42:6::729 Connecting to (||: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.

[root@nagios-01 ~]# yum install -y grafana-5.4.3-1.x86_64.rpm Loaded plugins: fastestmirror Examining grafana-5.4.3-1.x86_64.rpm: grafana-5.4.3-1.x86_64 Marking grafana-5.4.3-1.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package grafana.x86_64 0:5.4.3-1 will be installed --> Processing Dependency: urw-fonts for package: grafana-5.4.3-1.x86_64 Loading mirror speeds from cached hostfile * base: * epel: * extras: * updates: --> Running transaction check ---> Package urw-fonts.noarch 0:2.4-16.el7 will be installed --> Processing Dependency: xorg-x11-font-utils for package: urw-fonts-2.4-16.el7.noarch --> Running transaction check ---> Package xorg-x11-font-utils.x86_64 1:7.5-21.el7 will be installed --> Processing Dependency: for package: 1:xorg-x11-font-utils-7.5-21.el7.x86_64 --> Running transaction check ---> Package libfontenc.x86_64 0:1.1.3-3.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================ Package Arch Version Repository Size ================================================================================ Installing: grafana x86_64 5.4.3-1 /grafana-5.4.3-1.x86_64 151 M Installing for dependencies: libfontenc x86_64 1.1.3-3.el7 base 31 k urw-fonts noarch 2.4-16.el7 base 3.0 M xorg-x11-font-utils x86_64 1:7.5-21.el7 base 104 k Transaction Summary ================================================================================ Install 1 Package (+3 Dependent packages) Total size: 154 M Total download size: 3.2 M Installed size: 156 M Downloading packages: (1/3): libfontenc-1.1.3-3.el7.x86_64.rpm | 31 kB 00:01 (2/3): xorg-x11-font-utils-7.5-21.el7.x86_64.rpm | 104 kB 00:01 (3/3): urw-fonts-2.4-16.el7.noarch.rpm | 3.0 MB 00:11 -------------------------------------------------------------------------------- Total 281 kB/s | 3.2 MB 00:11 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : libfontenc-1.1.3-3.el7.x86_64 1/4 Installing : 1:xorg-x11-font-utils-7.5-21.el7.x86_64 2/4 Installing : urw-fonts-2.4-16.el7.noarch 3/4 Installing : grafana-5.4.3-1.x86_64 4/4 ### NOT starting on installation, please execute the following statements to configure grafana to start automatically using systemd sudo /bin/systemctl daemon-reload sudo /bin/systemctl enable grafana-server.service ### You can start grafana-server by executing sudo /bin/systemctl start grafana-server.service POSTTRANS: Running script Verifying : grafana-5.4.3-1.x86_64 1/4 Verifying : 1:xorg-x11-font-utils-7.5-21.el7.x86_64 2/4 Verifying : urw-fonts-2.4-16.el7.noarch 3/4 Verifying : libfontenc-1.1.3-3.el7.x86_64 4/4 Installed: grafana.x86_64 0:5.4.3-1 Dependency Installed: libfontenc.x86_64 0:1.1.3-3.el7 urw-fonts.noarch 0:2.4-16.el7 xorg-x11-font-utils.x86_64 1:7.5-21.el7 Complete!

Start and enable Grafana service.

[root@nagios-01 ~]# systemctl daemon-reload [root@nagios-01 ~]# systemctl enable grafana-server.service Created symlink from /etc/systemd/system/ to /usr/lib/systemd/system/grafana-server.service. [root@nagios-01 ~]# systemctl start grafana-server.service

Allow Grafana service port in Linux Firewall.

[root@nagios-01 ~]# firewall-cmd --permanent --add-port=3000/tcp success [root@nagios-01 ~]# firewall-cmd --reload success

Install PNP plugin for Grafana.

[root@nagios-01 ~]# grafana-cli plugins install sni-pnp-datasource installing sni-pnp-datasource @ 1.0.5 from url: into: /var/lib/grafana/plugins â Installed sni-pnp-datasource successfully Restart grafana after installing plugins . <service grafana-server restart>

Download Grafana API.

[root@nagios-01 ~]# cd /usr/local/pnp4nagios/share/application/controllers/ [root@nagios-01 controllers]# wget -O api.php "" --2019-02-17 21:30:25-- Resolving (, Connecting to (||:443... connected. HTTP request sent, awaiting response... 302 Found Location: [following] --2019-02-17 21:30:26-- Resolving ( Connecting to (||: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.

[root@nagios-01 ~]# 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.

[root@nagios-01 ~]# sed -i '/Allow from all/a\ Allow from ::1' /etc/httpd/conf.d/pnp4nagios.conf [root@nagios-01 ~]# sed -i '/Require valid-user/a\ Require all granted' /etc/httpd/conf.d/pnp4nagios.conf [root@nagios-01 ~]# sed -i 's/Allow from all/#&/' /etc/httpd/conf.d/pnp4nagios.conf [root@nagios-01 ~]# sed -i 's/AuthName/#&/' /etc/httpd/conf.d/pnp4nagios.conf [root@nagios-01 ~]# sed -i 's/AuthType Basic/#&/' /etc/httpd/conf.d/pnp4nagios.conf [root@nagios-01 ~]# sed -i 's/AuthUserFile/#&/' /etc/httpd/conf.d/pnp4nagios.conf [root@nagios-01 ~]# sed -i 's/Require valid-user/#&/' /etc/httpd/conf.d/pnp4nagios.conf

Restart Apache service.

[root@nagios-01 ~]# systemctl restart httpd.service

Test PNP4Nagios web service is locally accessed without authentication.

[root@nagios-01 ~]# 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.


Configuring PNP4Nagios as a Data Source for Grafana:

Browse the URL


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 Dashbaord Name and click on Save.


Grafana has been collecting data from Nagios Core via PNP and display it in our Panel.

We have successfully install Grafana and integrate it with Nagios Core via PNP4Nagios plugin on CentOS 7. 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.

Install Grafana with PNP4Nagios on CentOS 7



  1. hi, i can't see the imagen of data source type here as PNP.

    1. Hi, Please ensure that you have installed PNP data source using following command.

      # grafana-cli plugins install sni-pnp-datasource

  2. 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.

    1. Hi, Please install PNP data source.

      # grafana-cli plugins install sni-pnp-datasource

    2. 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.

    3. Pictures has been updated to normal sizes. Inconvenience is regretted please.