[rrd-users] newbie perl problem with rrds::graph

A Darren Dunham ddunham at taos.com
Fri Jan 15 00:57:36 CET 2010


On Thu, Jan 14, 2010 at 10:33:56AM +0200, Jaakko Kemppainen wrote:
> Hi,

> I'm trying to make a perl script to create graphs, much like in
> http://martybugs.net/linux/hddtemp2.cgi
> Only I would like to pass different amount of data to CreateGraph
> function each time and have that function to loop through parameters
> and create DEF and LINE/GRAPH -lines based on that.
> 
> Something along the lines of (doesn't work but cannot figure out what
> I'm doing wrong):

"doesn't work" isn't very descriptive.  Is it drawing something, but looks
bad?  Is it exiting with an error?  What is occuring?

> sub CreateGraph
>   {
>   # creates graph
>   # inputs: $_[0]: computer id
>   #         $_[1]: interval (ie, day, week, month, year)
>   #         $_[2]: hard drive names for computer (ie, hda, hdb, hdc)
> 
>   $size = scalar @_;  # get total amount of parameters
>   $defs = '';
>   $graphs = '';
> 
>   for($i = 2; $i < $size; $i++) {
>         $defs .= "DEF:$_[$i]=$rrd/$_[$i].rrd:temp:AVERAGE ";

So you're keeping each hard drive's information in a separate RRD file?
That's certainly allowed, but I would normally collect it as multiple DS
in a single RRD.

>       $graphs .= "LINE2:$_[$i]#FF9900:$_[$i]\\: ";
>       $graphs .= "GPRINT:$_[$i]:MIN:  Min\\: %2.lf ",
>       $graphs .= "GPRINT:$_[$i]:MAX: Max\\: %2.lf ",
>       $graphs .= "GPRINT:$_[$i]:AVERAGE: Avg\\: %4.1lf ",
>       $graphs .= "GPRINT:$_[$i]:LAST: Current\\: %2.lf degrees C\\n ",

Here, you're putting all of your graph arguments into a single variable.

>       }
> 
>       RRDs::graph "$img/$_[0]/hddtemp-$_[1].png",
>               "--lazy",
>               "-s -1$_[1]",
>               "-t hdd temperature :: hard disk drives",
>               "-h", "80", "-w", "600",
>               "-a", "PNG",
>               "-v degrees C",
>               "--slope-mode",
>               "$defs",
>               "$graphs";

And you're passing them into RRDs::graph that way.  You want to pass
them in as separate arguments.  Probably the easiest way is instead of
concatenating them, push them onto an array and then pass the array to
graph.

So from
>       $graphs .= "LINE2:$_[$i]#FF9900:$_[$i]\\: ";
>       $graphs .= "GPRINT:$_[$i]:MIN:  Min\\: %2.lf ",
to:
push @graphs, "LINE2:$_[$i]#FF9900:$_[$i]\\: ";
push @graphs,"GPRINT:$_[$i]:MIN:  Min\\: %2.lf ",
[...]

and 
[...]
               "--slope-mode",
	       @defs,
               @graphs;

>       if ( = RRDs::error) { print "$0: unable to generate $_[1] graph:
> $ERROR\n"; }

What error (if any) was reported?  Did it complain about garbage after
command?

-- 
Darren



More information about the rrd-users mailing list