Home » Categories » Products » Nagios XI » Documentation » Visualizations

Nagios XI - Using Grafana With Existing Performance Data

Nagios XI - Using Grafana With Existing Performance Data

This documentation explains how to install and configure Grafana to generate performance graphs on a Nagios XI server. Grafana uses the existing performance data files (RRD) to generate the graphs, this allows you to extend Nagios XI to use Grafana without any custom modifications that may break Nagios XI.

For this solution to work, Grafana requires the PNP4Nagios module to be installed. Nagios XI comes bundled with version 0.4.x of PNP4Nagios which is used for the generation of the RRD files. This solution requires PNP4Nagios 0.6.x to be installed, however it needs to be clearly stated that this installation is completely separate and isolated from Nagios XI. Installing 0.6.x using this guide will not interfere with your Nagios XI server.

This solution works with [ RHEL 6/7 | CentOS 6/7 | Oracle Linux 6/7 | Debian 8/9 | Ubuntu 14/16/18 ] however only the 64-bit (x86_64) implementations of these operating systems (OS) will work, it does not work on 32-bit (x86).

The instructions below require a terminal session to your Nagios XI server as the root user.

 


Install Grafana

Please follow the Grafana installation documentation:

http://docs.grafana.org/installation/rpm/

Just follow the install steps, starting the service and other steps continue below in this guide.

 

Once installed, execute the following commands to start the service and ensure it is enabled to start on boot:

===== RHEL 6 | CentOS 6 | Oracle Linux 6 | Ubuntu 14 =====

chkconfig --add grafana-server
service grafana-server start

 

===== Ubuntu 14 =====

update-rc.d grafana-server defaults
service grafana-server start

 

===== RHEL 7 | CentOS 7 | Oracle Linux 7 | Debian 8/9 | Ubuntu 16/18 =====

systemctl enable grafana-server.service
systemctl start grafana-server.service

 

You need to allow port 3000 inbound traffic on the local firewall so you can reach the Grafana web interface:

===== RHEL 6 | CentOS 6 | Oracle Linux 6 =====

iptables -I INPUT -p tcp --destination-port 3000 -j ACCEPT
service iptables save
ip6tables -I INPUT -p tcp --destination-port 3000 -j ACCEPT
service ip6tables save

 

===== RHEL 7 | CentOS 7 | Oracle Linux 7 =====

firewall-cmd --zone=public --add-port=3000/tcp
firewall-cmd --zone=public --add-port=3000/tcp --permanent

 

===== Ubuntu =====

sudo ufw allow 3000/tcp
sudo ufw reload

 

===== Debian =====

iptables -I INPUT -p tcp --destination-port 3000 -j ACCEPT

 

 

Install PNP Components

Execute these commands to download and install PNP4Nagios:

===== RHEL 6/7 | CentOS 6/7 | Oracle Linux 6/7 =====

cd /tmp
wget -O pnp4nagios.tar.gz https://github.com/lingej/pnp4nagios/archive/0.6.26.tar.gz
tar xzf pnp4nagios.tar.gz
cd pnp4nagios-0.6.26
./configure --with-perfdata-dir=/usr/local/nagios/share/perfdata
make all
make install
make install-webconf
rm -f /usr/local/pnp4nagios/share/install.php

 

===== Debian | Ubuntu =====

cd /tmp
wget -O pnp4nagios.tar.gz https://github.com/lingej/pnp4nagios/archive/0.6.26.tar.gz
tar xzf pnp4nagios.tar.gz
cd pnp4nagios-0.6.26
./configure --with-perfdata-dir=/usr/local/nagios/share/perfdata --with-httpd-conf=/etc/apache2/sites-enabled
make all
make install
make install-webconf
rm -f /usr/local/pnp4nagios/share/install.php

 

===== All =====

Execute these commands to install the PNP4Nagios components for Grafana:

grafana-cli plugins install sni-pnp-datasource
cd /usr/local/pnp4nagios/share/application/controllers/
wget -O api.php "https://github.com/lingej/pnp-metrics-api/raw/master/application/controller/api.php"

 

You also need to restart the grafana-server service:

===== RHEL 6 | CentOS 6 | Oracle Linux 6 | Ubuntu 14 =====

service grafana-server restart

 

===== RHEL 7 | CentOS 7 | Oracle Linux 7 | Debian 8/9 | Ubuntu 16/18 =====

systemctl restart grafana-server.service

 

 

Grant localhost Permission To PNP4Nagios Site

Grafana will be making calls to the PNP API and will require permission. The changes required differ slightly depending on your OS version. Both methods are changing the Apache pnp4nagios.conf file to only allow the Nagios XI server to connect.

 

===== RHEL 6 | CentOS 6 | Oracle Linux 6 =====

The following line is going to be added:

Allow from 127.0.0.1 ::1

These lines will be commented out:

Allow from all
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user

 

The following commands will make those changes:

sed -i '/Allow from all/a\        Allow from 127.0.0.1 ::1' /etc/httpd/conf.d/pnp4nagios.conf
sed -i 's/Allow from all/#&/' /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

 

The Apache httpdservice needs to be restarted for this change to take affect:

service httpd restart

 

Please proceed to the Test PNP4Nagios section.

 

===== RHEL 7 | CentOS 7 | Oracle Linux 7 =====

 The following lines are going to be added:

Require ip 127.0.0.1 ::1
Require all granted

These lines will be commented out:

Order allow,deny
Allow from all
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user

 

The following commands will make those changes:

sed -i 's/Order allow,deny/#&/' /etc/httpd/conf.d/pnp4nagios.conf
sed -i '/Allow from all/a\        Require ip 127.0.0.1 ::1' /etc/httpd/conf.d/pnp4nagios.conf
sed -i 's/Allow from all/#&/' /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 '/Require valid-user/a\        Require all granted' /etc/httpd/conf.d/pnp4nagios.conf
sed -i 's/Require valid-user/#&/' /etc/httpd/conf.d/pnp4nagios.conf

 

The Apache httpd service needs to be restarted for this change to take affect:

systemctl restart httpd.service

 

Please proceed to the Test PNP4Nagios section.

 

===== Debian | Ubuntu =====

 The following lines are going to be added:

Require ip 127.0.0.1 ::1
Require all granted

These lines will be commented out:

Order allow,deny
Allow from all
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user

 

The following commands will make those changes:

sed -i 's/Order allow,deny/#&/' /etc/apache2/sites-enabled/pnp4nagios.conf
sed -i '/Allow from all/a\        Require ip 127.0.0.1 ::1' /etc/apache2/sites-enabled/pnp4nagios.conf
sed -i 's/Allow from all/#&/' /etc/apache2/sites-enabled/pnp4nagios.conf
sed -i 's/AuthType Basic/#&/' /etc/apache2/sites-enabled/pnp4nagios.conf
sed -i 's/AuthUserFile/#&/' /etc/apache2/sites-enabled/pnp4nagios.conf
sed -i '/Require valid-user/a\        Require all granted' /etc/apache2/sites-enabled/pnp4nagios.conf
sed -i 's/Require valid-user/#&/' /etc/apache2/sites-enabled/pnp4nagios.conf

 

The Apache service needs to be restarted for this change to take affect:

===== Ubuntu 14 =====

service apache2 restart

===== Debian 8/9 | Ubuntu 16/18 =====

systemctl restart apache2.service

 

Please proceed to the Test PNP4Nagios section.

 

 

Test PNP4Nagios

To ensure that PNP4Nagios will accept calls from the Nagios XI server execute the following command:

curl http://localhost/pnp4nagios

 

If it was successful then the output will be something like:

<!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>
<hr>
<address>Apache/2.2.15 (Red Hat) Server at localhost Port 80</address>
</body></html>

 

If it was successful then you can proceed to the Grafana Configuration section.

 

An unsuccessful attempt will result in a message similar to:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Unauthorized</title>
</head><body>
<h1>Unauthorized</h1>
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
</body></html>

OR 

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>401 Authorization Required</title>
</head><body>
<h1>Authorization Required</h1>
<p>This server could not verify that you
are authorized to access the document
requested.  Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn't understand how to supply
the credentials required.</p>
<hr>
<address>Apache/2.2.15 (CentOS) Server at xi-c6x-x64 Port 80</address>
</body></html>

 

If you are not successful then you will need to review and fix your Apache configuration above before proceeding.

 

 

Grafana Configuration

Grafana needs to be configured to use the PNP4Nagios API. Open your web browser to the following URL:

http://nagios_server:3000

Replace nagios_server with the DNS record or ip address of your Nagios XI server.

You will be prompted with a login page, the default username is admin and the password is admin.

You will be presented with the Home Dashboard and you'll see an Add data source icon, click it to continue.

 

 

On the next screen click the PNP button:

 

 

You will need to populate the following information:

  • HTTP
    • URL: http://localhost/pnp4nagios
    • Access: Server (Default)
  • Auth: Leave settings as default (nothing selected)

 


 

 

Once populated click the Save & Test button. When the screen refreshes, if all settings are correct you will be notified that the Data source is working.

The next step is to create a dashboard & graph.

 

 

Create Dashboard + Graph

Now that Grafana has been configured you need to create a dashboard and then add a graph to the dashboard.

On the left navigation men hover over the + icon and select Create > Dashboard.

 


 

This creates an empty dashboard that needs panels added to it, this example will add a Graph panel.

 


 

An empty graph is added to the dashboard, to add data points to the graph click the Panel Title and select Edit.

 


 

This opens the editor interface for the panel. At the bottom you can see a list of tabs and the Metrics tab is selected by default. On this tab you will be able to add metric(s) to the graph using queries. This example is going to show you how create a graph for the localhost object that has the Current Load service. This is being used because the Current Load service has three separate data sources that need to be added to the graph.

  • Metrics tab
    • Next to Host click select host and select localhost
    • Next to Service click select service and select Current Load
    • Next to Label click select performance label and select load1
    • You will now see this metric has been added to the graph
    • Underneath this query click the Add Query button
    • Repeat the steps above to add the load5 and load15 metrics
  • General Tab
    • Give it the title localhost Current Load

 


 

After making those choices click the Back to dashboard button at the top right of the screen. You will exit the edit mode and the graph will now appear with the metrics you just added.

 

 

Click the Save icon in the top right corner of the screen and provide a name when prompted.

 


 

 

This completes the documentation on using Grafana with Nagios XI performance data.

 

 

Additional Reading

To get the most out of Grafana and PNP4Nagios you should check out the documentation:

http://docs.grafana.org/guides/getting_started/

https://github.com/sni/grafana-pnp-datasource 

 

 

Final Thoughts

For any support related questions please visit the Nagios Support Forums at:

http://support.nagios.com/forum/

4.5 (2)
Article Rating (2 Votes)
Rate this article
  • Icon PDFExport to PDF
  • Icon MS-WordExport to MS Word
Attachments Attachments
There are no attachments for this article.
Related Articles RSS Feed
Nagios XI - Exploring the Graph Explorer
Viewed 659 times since Mon, Aug 3, 2015
Nagios XI - Standard Edition Reports
Viewed 419 times since Tue, Jul 18, 2017
Nagios XI - Using Nagios BPI
Viewed 633 times since Thu, Jan 28, 2016
Nagios XI - Performance Data Averaging
Viewed 816 times since Mon, Nov 6, 2017
Nagios XI - Link Directly to Graph Explorer Graphs
Viewed 836 times since Mon, Apr 6, 2015
Nagios XI - Generating Reports With Nagios XI
Viewed 2336 times since Tue, Jan 6, 2015
Nagios XI - Enterprise Edition Reports
Viewed 479 times since Tue, Jul 18, 2017
Nagios XI - Leveraging and Understanding Performance Data and Graphs - NWC13
Viewed 703 times since Thu, Feb 4, 2016
Nagios XI - Using Views
Viewed 540 times since Thu, Jan 28, 2016
Nagios XI - Installing Dashlets
Viewed 541 times since Wed, Jan 27, 2016