Page 1 of 1

graph template line color

Posted: Mon May 26, 2014 10:34 am
by brandon.pal
Hey All,

I've created a custom disk check that analizes % free on all disks and outputs the data. Check works great. I've also created a custom graph that shows all disks in one graph. I'm using a loop to get all the drives added to one graph.

My questions is how can I get the color of the line to change in each loop iteration. I've tried adding an if and case statement into the loop but as soon as I do that my graph dies.

Any ideas?

My Current Graph Code is:

Code: Select all

<?php

$arrayCount=count($DS);

$opt[1] = "--vertical-label \"% Used\" -l0 --title \"Disk Space Usage for $hostname / $servicedesc\" ";

for($i=1; $i<=$arrayCount; $i++) {

  $def[1] .= "DEF:$NAME[$i]=$rrdfile:$DS[$i]:AVERAGE " ;
  $def[1] .= "LINE1:$NAME[$i]#0000FF:\"\"$NAME[$i] " ;
  $def[1] .= "GPRINT:$NAME[$i]:LAST:\"%3.2lf $unit[i] CUR \" ";
  $def[1] .= "GPRINT:$NAME[$i]:MAX:\"%3.2lf $unit[i] MAX \" ";
  $def[1] .= "GPRINT:$NAME[$i]" . ':AVERAGE:"%3.2lf $unit[i] AVG \j" ';
}
?>

Re: graph template line color

Posted: Mon May 26, 2014 7:16 pm
by Box293
You could create an array of colors before running the loop and then use the $i to reference the color in the array.

For example:

Code: Select all

$colors = array(
 1 => "#0000FF",
 2 => "#00FFFF",
 3 => "#FFFFFF"
 );
then inside the for statement:

Code: Select all

  $def[1] .= "LINE1:$NAME[$i]".$colors[$i].":\"\"$NAME[$i] " ;
Something along those lines

If the amount of disks is unknown, create an array of about 20 colors so that it'll always work.

Re: graph template line color

Posted: Tue May 27, 2014 8:08 am
by brandon.pal
Works perfectly. THANK YOU :D

Re: graph template line color

Posted: Tue May 27, 2014 9:41 am
by tmcdonald
Closing as solved.