Sunteți pe pagina 1din 11

Nagios Core - Us in g Grafan a Wit h PNP4Nagios

Article Number: 803 | Rating: Unrated | Last Updated: Sun, Mar 18, 2018 at 8:16 PM

Na g io s C o r e - Us ing G r a f a na W it h P NP 4 Na g io s
This documentation explains how to install and configure G r a fa na to generate performance graphs with an existing PNP4Nagios solution. This guide relies on having installed and
configured PNP4Nagios using the following documentation:

Nagios Core - Performance Graphs Using PNP4Nagios

If you don't have PNP4Nagios installed and want to use Grafana then you might be interested in this alternate solution:

Nagios Core - Performance Graphs Using InfluxDB + Nagflux + Grafana + Histou

I MP O RTANT

D O NO T fo llo w this guide if yo u are us ing Nagio s XI. This guide is intended fo r Nagio s Co re o nly.

This guide is broken up into several sections and covers different Linux distributions and operating systems (OS). If your Linux Distribution or operating system is not included in this guide
then please contact us to see if we can get it added. Some distributions may be missing as we don't have access to a test environment that allows us to develop the documentation.

N o te : This guide is based on Nagios Core being installed using the following KB article:

Documentation - Installing Nagios Core From Source

Please select your OS:

Red Hat Enterprise Linux (RHEL)

CentOS

Oracle Linux

Ubuntu

SUSE SLES | openSUSE Leap

Debian

Raspbian

Fedora

Arch Linux

Gentoo

FreeBSD

C e nt O S | RHEL | O r a c le L inux
This documentation works on CentOS / RHEL / Oracle Linux version 6+. We were unable to get this solution working on versions prior to 6.x.

Ins t all G r af ana

Please follow the Grafana installation documentation:

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

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

===== CentOS | RHEL | Oracle Linux 6.x =====

chkconfig --add grafana-server


service grafana-server start

===== CentOS | RHEL | Oracle Linux 7.x =====

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:

===== CentOS | RHEL | Oracle Linux 6.x =====

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
===== CentOS | RHEL | Oracle Linux 7.x =====

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


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

Ins t all P NP C o m p o ne nt s

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:

===== CentOS | RHEL | Oracle Linux 6.x =====

service grafana-server restart

===== CentOS | RHEL | Oracle Linux 7.x =====

systemctl restart grafana-server.service

G r ant lo c alho s t P e r m is s io n To P NP 4 Nag io s S it e

Grafana will be making calls to the PNP API and will require permission. This guide focusses on granting access to the local host however with "CentOS | RHEL | Oracle Linux 6.x" a
username/password is required.

===== CentOS | RHEL | Oracle Linux 6.x =====

The following command will add the user grafana with the password ANAFARG to htpasswd.users:

htpasswd -b /usr/local/nagios/etc/htpasswd.users grafana ANAFARG

Please proceed to the Grafana Configuration section for the next step.

===== CentOS | RHEL | Oracle Linux 7.x =====

The method used here is to allow the 127.0.0.1 & ::1 addresses of the Nagios server access. This is defined by adding the following line to pnp4nagios.cfg:

Require ip 127.0.0.1 ::1

The following command will add that line to pnp4nagios.cfg:

sed -i '/Require valid-user/a\ Require ip 127.0.0.1 ::1' /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 Grafana Configuration section for the next step.

Ub unt u
This documentation works on Ubuntu version 16+. We were unable to get this solution working on versions prior to 16.x.

Ins t all G r af ana

Please follow the Grafana installation documentation:

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

Once installed, execute the following commands to start the service and ensure it is enabled to start on boot:
sudo systemctl enable grafana-server.service
sudo 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.

sudo ufw allow 3000/tcp


sudo ufw reload

Ins t all P NP C o m p o ne nt s
Ins t all P NP C o m p o ne nt s

Execute these commands to install the PNP4 components for Grafana:

sudo grafana-cli plugins install sni-pnp-datasource


sudo systemctl restart grafana-server.service
cd /usr/local/pnp4nagios/share/application/controllers/
sudo wget -O api.php "https://github.com/lingej/pnp-metrics-api/raw/master/application/controller/api.php"

G r ant lo c alho s t P e r m is s io n To P NP 4 Nag io s S it e

Grafana will be making calls to the PNP API and will require permission. The method used here is to allow the 127.0.0.1 & ::1 addresses of the Nagios server access. This is defined
by adding the following line to pnp4nagios.cfg:

Require ip 127.0.0.1 ::1

The following command will add that line to pnp4nagios.cfg:

sudo sh -c "sed -i '/Require valid-user/a\ Require ip 127.0.0.1 ::1' /etc/apache2/sites-enabled/pnp4nagios.conf"

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

sudo systemctl restart apache2.service

Please proceed to the Grafana Configuration section for the next step.

S US E S L ES | o p e nS US E L e a p
This documentation was tested on SUSE SLES 12.2+ and openSUSE Leap 42.2+.

Ins t all G r af ana

Please follow the Grafana installation documentation:

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

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

sudo systemctl enable grafana-server.service


sudo 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:

===== SUSE SLES 12.x =====

sudo /usr/sbin/SuSEfirewall2 open EXT TCP 3000


sudo systemctl restart SuSEfirewall2

===== openSUSE Leap 42.x =====

The firewall service is not enabled by defauly on openSUSE.

Ins t all P NP C o m p o ne nt s

Execute these commands to install the PNP4 components for Grafana:

sudo grafana-cli plugins install sni-pnp-datasource


sudo systemctl restart grafana-server.service
cd /usr/local/pnp4nagios/share/application/controllers/
sudo wget -O api.php "https://github.com/lingej/pnp-metrics-api/raw/master/application/controller/api.php"

G r ant lo c alho s t P e r m is s io n To P NP 4 Nag io s S it e

Grafana will be making calls to the PNP API and will require permission. The method used here is to allow the 127.0.0.1 & ::1 addresses of the Nagios server access. This is defined
by adding the following line to pnp4nagios.cfg:

Require ip 127.0.0.1 ::1

The following command will add that line to pnp4nagios.cfg:

sudo sh -c "sed -i '/Require valid-user/a\ Require ip 127.0.0.1 ::1' /etc/apache2/vhosts.d/pnp4nagios.conf"

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

sudo systemctl restart apache2.service


Please proceed to the Grafana Configuration section for the next step.

De b ia n | Ra s p b ia n
This documentation works on Debian / Raspbian version 8+. We were unable to get this solution working on versions prior to 8.x.
All steps on Debian require to run as root. To become root simply run:

Debian:

su

Raspbian:

sudo -i

All commands from this point onwards will be as root.

Ins t all G r af ana

Please follow the Grafana installation documentation:

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

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

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.

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

Ins t all P NP C o m p o ne nt s

Execute these commands to install the PNP4 components for Grafana:

grafana-cli plugins install sni-pnp-datasource


systemctl restart grafana-server.service
cd /usr/local/pnp4nagios/share/application/controllers/
wget -O api.php "https://github.com/lingej/pnp-metrics-api/raw/master/application/controller/api.php"

G r ant lo c alho s t P e r m is s io n To P NP 4 Nag io s S it e

Grafana will be making calls to the PNP API and will require permission. The method used here is to allow the 127.0.0.1 & ::1 addresses of the Nagios server access. This is defined
by adding the following line to pnp4nagios.cfg:

Require ip 127.0.0.1 ::1

The following command will add that line to pnp4nagios.cfg:

sed -i '/Require valid-user/a\ Require ip 127.0.0.1 ::1' /etc/apache2/sites-enabled/pnp4nagios.conf

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

systemctl restart apache2.service

Please proceed to the Grafana Configuration section for the next step.

Fe d o r a
Ins t all G r af ana

Please follow the Grafana installation documentation:

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

Once installed, execute the following commands to start the service and ensure it is enabled to start on boot:
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:

firewall-cmd --zone=FedoraServer --add-port=3000/tcp


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

Ins t all P NP C o m p o ne nt s

Execute these commands to install the PNP4 components for Grafana:

grafana-cli plugins install sni-pnp-datasource


systemctl restart grafana-server.service
cd /usr/local/pnp4nagios/share/application/controllers/
wget -O api.php "https://github.com/lingej/pnp-metrics-api/raw/master/application/controller/api.php"

G r ant lo c alho s t P e r m is s io n To P NP 4 Nag io s S it e

Grafana will be making calls to the PNP API and will require permission. The method used here is to allow the 127.0.0.1 & ::1 addresses of the Nagios server access. This is defined
by adding the following line to pnp4nagios.cfg:

Require ip 127.0.0.1 ::1

The following command will add that line to pnp4nagios.cfg:

sed -i '/Require valid-user/a\ Require ip 127.0.0.1 ::1' /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 Grafana Configuration section for the next step.

A r c h L inux
Ins t all G r af ana

Please follow these instructions to install Grafana:

pacman --noconfirm -Syyu


pacman --noconfirm -S grafana

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

systemctl enable grafana.service


systemctl start grafana.service

Arch Linux does not have a firewall enabled in a fresh installation. Please refer to the Arch Linux documentation on allowing TCP port 3000 inbound.

Ins t all P NP C o m p o ne nt s

Execute these commands to install the PNP4 components for Grafana:

grafana-cli plugins install sni-pnp-datasource


systemctl restart grafana.service
cd /usr/local/pnp4nagios/share/application/controllers/
wget -O api.php "https://github.com/lingej/pnp-metrics-api/raw/master/application/controller/api.php"

G r ant lo c alho s t P e r m is s io n To P NP 4 Nag io s S it e

Grafana will be making calls to the PNP API and will require permission. The method used here is to allow the 127.0.0.1 & ::1 addresses of the Nagios server access. This is defined
by adding the following line to pnp4nagios.cfg:

Require ip 127.0.0.1 ::1

The following command will add that line to pnp4nagios.cfg:

sed -i '/Require valid-user/a\ Require ip 127.0.0.1 ::1' /etc/httpd/conf/extra/pnp4nagios.conf

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

systemctl restart httpd.service

Please proceed to the Grafana Configuration section for the next step.

G e nt o o
Ins t all G r af ana

Please follow these instructions to install Grafana:

emerge --sync
echo ">=www-apps/grafana-bin-5.0.0 **" >> /etc/portage/package.accept_keywords
emerge --noreplace www-apps/grafana-bin

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

rc-update add grafana default


rc-service grafana start

Gentoo does not have a firewall enabled in a fresh installation. Please refer to the Gentoo documentation on allowing TCP port 3000 inbound.

Ins t all P NP C o m p o ne nt s

Execute these commands to install the PNP4 components for Grafana:

grafana-cli plugins install sni-pnp-datasource


ln -s /var/lib/grafana/plugins/sni-pnp-datasource /usr/share/grafana/data/plugins
rc-service grafana restart
cd /usr/local/pnp4nagios/share/application/controllers/
wget -O api.php "https://github.com/lingej/pnp-metrics-api/raw/master/application/controller/api.php"

G r ant lo c alho s t P e r m is s io n To P NP 4 Nag io s S it e

Grafana will be making calls to the PNP API and will require permission. The method used here is to allow the 127.0.0.1 & ::1 addresses of the Nagios server access. This is defined
by adding the following line to pnp4nagios.cfg:

Require ip 127.0.0.1 ::1

The following command will add that line to pnp4nagios.cfg:

sed -i '/Require valid-user/a\ Require ip 127.0.0.1 ::1' /etc/apache2/vhosts.d/pnp4nagios.conf

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

rc-service apache2 restart

Please proceed to the Grafana Configuration section for the next step.

Fr e e B S D
Ins t all G r af ana

Please follow these instructions to install Grafana:

pkg install -y grafana4

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

echo 'grafana_enable="YES"' >> /etc/rc.conf


service grafana onestart

FreeBSD does not have a firewall enabled in a fresh installation. Please refer to the FreeBSD documentation on allowing TCP port 3000 inbound.

Ins t all P NP C o m p o ne nt s

Execute these commands to install the PNP4 components for Grafana:

grafana-cli plugins install sni-pnp-datasource


service grafana onerestart
service grafana onerestart
cd /usr/local/pnp4nagios/share/application/controllers/
wget -O api.php "https://github.com/lingej/pnp-metrics-api/raw/master/application/controller/api.php"

G r ant lo c alho s t P e r m is s io n To P NP 4 Nag io s S it e

Grafana will be making calls to the PNP API and will require permission. The method used here is to allow the 127.0.0.1 & ::1 addresses of the Nagios server access. This is defined
by adding the following line to pnp4nagios.cfg:

Require ip 127.0.0.1 ::1

The following command will add that line to pnp4nagios.cfg:

perl -ni.bak -le 'print; print " Require ip 127.0.0.1 ::1" if /Require valid-user/' /usr/local/etc/apache24/Includes/pnp4nagios.conf

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

service apache24 onerestart

Please proceed to the Grafana Configuration section for the next step.

G r a f a na C o nf ig ur a t io n
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 Core 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 Ad d d a ta s o ur c e icon, click it to continue.
You will need to populate the following information:

Name: PNP
Type: PNP
HTTP
URL: http://localhost/pnp4nagios
Access: proxy
Auth: Leave settings as default (nothing selected)
IF you are using CentOS | RHEL | Oracle Linux 6.x
Tick the box B a s ic Auth
Under B a s ic Auth De ta ils populate the username and password as per the steps earlier (grafana / ANAFARG)
Once populated click the S a ve & T e s t button. When the screen refreshes, if all settings are correct you will be notified that the Da ta s o ur c e is w o r king .

The next step is to create a dashboard & graph.

C r e a t e Da s hb o a r d + G r a p h
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 C r e a te > Da s hb o a r d .

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 P a ne l T itle and select Ed it .

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
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 lo c a lho s t object that has the C ur r e nt Lo a d 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 Ho s t click s e le c t ho s t and select lo c a lho s t
Next to S e r vic e click s e le c t s e r vic e and select C ur r e nt Lo a d
Next to La b e l click s e le c t p e r fo r ma nc e la b e l and select lo a d 1
You will now see this metric has been added to the graph
Underneath this query click the Ad d Q ue r y button
Repeat the steps above to add the lo a d 5 and lo a d 15 metrics
General Tab
Give it the title lo c a lho s t C ur r e nt Lo a d

After making those choices click the B a c k to d a s hb o a r d 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 S a ve icon in the top right corner of the screen and provide a name when prompted.
Click the S a ve icon in the top right corner of the screen and provide a name when prompted.

This completes the steps required for using Grafana With PNP4Nagios on Nagios Core.

A d d it io na l Re a d ing
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

Fina l T ho ug ht s
For any support related questions please visit the Nagios Support Forums at:

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

Posted by: tle a - Wed, Mar 7, 2018 at 5:40 PM. This article has been viewed 1936 times.

Online URL: https://support.nagios.com/kb/article/nagios- core- using- grafana- with- pnp4nagios- 803.html

S-ar putea să vă placă și