[prev in list] [next in list] [prev in thread] [next in thread]
List: rrd-users
Subject: Re: [rrd-users] newbie perl problem with rrds::graph
From: Mark Wingate <mlwingate () comcast ! net>
Date: 2010-01-15 21:00:33
Message-ID: 1386173953.2552191263589233241.JavaMail.root () sz0094a ! emeryville ! ca ! mail ! comcast ! net
[Download RAW message or body]
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
_______________________________________________
rrd-users mailing list
rrd-users@lists.oetiker.ch
https://lists.oetiker.ch/cgi-bin/listinfo/rrd-users
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic