[rrd-users] Re: Extracting data for text pased reporting
martijn
martijn at pacno.net
Tue Oct 8 02:59:36 MEST 2002
Hi,
I'm also very new to rrdtool and was about to hit the send button on a simulair
question i think, if i understood your needs that is. Before sending i did a
little more trial and error on how to output my wanted graphics and text
output.
First of all, what I try to get out of my rrd's is just the normal rate per
second graphics, but also (and this was the troubling bit) the total amount of
data consumed by each of my network clients. The text output was easy. Just a
fetch on all the data i had was enough, multiplying every value by 60 (as i
stored bytes in/out per minute) and came up with the grand total. I store each
host in it's own rrd, so something like this gave me the figures i needed:
#!/usr/bin/perl -w
use strict;
use RRDs;
my $hostname=shift;
my $startstamp=shift;
$startstamp=int($startstamp/60)*60;
print "$startstamp\n";
my $endstamp=$startstamp+(7*24*60*60); # seven days of data
my ($start,$step,$names,$data) = RRDs::fetch "$hostname.rrd","AVERAGE","-e","$endstamp","-s","$startstamp";
print "Start: ", scalar localtime($start), " ($start)\n";
print "Step size: $step seconds\n";
print "DS names: ", join (", ", @$names)."\n";
print "Data points: ", $#$data + 1, "\n";
print "Data:\n";
my @total;
foreach my $line (@$data) {
$start += $step;
my $val;
for my $i (0 .. 2) {
$total[$i]+=$step*($$line[$i]? $$line[$i]:0); # null / *UNKOWN* values should be zero
}
}
printf "In: %12.1f\tOut: %12.1f\tTotal: %12.1f\n", $total[0],$total[1],$total[2];
Then for the trickiest part, generating a nice graph on it... After a lot (i
mean a _lot_) of trial and error, i found out that the hard part was to figure
out that in my CDEF's i had to understand that the amount values i was getting,
was once every step which in this case means each pixel of the output graphics.
The calculation i made, goes as follows. First divide endtime-starttime by the
width, to get to total seconds that each pixel occupies. Then multiply that
number by the value you get from RRDtool and add that to the previous value of
the CDEF where all theses calculations happen. I guess it must be the right,
for it looks ok... The graphical output for the above would be something like:
my $width=640;
RRDs::graph "test.png",
"--title","This weeks drain for $hostname",
"-a","PNG",
"--start",$startstamp,
"--end",$endstamp,
"--width","$width",
"--height","200",
"DEF:in=$hostname.rrd:In:AVERAGE",
"DEF:out=$hostname.rrd:Out:AVERAGE",
"DEF:total=$hostname.rrd:Total:AVERAGE",
"CDEF:cin=in,UN,0,in,IF",
"CDEF:cout=out,UN,0,out,IF",
"CDEF:ctotal=total,UN,0,total,IF",
"CDEF:pin=PREV,UN,0,PREV,IF,cin,$endstamp,$startstamp,-,*,$width,/,+",
"CDEF:pout=PREV,UN,0,PREV,IF,cout,$endstamp,$startstamp,-,*,$width,/,+",
"CDEF:ptotal=PREV,UN,0,PREV,IF,ctotal,$endstamp,$startstamp,-,*,$width,/,+",
"LINE1:pin#AF0000:In",
"LINE1:pout#00AF00:Out",
"LINE1:ptotal#0000AF:Total";
But do play around with it, especially when the steps between values are
getting larger. I've noticed a bit more inaccurate results when i used these
scripts on another RRA from my rrd's, one that stores values each 7 minutes. It
must be because of the way seven values are averaged into one, but i'm not sure
how much off it is, and if it actually should happen. So play around with it
and if you learned something new, please let me know ;)
martijn
--
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