[rrd-users] pnp4nagios php cdef Grand Total
Joel Brooks
jbrooks at oddelement.com
Mon Sep 20 15:42:46 CEST 2010
This is probably better suited to the pnp4nagios users list, but I thought
I'd post here as well.
I recently set out to do the exact same. Jorge was kind enough to help me
along. The pnp4nagios "special" template (note: requires pnp4nagios 0.6.5+)
below creates a stacked graph showing "messages per hour" on a number of
ironport MTAs and at the bottom of the graph, shows the total of all
messages for all ironports.
The magic variables $rpn_stack and $counter are where the good stuff
happens.
<?php
#
$this->MACRO['TITLE'] = "messages per hour";
$this->MACRO['COMMENT'] = "messages per hour";
#
# Get a List of Services by regex
# Option 1 = 'Host Regex'
# Option 2 = 'Service Regex'
#
$services = $this->tplGetServices("ironport","messages_per_hour");
#
# The Datasource Name for Graph 0
$ds_name[0] = "total messages";
$opt[0] = "--title \"messages per hour\"";
$opt[0] .= " --watermark=\"ironport_messages_per_hour\" ";
$def[0] = "";
# THESE ARE THE MAGIC VARIABLES HERE:
$rpn_stack = ""; # empty RPN string
$counter = -1; # loop counter starting by -1
#
# Iterate through the list of hosts
foreach($services as $key=>$val){
#
# get the data for a given Host/Service
$a = $this->tplGetData($val['host'],$val['service']);
#
# Throw an exception to debug the content of $a
# Just to get Infos about the Array Structure
#
#throw new Kohana_exception(print_r($a,TRUE));
$def[0] .= rrd::def("a$key" ,$a['DS'][0]['RRDFILE'],
$a['DS'][0]['DS'], "AVERAGE");
$def[0] .= rrd::area("a$key", rrd::color($key),
$a['MACRO']['HOSTNAME'], "STACK");
$def[0] .= rrd::gprint("a$key", array("MIN", "MAX", "LAST",
"AVERAGE"), "%3.0lf %s");
# THIS IS WHERE THE MAGIC VARIABLES GET USED:
$rpn_stack .= "a$key,"; # add the current key to the stack
$counter++; # counter +1
}
# AFTER THE FOREACH LOOP, CREATE THE RPN STACK, then use it in a CDEF.
$rpn_stack .= str_repeat("+,", $counter); # build the rpn stack for
rrdtool "a0,a1,+,"
$rpn_stack = substr($rpn_stack, 0, -1); # strip the last comma to avoid
rpn underflow
$def[0] .= rrd::cdef("totals", $rpn_stack); # build a cdef using out rpn
expression
$def[0] .=
rrd::comment("-------------------------------------------------------\\n");
$def[0] .= rrd::comment("Totals\:\t ");
$def[0] .= rrd::gprint("totals", array("MIN", "MAX", "LAST", "AVERAGE")
,"%3.2lf %s");
$def[0] .= rrd::comment(" \\n");
cheers,
J
On Mon, Sep 20, 2010 at 9:24 AM, <Matt.Garrett at shell.com> wrote:
> Folks
>
>
>
> A little off topic but maybe someone can help.
>
>
>
> Using pnp4nagios php template to loop through all rrds of a certain type,
> which works fine.
>
> However I would like to get the Grand Total of all rrds
>
>
>
> I know CDEF is the answer and can do this using php hard coding but just
> cannot find out how to get this to work inside a php foreach loop
>
> e.g
>
> CDEF:total=var1,var2,+,var3,+
>
>
>
> The php code I have been using is:
>
>
>
> foreach($services as $key=>$val){
>
> #
>
> # get the data for a given Host/Service
>
> $data = $this->tplGetData($val['host'],$val['service']);
>
> #
>
> $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("LAST", "MAX"));
>
> }
>
> ?>
>
>
>
> Matthew
>
>
>
> _______________________________________________
> rrd-users mailing list
> rrd-users at lists.oetiker.ch
> https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.oetiker.ch/pipermail/rrd-users/attachments/20100920/b6daad31/attachment-0001.htm
More information about the rrd-users
mailing list