Skip to content

How to Install Nagiosgraph to Display Graphs in Nagios?

  • by
install nagiosgraph

In the previous article, we explained about displaying graphics in Nagios using pnp4nagios. In this article, we will use Nagiosgraph to display graphs in Nagios.

 

Problem

How to install nagiosgraph to display graphs in Nagios?

 

Solution

Nagiosgraph is an add-on to Nagios to display graphs and was first released in 2004 and it is written in Perl. Nagiosgraph parses output and performance data from Nagios plugins, and stores the data in RRD files. Nagiosgraph displays data in Nagios trends, as popups for hosts and services, or in separate reports. Graphs are generated and managed via CGI scripts, with a small amount of JavaScript and CSS. As of this writing, the last version of Nagiosgraph is 1.5.2. Here is a workflow drawing of nagiosgraph:

 

Nagiosgraph workflow

 

Here are the ways to install Nagiosgraph:

1. Install the required packages

Install the required packages based on the OS you are using:

 

CentOS

yum install -y rrdtool perl-Time-HiRes php-gd php-xml perl-CPAN rrdtool-perl perl-CGI-*

cd /tmp
wget http://downloads.sourceforge.net/project/nagiosgraph/nagiosgraph/1.5.2/nagiosgraph-1.5.2.tar.gz
tar -xf nagiosgraph-1.5.2.tar.gz
cd nagiosgraph-1.5.2

 

Ubuntu/Debian

sudo apt-get update
sudo apt-get install -y rrdtool librrdp-perl php-gd php-xml librrds-perl

cd /tmp
wget http://downloads.sourceforge.net/project/nagiosgraph/nagiosgraph/1.5.2/nagiosgraph-1.5.2.tar.gz
tar -xf nagiosgraph-1.5.2.tar.gz
cd nagiosgraph-1.5.2

 

OpenSUSE

zypper --non-interactive install rrdtool php-gd php-zlib php-sockets rrdtool-devel perl-rrdtool perl-CGI-Session

cd /tmp
wget http://downloads.sourceforge.net/project/nagiosgraph/nagiosgraph/1.5.2/nagiosgraph-1.5.2.tar.gz
tar -xf nagiosgraph-1.5.2.tar.gz
cd nagiosgraph-1.5.2

 

 

2. Configure Nagiosgraph

Next, copy the command below to configure files and folders of nagiosgraph:

mkdir /usr/local/nagios/nagiosgraph
mkdir /usr/local/nagios/nagiosgraph/var
mkdir /usr/local/nagios/nagiosgraph/var/rrd
 
cp -r etc /usr/local/nagios/nagiosgraph/
sed -i "s#/opt/nagiosgraph/etc#/usr/local/nagios/nagiosgraph/etc#g" cgi/*cgi
sed -i "s#/opt/nagiosgraph/etc#/usr/local/nagios/nagiosgraph/etc#g" lib/insert.pl

cp lib/insert.pl /usr/local/nagios/libexec
cp cgi/*.cgi /usr/local/nagios/sbin
cp share/nagiosgraph.css /usr/local/nagios/share
cp share/nagiosgraph.js /usr/local/nagios/share
cp /usr/local/nagios/nagiosgraph/etc/nagiosgraph.conf /usr/local/nagios/nagiosgraph/etc/nagiosgraph.conf.ori
cp /usr/local/nagios/etc/nagios.cfg /usr/local/nagios/etc/nagios.cfg.bkp

 

Open the file share/nagiosgraph.ssi and change it to be like below script:

<script type="text/javascript" src="/nagios/nagiosgraph.js"></script>

 

and then, copy the file using the below command:

cp share/nagiosgraph.ssi /usr/local/nagios/share/ssi/common-header.ssi
chown nagios:nagios /usr/local/nagios/share/ssi/common-header.ssi

 

Next, change the /usr/local/nagios/nagiosgraph/etc/nagiosgraph.conf file to be like this:

# Location of output from nagiosgraph data processing
logfile = /usr/local/nagios/nagiosgraph/var/nagiosgraph.log

# Location of output from nagiosgraph CGI scripts
cgilogfile = /usr/local/nagios/nagiosgraph/var/nagiosgraph-cgi.log

# Location of nagios performance data log file.
perflog = /usr/local/nagios/var/perfdata.log

# Directory in which to store RRD files
rrddir = /usr/local/nagios/nagiosgraph/var/rrd

# File containing regular expressions to identify service and perf data
mapfile = /usr/local/nagios/nagiosgraph/etc/map

# Nagiosgraph CGI URL.
nagiosgraphcgiurl = /nagios/cgi-bin

# JavaScript: URL to the nagiosgraph javascript file.
javascript = /nagios/nagiosgraph.js

# Stylesheet: URL to the nagiosgraph stylesheet.
stylesheet = /nagios/nagiosgraph.css

# Location of showgroup control file (required for showgroup.cgi)
groupdb = /usr/local/nagios/nagiosgraph/etc/groupdb.conf

 

and then set nagiosgraph files permissions using the commands below:

chown -R nagios:nagios /usr/local/nagios/nagiosgraph
chmod 755 /usr/local/nagios/nagiosgraph/var/rrd
touch /usr/local/nagios/nagiosgraph/var/nagiosgraph.log
chmod 664 /usr/local/nagios/nagiosgraph/var/nagiosgraph.log
touch /usr/local/nagios/nagiosgraph/var/nagiosgraph-cgi.log
chown apache /usr/local/nagios/nagiosgraph/var/nagiosgraph-cgi.log
chmod 664 /usr/local/nagios/nagiosgraph/var/nagiosgraph-cgi.log

 

Next, open your browser and insert the URL below:

http://your_nagios_server/nagios/cgi-bin/showconfig.cgi

 

You should see the display like the image below:

Requirement of nagiosgraph

 

3. Configure Nagios

Next, edit the /usr/local/nagios/etc/nagios.cfg file like this below script:

process_performance_data=1
service_perfdata_file=/usr/local/nagios/var/perfdata.log
service_perfdata_file_template=$LASTSERVICECHECK$||$HOSTNAME$||$SERVICEDESC$||$SERVICEOUTPUT$||$SERVICEPERFDATA$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=30
service_perfdata_file_processing_command=process-service-perfdata

 

After that, copy the nagiosgraph icon:

cp -f share/graph.gif /usr/local/nagios/share/images/action.gif

 

And then copy the below script and paste it to the /usr/local/nagios/share/side.php file under Trends word:

<li><a href="<?php echo $cfg["cgi_base_url"];?>/trends.cgi" target="<?php echo $link_target;?>">Trends</a>
<ul>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/show.cgi" target="<?php echo $link_target;?>">Graphs</a></li>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/showhost.cgi" target="<?php echo $link_target;?>">Graphs by Host</a></li>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/showservice.cgi" target="<?php echo $link_target;?>">Graphs by Service</a></li>
<li><a href="<?php echo $cfg["cgi_base_url"];?>/showgroup.cgi" target="<?php echo $link_target;?>">Graphs by Group</a></li>
</ul>
</li>

 

Copy the scripts below Trends word

 

 

4. Integrate Nagios with Nagiosgraph

After that, we want to integrate Nagiosgraph with Nagios. You can choose the method you use to integrate Nagiosgraph with Nagios from the 3 methods below:

 

 

 

If your display like below when you want to see graph in Nagios:

No data in rrd directory /usr/local/nagios/nagiosgraph/var/rrd

No data in rrd directory

 

you have to wait longer for the nagiosgraph graph to appear in the browser. but if you feel you have waited a long time but the graphics still don’t appear in the browser then usually I reboot my server and then the graphics will appear. But if the graph still doesn’t appear, then check the log.

 

 

Note

1. Like in pnp4nagios, if you want to reset the graphics, then you just stay in the /usr/local/nagios/nagiosgraph/var/rrd folder and there will be several hosts in that folder. If we want to delete the graphics on the vps1 host then use the following command:

rm -rf /usr/local/nagios/nagiosgraph/var/rrd/localhost/*

 

2. In nagiosgraph, if Nagios can not monitor the host then there is no graph like in the image below:

Display of nagiosgraph when the host does not connect


While in pnp4nagios, the graph is still displayed even though the host cannot be monitored by Nagios so it might confuse the sysadmin if they have to analyze an event like in the image below:

Display of pnp4nagios when the host can not be monitored by Nagios

 

References

sourceforge.net
allcloud.io
centlinux.com
blog.ruanbekker.com
sysadminxpert.com
stackoverflow.com
support.nagios.com

 

Print Friendly, PDF & Email

Leave a Reply

Your email address will not be published.