Calculating Rate of Change on Disk Volumes

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Calculating Rate of Change on Disk Volumes

Post by Box293 »

I'll get you to send me the template and an example rrd and xml file so I can have a look at what could be happening.

Zip them all up into one file and email it to [email protected].
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
User avatar
rseiwert
Posts: 196
Joined: Wed Jun 22, 2011 10:33 pm
Location: Somewhere between Here and Now

Re: Calculating Rate of Change on Disk Volumes

Post by rseiwert »

Been going nuts trying to grab the $DS and loop thru it's data sources but this fails for me. If I hardcode for one volume my stuff works but I need to be able to generate multiple charts for multiple volumes. Since I use WMI to pull ALL drives for each host there is between 1 and some arbitrary number. For the single case I got it working OK, just need to figure out how to blank the invalid dates and control the time window inside the template. I'm sure there are php variables exposed to the template but I cannot seem to find a list of them.
Where I am so far.
Image
Grumpy Olde IT Guy
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Calculating Rate of Change on Disk Volumes

Post by sreinhardt »

Could you provide an example of the code you currently have working? I'm sure we can play with it on wmi or other check results\rrd files here.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
User avatar
rseiwert
Posts: 196
Joined: Wed Jun 22, 2011 10:33 pm
Location: Somewhere between Here and Now

Re: Calculating Rate of Change on Disk Volumes

Post by rseiwert »

I will have to post something soon. Still looking at it myself. The problem I save is that I have 17 performance counters in my check. Using the defualt template produces 17 graphs. Copying the default template and renaming it to match my check only produces 1 graph. I'm sure that check_template.php is iterating thru the dataset and is building the 17 item $def array but Nagios produces only one chart. If I hardcode to one chart it works but my check returns a different number of volumes for each system.
Grumpy Olde IT Guy
User avatar
rseiwert
Posts: 196
Joined: Wed Jun 22, 2011 10:33 pm
Location: Somewhere between Here and Now

Re: Calculating Rate of Change on Disk Volumes

Post by rseiwert »

Maybe this is documented someone but I couldn't find it. A 10 hour trip down the rabbit hole solved my issue and taught me PHP. This is a bug in function pnp_read_service_sources_from_template_file in pnp.inc.php.

When you create a template if you hardcode DEFs you get a chart for each def. When you hardcode a def (ie DEF[1], DEF[2]) it creates a chart for each DEF defined. This is refered to as getting the datasource list from the template. If you don't hard code any DEFs (ie DEF[$i]) it's supposed to use the XML datasource list to generate a graph for each datasource in the XML file. This is where the bug is. To test (as I have said before) simply copy the default.php to your templates and name it your_check_name.php for a service which collects multiple sets of performance data. At this point I was getting only one chart with the name DS1. When I uncommented the debugging lines in the file I got the following

Code: Select all

SERVICEXML: /usr/local/nagios/share/perfdata/iSCSIgroup/Volumes.xml
F1: /usr/local/nagios/share/pnp/templates/check_equallogic_volumes.php
F2: /usr/local/nagios/share/pnp/templates.dist/check_equallogic_volumes.php
FOUND: 0 [I=2][J=6][BUF=	$def[$i] = "DEF:var1=$rrdfile:$DS[$i]:AVERAGE "; ]
FOUND: 0 [I=2][J=6][BUF=	$def[$i] .= "AREA:var1" . _AREA . ":\"$NAME[$i] \" "; ]
FOUND: 0 [I=2][J=6][BUF=	$def[$i] .= "LINE1:var1" . _LINE . ":\"\" "; ]
FOUND: 0 [I=2][J=6][BUF=	$def[$i] .= "GPRINT:var1:LAST:\"%3.4lf $UNIT[$i] LAST \" "; ]
FOUND: 0 [I=2][J=6][BUF=	$def[$i] .= "GPRINT:var1:MAX:\"%3.4lf $UNIT[$i] MAX \" "; ]
FOUND: 0 [I=2][J=6][BUF=	$def[$i] .= "GPRINT:var1:AVERAGE:\"%3.4lf $UNIT[$i] AVERAGE \\n\" "; ]
FOUND: 0 [I=2][J=6][BUF=	$def[$i] .= 'COMMENT:"Equallogic Volumes Template\r" '; ]
FOUND: 0 [I=2][J=6][BUF=	$def[$i] .= 'COMMENT:"Check Command ' . $TEMPLATE[$i] . '\r" '; ]
FOUND: 0 [I=8][J=12][BUF=	logit($def[$i]); ]
Array ( [0] => 0 ) DEF1= 
TEMPLATE_SOURCES: ds1 - check_equallogic_volumes
Array ( [0] => Array ( [id] => 1 [name] => ds1 [template] => check_equallogic_volumes [display_name] => ds1 ) ) 
WE GOT ONE!
1|ds1|check_equallogic_volumes|ds1
Using Template Sources
1|ds1|check_equallogic_volumes|ds1
It might be hard to understand but you can see item zero array and the WE GOT ONE! means it thinks the data source should be pulled from the template. Simply adding a check for a non-zero value causes a null array to be returned which in turn causes it use the XML datasource as you can plainly see below.

Code: Select all

F2: /usr/local/nagios/share/pnp/templates.dist/check_equallogic_volumes.php
Array ( ) TEMPLATE_SOURCES: - check_equallogic_volumes
Array ( ) F1: /usr/local/nagios/share/pnp/templates/check_equallogic_volumes.php
F2: /usr/local/nagios/share/pnp/templates.dist/check_equallogic_volumes.php
Array ( ) TEMPLATE_SOURCES: - check_equallogic_volumes
Array ( ) Using XML File Sources
1|Witness|check_equallogic_volumes|Witness
2|CSV1|check_equallogic_volumes|CSV1
3|CSV2|check_equallogic_volumes|CSV2
4|ENGMassive|check_equallogic_volumes|ENGMassive
5|SQL2K8Data|check_equallogic_volumes|SQL2K8Data
6|Archive|check_equallogic_volumes|Archive
7|EX3-DB|check_equallogic_volumes|EX3-DB
8|EX3-LOG|check_equallogic_volumes|EX3-LOG
9|EX2-DB|check_equallogic_volumes|EX2-DB
10|EX2-LOG|check_equallogic_volumes|EX2-LOG
11|FSWitness|check_equallogic_volumes|FSWitness
12|EX1-DB|check_equallogic_volumes|EX1-DB
13|EX1-LOG|check_equallogic_volumes|EX1-LOG
Any way I thought I would share since this consumed way to much time for me. The fix I put in place on my system is below

Code: Select all


function pnp_read_service_sources_from_template_file($fname="",$template=""){

        $sources=array();
        $def=array();

        //echo "INCLUDING $fname<BR>\n";
        //include_once($fname);
        $fh=fopen($fname,"r");
        if($fh){
                while(!feof($fh)){
                        $buf=fgets($fh,4096);

                        $i=strpos($buf,"def[");
                        if($i===FALSE)
                                continue;
                        $j=$i+4;
                        $dn=intval($buf[$j]);
                        // RS: added test for to ignore $DEF[$i]
                        if ($dn<>0) {
                                echo "FOUND: $dn [I=$i][J=$j][BUF=$buf]<BR>\n";
                                $def[$dn]=$dn;
                        }
                }
                fclose($fh);
        }

        //print_r($def);

        $n=1;
        foreach($def as $d){

                //echo "DEF".$n."= ".$def[$n]."<BR>\n";

                $name="ds".$n;
                $sources[]=array(
                        "id" => $n,
                        "name" => $name,
                        "template" => $template,
                        "display_name" => perfdata_get_friendly_source_name($name,$template),
                        );

                $n++;
        }

        //echo "TEMPLATE_SOURCES: $name - $template<BR>\n";
        //print_r($sources);

        return $sources;
}

Grumpy Olde IT Guy
User avatar
Box293
Too Basu
Posts: 5126
Joined: Sun Feb 07, 2010 10:55 pm
Location: Deniliquin, Australia
Contact:

Re: Calculating Rate of Change on Disk Volumes

Post by Box293 »

Thanks for sharing, this is really useful information.
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked