Sunday, October 14, 2012

Monitoring tool - pnp4nagios special template


When we use Icinga or Nagios with pnp4nagios for graphing the resources of hardwares or middle wares, we often want to look a resource graph from several services in one graph like load average of all of the servers or HTTP response time of web servers to compare them and examine each the difference.
We can make it by creating own templates called special template with pnp4nagios.

"special templates (starting with PNP 0.6.5) are used to combine data from arbitrary hosts and services and thus are not connected directly to a host or service.", says about pnp4nagios special template, here.

Then, what is it like the special template? This is an example which combines load average from all of the hosts in one graph.
sample_load.php
<?php
$this->MACRO['TITLE']   = "LOADAVERAGE";
$this->MACRO['COMMENT'] = "For All Servers";
$services = $this->tplGetServices("","LOADAVERAGE$");
# The Datasource Name for Graph 0
$ds_name[0] = "LOADAVERAGE";
$opt[0]     = "--title \"LOADAVERAGE\"";
$def[0]     = "";
# Iterate through the list of hosts
foreach($services as $key=>$val){
  $data = $this->tplGetData($val['host'],$val['service']);
  #throw new Kohana_exception(print_r($a,TRUE));
  $hostname   = rrd::cut($data['MACRO']['HOSTNAME']);
  $def[0]    .= rrd::def("var$key" , $data['DS'][0]['RRDFILE'], $data['DS'][0]['DS'] );
  $def[0]    .= rrd::line1("var$key", rrd::color($key), $hostname);
  $def[0]    .= rrd::gprint("var$key", array("MAX", "AVERAGE"));
}
?> 


The sample template is on my github. Please see the official reference for more detailed information about how to define the special template.

Next, I would like to demonstrate about how to create own template for the number of http accesses one by one, including setting up nagios plugin, pnp4nagios custom template and special template.
If you need to install Icinga or pnp4nagios, please see the past articles, here.

This is the graph which sample_apache_access.php generates.


  • setup nagios plugin (/usr/local/icinga/libexec)
# for modules in LWP::UserAgent Time::HiRes Digest::MD5 ; docpan -if $modules ; done
# wget  http://blog.spreendigital.de/wp-content/uploads/2009/07/check_apachestatus_auto.tgz -O- | tar zx
# ./check_apachestatus_auto.pl -H 127.0.0.1
APACHE OK - 0.050 sec. response time, Busy/Idle 1/9, open 246/256, ReqPerSec 0.4, BytesPerReq 17, BytesPerSec 5|Idle=9 Busy=1 OpenSlots=246 Slots=256 Starting=0 Reading=0 Sending=1 Keepalive=0 DNS=0 Closing=0 Logging=0 Finishing=0 ReqPerSec=0.350877 BytesPerReq=17 BytesPerSec=5.988304 Accesses=60

  • enable mod_status module if it's not enable(httpd.conf or including configuration)
ExtendedStatus On
<VirtualHost *:80>
  ServerName 127.0.0.1
  <Location /server-status>
    SetHandler server-status
    Order deny,allow
    Allow from 192.168.0.0/24
  </Location>
</VirtualHost>

  • define command and service configuration for Icinga/Nagios
define command{
        command_name    check_apache_performance
        command_line    $USER1$/check_apachestatus_auto.pl -H $HOSTADDREESS$ -t $ARG1$
}
define  service{
        use                    generic-service
        host_name               ha-mgr02, eco-web01, eco-web02
        service_description     Apache:Performance
        check_command           check_apache_performance!60
}
※Make sure that the hosts are defined on hosts.cfg.

  • setup custom template
    put check_apache_performance.php on /usr/local/pnp4nagios/share/template/
  • setup special template
    put sample_apache_access.php on /usr/local/pnp4nagios/share/templates.special/
  • Take a look at http://<your icinga server>/pnp4nagios/special?tpl=sample_apache_access

Lastly, I'm going to show you some examples.

Let's enjoy creating your own template and saving time to look around all of the graphs.

No comments:

Post a Comment

iJAWS@Doorkeeper