Graphing Nagios services with pnp4nagios 0.6

A few years ago I wrote a guide on using pnp4nagios with Nagios. Since then pnp4nagios has had a major version update and the guide could use a refresh.

pnp4nagios is a graphing framework with portions written in perl, PHP and C for automatically parsing performance data collected by Nagios plugins. The data is collected into RRD databases for display in the Nagios web interface. The graphs created by pnp4nagios are similar to other monitoring tools like Cacti.

pnp4nagios is designed to work well with the standard Nagios plugins and create useable graphs right out of the box. The appearance of the graphs can be customized.

Pages of related graphs (for instance, CPU usage or TCP connections of each server in a web farm) can be easily defined and displayed in HTML or exported to PDF.

pnp4nagios requires perl, PHP (built with XML, zlib and GD support) and rrdtool. It can optionally use the rrd perl modules for better performance. Packages for Fedora, Debian and Ubuntu are available. My example will use Ubuntu Server 12.04 with the bundled perl, PHP and Apache packages. Nagios has been installed from source to the default location of /usr/local/nagios.

Installing pnp4nagios

By default, pnp4nagios 0.6 installs into its own directory – a change from version 0.4 which was installed in your nagios directory.

jason@ubuntu:~/pnp4nagios-0.6.17$ ./configure
*** Configuration summary for pnp4nagios-0.6.17 03-25-2012 ***

  General Options:
  -------------------------         -------------------
  Nagios user/group:                nagios nagios
  Install directory:                /usr/local/pnp4nagios
  HTML Dir:                         /usr/local/pnp4nagios/share
  Config Dir:                       /usr/local/pnp4nagios/etc
  Location of rrdtool binary:       /usr/bin/rrdtool Version 1.4.7
  RRDs Perl Modules:                FOUND (Version 1.4007)
  RRD Files stored in:              /usr/local/pnp4nagios/var/perfdata Logfile:      /usr/local/pnp4nagios/var/perfdata.log
  Perfdata files (NPCD) stored in:  /usr/local/pnp4nagios/var/spool

  Web Interface Options:
  -------------------------         -------------------
  HTML URL:                         http://localhost/pnp4nagios
  Apache Config File:               /etc/apache2/conf.d/pnp4nagios.conf

jason@ubuntu:~/pnp4nagios-0.6.17$ sudo make all
jason@ubuntu:~/pnp4nagios-0.6.17$ sudo make install
jason@ubuntu:~/pnp4nagios-0.6.17$ sudo make install-webconf
jason@ubuntu:~/pnp4nagios-0.6.17$ sudo make install-config

Configuring pnp4nagios

The main configuration file for pnp4nagios is /usr/local/pnp4nagios/etc/config.php

Before configuring pnp, we need to decide how we want Nagios to process the performance data. This largely depends on the number of monitored hosts and services of Nagios.

Default mode, where is executed after each host and service check, is ok for very small installations.

Bulk mode, where performance information is appended to a temporary file and processed after a short interval, is fine for medium-sized installations.

Setups with hundreds of hosts and services should use bulk mode with npcd, where a separate multi-threaded daemon handles the processing. Version 0.6 introduced integration with gearman – which might be useful if your monitored hosts grow beyond what your nagios server can handle.

Our example will use Bulk mode, but it is possible to switch between modes as your Nagios setup grows.

Edit the performance data section of /usr/local/nagios/etc/nagios.cfg, making the changes noted in Bold:

# This determines whether or not Nagios will process performance 
# data returned from service and host checks.  If this option is 
# enabled, host performance data will be processed using the 
# host_perfdata_command (defined below) and service performance 
# data will be processed using the service_perfdata_command (also 
# defined below).  Read the HTML docs for more information on 
# performance data. 
# Values: 1 = process performance data, 0 = do not process performance data 


# These commands are run after every host and service check is 
# performed.  These commands are executed only if the 
# enable_performance_data option (above) is set to 1.  The command 
# argument is the short name of a command definition that you 
# define in your host configuration file.  Read the HTML docs for 
# more information on performance data. 


# These files are used to store host and service performance data. 
# Performance data is only written to these files if the 
# enable_performance_data option (above) is set to 1. 


# These options determine what data is written (and how) to the 
# performance data files.  The templates may contain macros, special 
# characters (\t for tab, \r for carriage return, \n for newline) 
# and plain text.  A newline is automatically added after each write 
# to the performance data file.  Some examples of what you can do are 
# shown below. 


# This option determines whether or not the host and service 
# performance data files are opened in write ("w") or append ("a") 
# mode. If you want to use named pipes, you should use the special 
# pipe ("p") mode which avoid blocking at startup, otherwise you will 
# likely want the defult append ("a") mode.


# These options determine how often (in seconds) the host and service 
# performance data files are processed using the commands defined 
# below.  A value of 0 indicates the files should not be periodically 
# processed. 


# These commands are used to periodically process the host and 
# service performance data files.  The interval at which the 
# processing occurs is determined by the options above. 


At the end of /usr/local/nagios/etc/objects/commands.cfg, add the command definitions:

define command {
command_name    process-service-perfdata-file
command_line    /usr/local/pnp4nagios/libexec/ --bulk=/usr/local/pnp4nagios/var/service-perfdata

define command {
command_name    process-host-perfdata-file
command_line    /usr/local/pnp4nagios/libexec/ --bulk=/usr/local/pnp4nagios/var/host-perfdata

There is one other thing to check before running pnp4nagios for the first time. If you don’t want the default resolution for your performance data (1 minute intervals for 2 days up to 6 hour intervals for 4 years), you must create a /usr/local/pnp4nagios/etc/rra.cfg file with your preferences. You can use the snippet below as a template.

# 2880 entries with 1 minute step = 48 hours
# 2880 entries with 5 minute step = 10 days
# 4320 entries with 30 minute step = 90 days
# 5840 entries with 360 minute step = 4 years

Now restart Nagios. If you look in /usr/local/pnp4nagios/var/perfdata, you should start to see rrd files created by pnp4nagios for all your monitored hosts and services.

Verify that you have all the components to use the web interface by checking http://your-nagios-host/pnp4nagios/

Correct any missing components, then delete the /usr/local/pnp4nagios/share/install.php file to see your first graphs:

There is one more step to complete the setup. We need to enable extended info in Nagios so that links to the graphs are created for each applicable host and service.

Append two entries to /usr/local/nagios/etc/objects/templates.cfg:

define host {
name            host-pnp
action_url      /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
register        0

define service {
name            srv-pnp
action_url      /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register        0

These are templates that you add to each host and service definition with graphs:

define host { 
    use                     linux-server,host-pnp 
    host_name               ubuntu 
    alias                   ubuntu 

define service { 
    use                             local-service,srv-pnp 
    host_name                       ubuntu 
    service_description             PING 
    check_command                   check_ping!100.0,20%!500.0,60% 

After restarting Nagios again, the icons for the graphs should appear next to the hosts and services. The image for the graph icon in Nagios in the new exfoliation skin works well – but in the previous Nagios skin you should change /usr/local/nagios/share/images/action.gif to something more appropriate than a bullet hole.

If you’d like to see some more advanced examples of graphing, you can see two in my original presentation.

17 thoughts on “Graphing Nagios services with pnp4nagios 0.6”

  1. i’ve restart all the steps,everything was i removed install.php .but when i go to the link which should graph the PING “”,i have no graph .checking with firebug here is what it says “ ” 404 error .

  2. hello,i’m a beginner in monitoring domain. i’m using ubuntu server 14.04 in which Nagios3 run.i’ve followed the setup procedure as outlined above,and when i check the ,i got this error @PERFDATA_DIR@ is not readable and @RRDTOOL@ is not executable by PHP so can anyone help me?

    1. It sounds like to me like you didn’t follow or forgot a step in the “Installing pnp4nagios” section, as those things that are giving you errors are substituted by the real paths when you run configure.

        1. For instance, the configuration process will substitute /usr/bin/rrdtool for @RRDTOOL@ which is the actual location of the command on your Ubuntu server. You will have to send me the complete output of your install attempt (with a tool like /usr/bin/script) for me to be able to help further. Use the contact form, not these comments, please.

  3. Followed the setup procedure as outlined above, double checked changes, restarted both apache and nagios but still having two problems.
    1. When I look at /usr/local/nagios/share/perfdata I see no files, the directory is empty. Note: I had to manually create the prefdata directory, assigned ownership to user nagios and group nagios, with rw.

    2. When I point the nagios browser to http://localhost/pnp4nagios I get a 404 error, not found. Apache has correct settings point to /usr/local/pnp4nagios/share and the directory has index.php and install.php.

    Any suggestions on how to proceed?

    1. Update;

      Item 1, failed to note that the location has changed, in the write up you say go to /usr/local/nagios/share/perfdata, but in the config inst. you point to /usr/local/pnp4nagios/var/perfdata, and this is being populated.

    2. 1. Looks like I left the path for the older pnp4nagios in the instructions – you should check for rrd files in /usr/local/pnp4nagios/var/perfdata, not /usr/local/nagios/share/perfdata. I updated the instructions.

      2. Did you really mean localhost – as in your web browser is running on the same machine as your pnp4nagios installation?

        1. Substitute your real hostname (fully qualified in DNS) in place of your-nagios-host.

          It seems likely there’s a mismatch between the host in your URL and the virtual host that’s defined on your pnp4nagios server.

          Unfortunately my procedure glosses over the web server configuration. It will be different depending on what flavor of operating system you are running. You should investigate whether the pnp4nagios configuration is defined in the main host or a virtual host and then check your web server logs to see if your requests are reaching the server correctly.

  4. Thanks for this guide. It was very helpful to a point. I think you have a typo where you call the service “service-pnp” and then reference it later as “svr-pnp”. I found you need these both to match for this to work. Cheers.

  5. I have configured pnp4nagios in bulk mode using your tutorial and the problem is that the host-perfdata and service-perfdata are way too huge for these number of hosts and services I have… Shouldn’t those store only the temporary data? After a month of usage the files are 800MB and 4GB huge…

    1. This isn’t normal, the script should delete the files each time it runs. I would set LOG_LEVEL=1 in php4nagios/etc/process_perfdata.cfg and let the collector run a few times. You should see something like “2013-05-17 07:19:20 [19949] [1] /usr/local/pnp4nagios/var/service-perfdata-PID-19949 deleted” in perfdata.log if it is working correctly and and error message if it is not. If you don’t see either of those then maybe isn’t being run at all.

      If your disk is filling up and you have graph data like you expect, it should be ok to delete the host-perfdata and service-perfdata files.

  6. Do you have any ideas on getting a metric that is being process as “seconds” to be graphed as “minutes”?

    In other words- you have a RRD database that has metrics recorded in seconds units, but when you graph you’d like to view the metric in minutes. I’m having a hard time finding any info on unit conversion.

    1. Do you just want to scale up the units? For instance instead of 1 per second you want to see 60 per minute on the graph? If that’s the case you can scale up the units by using a CDEF – see the SNMP example.

Comments are closed.