Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

<?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?

share|improve this question
    
is this pnp4nagios or another graphing system that has a very similar template format used? –  rackandboneman May 19 '12 at 23:13
    
pnp4nagios I believe –  Kasper Middelboe Petersen May 20 '12 at 5:00
    
Here's one part of your question: the for loop is stopping one short, it should be using "<=" instead of "<". –  Alan Aug 28 '12 at 22:17

1 Answer 1

This stuff is definitely confusing when you first start looking under the hood. You've actually figured out a lot of the key pieces, let's see if I can help you understand how they fit together.

Here's what I've learned through my own experimentation:

1) PNP4Nagios

See their main site: http://docs.pnp4nagios.org/pnp-0.4/start

To verify that you're using PNP4Nagios, look at:

$ more /usr/local/nagios/etc/pnp/pnp4nagios_release
PKG_REL_DATE="05-02-2009"
PKG_VERSION="0.4.14"
PKG_NAME="pnp"

PNP configuration is done in /usr/local/nagios/etc/nagios.cfg

Here's a nice overview that I recently found, it includes a description of the various PNP-related settings in nagios.cfg:

http://bitflip.net/files/pnp4nagios-presentation-20090409.pdf

2) RRD Data Sources and Graph Templates

See: http://docs.pnp4nagios.org/pnp-0.4/tpl

The php template scripts are found in /usr/local/nagios/share/pnp/.

A php graph template is invoked within the context of the RRD data file that's associated with the host or service command whose data you're trying to graph. If there is no template for the command, default.php is used.

As you found, you can't simply add a fourth graph because there's no corresponding datasource:

the 4th graph displays, but with a broken picture icon.

And, as you also found, you can customize the graph that is displayed for a particular datasource:

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

3) default.php

Remember, that default.php is used whenever a host or service command doesn't have an associated graph template. This means that any change you make will affect the default graph for your entire system. If that's what you want, fine. Otherwise, simply add a check for the host and/or service whose graph you're trying to customize:

if ($hostname == 'MyHost') {
  // generate a customized graph
}
else {
  // generate the default graph
}

4) Finally, how to create a combined graph AND display the original three data sources.

I would simply have your perl script generate a fourth datasource and populate it with zeroes:

val1=1;; val2=5;; val3=10;; val4=0;;

Then, in default.php, you can create a custom graph for that datasource:

foreach ($DS as $i) {
  if ($servicedesc == 'My_Test_Service') {
    if ($i == 4) {  # the "val4" placeholder datasource
      // your combined graph logic goes here
    }
    else {
      // datasource 1 to 3 graph logic goes here
    }
  }
}

This just begins to cover this topic, I hope it helps!

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.