[rrd-users] newbie perl problem with rrds::graph
Mark Wingate
mlwingate at comcast.net
Fri Jan 15 22:00:33 CET 2010
Here are a few ideas that should get you closer. I haven't used RRDs::graph, so I may be doing something silly with the quoting.
&CreateGraph("$computer", "day", $harddrives); # I removed a double quote before $harddrives
&CreateGraph("$computer", "week", $harddrives); # ditto
# let's assume you have a string containing hard drive names, like this: $harddrives = "hda hdb hdc"
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)
( $computer_id, $interval, $hd_list ) = @_; # treat yourself and others to some human-readable variables!
#$size = scalar @_; # get total amount of parameters <-- not needed
@defs = (); #<-- use array to gather up the defs
@graphs = (); #<-- ... and the graph specs
for $drive ( split(' ', $hd_list ) {
push @defs, "DEF:$drive=$rrd/$drive.rrd:temp:AVERAGE";
# -- while troubleshooting, I would make the GPRINTs as simple as possible.
push @graphs, "LINE2:$drive#FF9900:$drive\\: ",
"GPRINT:$drive:MIN: Min\\: %2.lf ",
"GPRINT:$drive:MAX: Max\\: %2.lf ",
"GPRINT:$drive:AVERAGE: Avg\\: %4.1lf ",
"GPRINT:$drive:LAST: Current\\: %2.lf degrees C\\n ";
}
RRDs::graph "$img/$computer_id/hddtemp-$interval.png",
"--lazy",
"-s -1$interval",
"-t 'hdd temperature :: hard disk drives'", #<-- added some quotes
"-h", "80", "-w", "600",
"-a", "PNG",
"-v 'degrees C'", #<-- added some quotes
"--slope-mode",
join(' ', @defs),
join(' ', @graphs);
if ( = RRDs::error) { print "$0: unable to generate $interval graph:
$ERROR\n"; }
}
#... If you put the hard drives into an array instead of building a string,
#you would do something like this:
#Let's say @harddrives contains the drive names;
@harddrives = ('hda', 'hdb', 'hdc'); # Perl-y way: ... = qw(hda hdb hdc);
#But don't pass the array in, pass a reference instead ...
&CreateGraph("$computer", "day", \@harddrives); # removed a ouble quote before $harddrives
#Then change the routine to use the ref
( $computer_id, $interval, $hd_list_ref ) = @_; # changing variable name just for clarity
#...
for $drive ( @$hd_list_ref ) {
#... that's it.
Mark Wingate
More information about the rrd-users
mailing list