[rrd-users] Re: how to use RRDs::graph in a perlscript?

Arne Götje ( 高盛華 ) arne at linux.org.tw
Thu May 20 05:17:19 MEST 2004


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wednesday 19 May 2004 22:14, Christian_Lair at i2.com wrote:
> Here's an example from one of my scripts that works just fine. If you
> include your code we may be able to help you in detail.
> my $start_90 = ($today - 77760000);
>
> RRDs::graph     "$graph_location/$host/90day.gif",
>                 "--start", "$start_90",
>                 "--title", "90 Day Graph",
>                 "--w","375", "--h", "200",
>                 "--x", "WEEK:1:MONTH:1:MONTH:1:0:%b",
>                
> "DEF:LoadAvg=$rrd_location/$host/$host.rrd:load:AVERAGE",
> "LINE2:LoadAvg#FF0000:Load Average",
>                
> "DEF:CPU_Load=$rrd_location/$host/$host.rrd:cpu:AVERAGE",
> "LINE2:CPU_Load#00FF00:CPU Load",
>                
> "DEF:Vmem_Load=$rrd_location/$host/$host.rrd:vm:AVERAGE",
> "LINE2:Vmem_Load#0000FF:VM Load",;
>
> my $ERR=RRDs::error;
> die "ERROR while creating 90 day graph: $ERR\n" if $ERR;
>
> =

Ok, my png filename was lacking the "". But even with it still doesn't 
work, while the same string on the console with rrdtool graph works.

- ------------------- snip----------------------
my $testpng = "./test.png";
my $rrd = "/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd";
my @colors = 
("","#FF0000","#00FF00","#0000FF","#FFFF00","#FF00FF","#00FFFF","#FFC0C0","#C0C0C0","#C0FFC0","#C0C0FF",
              "#A000A0","#A0A000","#00A0A0","#0000A0","#A00000","#00A000","FFA000","#A0FFFF","#131313","#BC0013");

my $string = "\"$testpng\", \"-a\", \"PNG\", \"DEF:myin1=".
$rrd.":in1:AVERAGE\", \"AREA:myin1".$colors[1].":Service1\"";

for (my $i = 2; $i <= 10; $i++) {
  $string .= ", \"DEF:myin".$i."=".$rrd.":in".$i.":AVERAGE\", 
\"STACK:myin".$i.$colors[$i].":Service$i\"";
}

print $string."\n";
RRDs::graph $string;
my $ERR=RRDs::error;
print "$ERR\n" if ($ERR);
- ----------------- snip ------------------------------

this prints:

"./test.png", "-a", "PNG", 
"DEF:myin1=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in1:AVERAGE", 
"AREA:myin1#FF0000:Service1", 
"DEF:myin2=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in2:AVERAGE", 
"STACK:myin2#00FF00:Service2", 
"DEF:myin3=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in3:AVERAGE", 
"STACK:myin3#0000FF:Service3", 
"DEF:myin4=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in4:AVERAGE", 
"STACK:myin4#FFFF00:Service4", 
"DEF:myin5=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in5:AVERAGE", 
"STACK:myin5#FF00FF:Service5", 
"DEF:myin6=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in6:AVERAGE", 
"STACK:myin6#00FFFF:Service6", 
"DEF:myin7=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in7:AVERAGE", 
"STACK:myin7#FFC0C0:Service7", 
"DEF:myin8=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in8:AVERAGE", 
"STACK:myin8#C0C0C0:Service8", 
"DEF:myin9=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in9:AVERAGE", 
"STACK:myin9#C0FFC0:Service9", 
"DEF:myin10=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in10:AVERAGE", 
"STACK:myin10#C0C0FF:Service10"
can't make a graph without contents

while the same on the console with rrdtools :
rrdtool graph test.png -a PNG 
DEF:myin1=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in1:AVERAGE 
AREA:myin1#FF0000:Service1 
DEF:myin2=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in2:AVERAGE 
STACK:myin2#00FF00:Service2 
DEF:myin3=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in3:AVERAGE 
STACK:myin3#0000FF:Service3 
DEF:myin4=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in4:AVERAGE 
STACK:myin4#FFFF00:Service4 
DEF:myin5=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in5:AVERAGE 
STACK:myin5#FF00FF:Service5 
DEF:myin6=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in6:AVERAGE 
STACK:myin6#00FFFF:Service6 
DEF:myin7=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in7:AVERAGE 
STACK:myin7#FFC0C0:Service7 
DEF:myin8=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in8:AVERAGE 
STACK:myin8#C0C0C0:Service8 
DEF:myin9=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in9:AVERAGE 
STACK:myin9#C0FFC0:Service9 
DEF:myin10=/usr/local/lib/pcube/140.112.225/140.112.225.70.rrd:in10:AVERAGE 
STACK:myin10#C0C0FF:Service10

works fine.

Thanx for help.

- -- 
Arne Götje (高盛華) <arne at linux.org.tw>
PGP/GnuPG key: 1024D/685D1E8C
Fingerprint: 2056 F6B7 DEA8 B478 311F  1C34 6E9F D06E 685D 1E8C
Key available at wwwkeys.pgp.net.   Encrypted e-mail preferred.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFArCNAbp/QbmhdHowRArfTAJ0actvOPCVdK+7Fohdmbp6Vs+YvEQCfS6sM
FJk/rS0g7Knt/ma2lfCKk18=
=hzMw
-----END PGP SIGNATURE-----

--
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