Monday, July 16, 2012

Monitoring tool - pnp4nagios custom template

I introduced about how to setup icinga an icinga-web, and setup icinga-web with pnp4nagios  to setup a monitoring server with icinga and pnp4nagios before. I'm going to show you pnp4nagios custom templates which influences the appearance of RRD graphs.

Why is it necessary to create custom templates?


I belive that the reason is that we are sometimes obliged to look into the graphs with specific hardware resource or performance data, when we analyze or investigate network devices, servers or middle ware performance, for example, how much cpu or memory resources are utilized, how much disk space is left, how much traffic is transferred, and so on.

If you need further information about custom templates for pnp4nagios, please see the official reference.

I'll give you an example of custom template based on default templates($pnp4nagios_prefix/share/templates.dist/interger.php) for traffic and graphs with nagios plugins, check_tcptraffic.

  • check_tcptraffic
# for module in \
Carp \
English \
Nagios::Plugin \
Readonly
do cpan -i install $module ; done
# wget https://trac.id.ethz.ch/projects/nagios_plugins/downloads/check_tcptraffic-2.2.4.tar.gz
# tar zxf check_tcptraffic-2.2.4.tar.gz
# cd check_tcptraffic-2.2.4
# check_tcptraffic -i eth0 -s 100 -w 10 -c 20
TCPTRAFFIC CRITICAL - eth0 182216 bytes/s | TOTAL=182216Byte;10;20 IN=180221Byte;; OUT=1995Byte;; TIME=204852Byte;; 
  • commands.cfg
define command{
        command_name    check_traffic
        command_line    $USER1$/check_tcptraffic -t $ARG1$ -s 1000 -w $ARG2$ -c $ARG3$ -i $ARG4$
        }
  • services.cfg 
define  service{
        use                     generic-service
        host_name               <hostname>
        service_description     TRAFFIC:eth0
        check_command           check_traffic!60!10000000!20000000!eth0
}
  • check_traffic.php (custom template for pnp4nagios)
    ※template_dirs=/usr/local/pnp4nagios/share/templates
<?php
$ds_name[1] = "$NAGIOS_AUTH_SERVICEDESC"; 
$opt[1] = "--vertical-label \"$UNIT[1]\" --title \"$hostname / $servicedesc\" ";
$def[1]  = rrd::def("var1", $RRDFILE[1], $DS[1], "AVERAGE");
$def[1] .= rrd::def("var2", $RRDFILE[2], $DS[2], "AVERAGE");
$def[1] .= rrd::def("var3", $RRDFILE[3], $DS[3], "AVERAGE");

if ($WARN[1] != "") {
    $def[1] .= "HRULE:$WARN[1]#FFFF00 ";
}
if ($CRIT[1] != "") {
    $def[1] .= "HRULE:$CRIT[1]#FF0000 ";       
}
$def[1] .= rrd::line1("var1", "#000000", "$NAME[1]") ;
$def[1] .= rrd::gprint("var1", array("LAST", "AVERAGE", "MAX"), "%6.2lf");
$def[1] .= rrd::area("var2", "#00ff00", "$NAME[2]") ;
$def[1] .= rrd::gprint("var2", array("LAST", "AVERAGE", "MAX"), "%6.2lf");
$def[1] .= rrd::line1("var3", "#0000ff", "$NAME[3]") ;
$def[1] .= rrd::gprint("var3", array("LAST", "AVERAGE", "MAX"), "%6.2lf");
?>

check_traffic.php generates the graphs below.









Other custom templates are open to the public at my github.
These are the list of custom templates and sample graphs.

  • check_apache_performance.php




  • check_connections.php


  • check_cpu.php
 
  • check_disk.php 
 
  • check_diskio.php
 
  • check_http.php

  • check_load.php
 
  • check_mem.php
 
  • check_mysql_health.php
 
  • check_nagios_latency_service.php
 
  • check_traffic.php

iJAWS@Doorkeeper