[rrd-users] New to perl, strange behaviour
Claude R Trepanier/Bromont
crtrepan at ca.ibm.com
Wed Feb 20 15:20:35 MET 2002
DISCLAIMER ON
Yes this is my first attempt at doing something with perl, I may be
completely lost, so lost that I would no know I'm lost...
DISCLAIMER OFF
I need to create graphs with a variable number of ranges (I am graphing
data from Cisco stacks and all stacks do not have the same quantity of
members)
This is what I have come up so far:
#!/usr/bin/perl
use RRDs;
sub getColor {
#############################################################################
# getColor: select a different color for every element
#
# --- could use some parameter checking
#
# Parameters: item number
# Returns : Color value
#
#############################################################################
my @Colors = ("#000000",
"#FF0000",
"#A007B6",
"#608E78",
"#FCA965",
"#5841FE",
"#F0FF0F",
"#80FF80",
"#FF80FF");
return @Colors[$_[0]];
}
sub doCPU {
#############################################################################
# doCPU: create graph for CPU utilization for a stack
#
# Parameters: stack name, number of members
# Returns : Nothing
#
#############################################################################
$Machine = $_[0];
$Members = $_[1];
my @GraphParams = ("--height=200", "--width=400", "--start=-108000",
"--lazy", "--upper-limit=100", "--lower-limit=0",
"--title=Utilisation du CPU $Machine", "--rigid",
"--vertical-label=\"% CPU\"",
"--color=CANVAS#808080", "--color=BACK#000000",
"--color=FONT#00FFFF", "--color=GRID#000000");
$Comment = "COMMENT: Courant Maximum Moyenne
Minimum\\n";
$Output = "/mrtg/images/$Machine.png";
for $loop (1 .. $Members ) {
$Source = "/mrtg/images/$Machine"."_cpu_"."$loop.rrd";
$Var = "cpu"."$loop";
$Color = getColor($loop);
if ($loop == 1) {
@Graph = ("DEF:$Var"."=$Source".":ds0:AVERAGE",
"LINE2:$Var"."$Color".":CPU $loop",
"GPRINT:$Var".":LAST:%8.1lf%s",
"GPRINT:$Var".":MAX:%8.1lf%s",
"GPRINT:$Var".":AVERAGE:%8.1lf%s",
"GPRINT:$Var".":MIN:%8.1lf%s\\n");
} else {
@Graph = ("@Graph",
"DEF:$Var"."=$Source".":ds0:AVERAGE",
"LINE2:$Var"."$Color".":CPU $loop",
"GPRINT:$Var".":LAST:%8.1lf%s",
"GPRINT:$Var".":MAX:%8.1lf%s",
"GPRINT:$Var".":AVERAGE:%8.1lf%s",
"GPRINT:$Var".":MIN:%8.1lf%s\\n");
}
}
print "@Graph--\n";
RRDs::graph($Output,
@GraphParams,
$Comment,
$Graph);
my $ERR=RRDs::error;
print "$ERR\n";
}
#############################################################################
# M A I N
#############################################################################
$Machine = "b3548a";
$Members = 5;
doCPU($Machine, $Members) ;
#############################################################################
My problem is that the resulting graph only contains 1 element, the last
one.
I have taken the output of the 'print "@Graph--\n";' and created a static
script and then I get all 5 lines on the graph and the exact same output
for the 'print "@Graph--\n";'.
I'm guessing my problem is probably due to the attempt to glue @Graph onto
itself but can't explain why the last element would be OK.
Sorry for the long post.
Thanks for any help
Claude R Trépanier
Support de l'infrastructure du réseau
IBM Bromont
--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin http://www.ee.ethz.ch/~slist/lsg2.cgi
More information about the rrd-users
mailing list