Making graphs

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
fantyz
Posts: 4
Joined: Sat May 19, 2012 4:45 am

Making graphs

Post by fantyz »

I've written my own perl script to return status from a server of mine. It is running just fine (ie. performance data: val1=1; val2=5; val3=10).

Using templates.dist/default.php this gives me 3 graphs (as I would expect).

Now this problem I have is, that I wish to make one more graph that has all 3 values in it.

I've been fiddling around with a template file but the results I'm getting seems very random and confusing.

Code: Select all

<?php

for($i=1; $i < count($DS); $i++) {
  $opt[$i] = '--title "My graph '.$i.'"';
  $def[$i] = 'DEF:var1='.$rrdfile.':'.$DS[$i].':AVERAGE LINE1:var1#000000';
}

$opt[4] = '--title "My graph 4"';
$def[4] =
  'DEF:var1='.$rddfile.':'.$DS[1].':AVERAGE '.
  'DEF:var2='.$rddfile.':'.$DS[2].':AVERAGE '.
  'DEF:var3='.$rddfile.':'.$DS[3].':AVERAGE '.
  'LINE1:var1#FF0000:"Var 1" '.
  'LINE1:var2#FF0000:"Var 2" '.
  'LINE1:var3#FF0000:"Var 3"';

?>
With the fourth graph commented out, this usually just draw the first two (not three) graphs (third graph just isen't there). I say usually, because while making this post I checked it again and this time it inisisted on doing 5 graphs where the first 3 was as expected and the last two had a broken picture icon.

When I add the 4th graph it draws 3 graphs. If I add a $def[5] = "hmmm"; then the 4th graph displays, but with a broken picture icon.

I've changed titles to make sure it really is this file and not something cached, but these change like I would expect them them.

Can anyone please shed some light on what is going on here?

Using only the fourth combined graph as $def[1] works.

Trying to debug why it won't display as the fourth graph has led me to nagiosxi/html/includes/components/perfdata/graphApi.php. It looks like it tries to find a fourth datasource from the perfdata xml file located next to the rrd file. This, ofcause, only has 3 datasets as I'm only working with 3 datasets. I need all four graphs.

How do I add more graphs for a given service than the amount of datasets?
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Making graphs

Post by mguthrie »

Currently there's a limitation in Nagios XI that graph templates won't allow for a dynamic number of data sets.
http://tracker.nagios.com/view.php?id=249

You can hard-code the array indices if you have an expected number of graph results. But at the moment it won't work correctly if you're using a "for" loop for each of the datasources.
fantyz
Posts: 4
Joined: Sat May 19, 2012 4:45 am

Re: Making graphs

Post by fantyz »

For a given service, the amount of datasets is constant. I'm not trying to add or remove values from the check script while its running. This means there will always be 3 datasets in $DS - and the for loop will always return the same amount of entries in $DEF and $OPT. I can't see what you possibly could mean this for-loop would break.

This would, however, explain some of the weird behaviour as the number of entries I output from the template varies while I debug/develop the script. But it does not change my problem of not being able to have more graphs than there are datasources. If I hardcode 4 graphs in my template, I would still not get the 4th graph to display.

I could hope that this is something that the issue about dynamic number of datasets would fix, but this is tagged as a minor..? What does this mean for expected fix time?

I work with a fairly large system performing in realtime and lack of support for proper customized graphing is something that could potentially force us to switch to something else, which I personally would be sad to see happen.
mguthrie
Posts: 4380
Joined: Mon Jun 14, 2010 10:21 am

Re: Making graphs

Post by mguthrie »

How do I add more graphs for a given service than the amount of datasets?
I'm not sure I'm understanding this, without a dataset, there's no data to graph.

PNP templates start their array index at 1 instead of 0, that could be what's causing the missing 4th graph?.


For each graph that you want, the template needs to contain a hard-coded array index, starting at one instead of zero. The below example would tell XI to display 4 graphs:

Code: Select all

$def[1] = //add stuff here 
$def[2] = 
$def[3] = 
$def[4] =