[rrd-users] Having some trouble understanding what it is, exactly, I'm pulling from an RRD database file using RRDTool::OO with perl

Landon Stewart lstewart at superb.net
Tue Jun 15 01:37:57 CEST 2010

Hello RRD-Users,

I also posted this on the Cacti forum since it relates to Cacti data
directly but the RRD database is rrdtool specific. I'm having some trouble
understanding what it is, exactly, I'm pulling from an RRD database file.

Lets say, for example, that I have a graph of network traffic called
"aa11.acc - Traffic - Fa0/14". The data source template being used is
"Interface - Traffic". And the datasource path is
"<path_rra>/326/28889.rrd". The graph template being used is "Interface -
Traffic (bits/sec)" characterized by "(traffic_in): Inbound" and
"(traffic_out): Outbound" as well as the current, average and maximum for
each of those.

I'd like to pull the values from the RRD file. I've created a script to do
this using the device name, interface name and a start/end pair like this:

use RRDTool::OO;

# code to get the rrd file name from the cacti database omitted.  Instead
# I'll define it as:
$rrdfile = "/var/www/html/cacti/rra/326/28889.rrd";

$rrd = RRDTool::OO->new( file => $rrdfile );
@ARGV[2] = time()-3600 if !@ARGV[2];
@ARGV[3] = time()      if !@ARGV[3];
        start => @ARGV[2],
        end   => @ARGV[3],
        resolution => "300",
        cfunc => "AVERAGE"
print "Start: ",time()-3600,"\nEnd:   ",time(),"\n";
print "Device: $devname\n";
print "RRDFile: $rrdpath\n\n";
while(my($time, @value) = $rrd->fetch_next()) {
  print "$time: ",sprintf("%.2f", $value[0])," Bytes IN\n" if $value[0];
  print "$time: ",sprintf("%.2f", $value[1])," Bytes OUT\n" if $value[1];
  $sumin = $sumin + $value[0];
  $sumout = $sumout + $value[1];
print "IN:   ",sprintf("%.2f", $sumin)," Bytes\n";
print "OUT:  ",sprintf("%.2f", $sumout)," Bytes\n";
print "TOTAL:",sprintf("%.2f", $sumin+$sumout)," Bytes\n";

The values I get are the following, leaving off the start-end parameters in
my script defaults them to the last one hour (3600 seconds) of data.

[root at traf ~]# ./rrd-read.pl aa11 Fa0/14
Start: 1276544454
End:   1276548054
Device: Fa0/14
RRDFile: /var/www/html/cacti/rra/326/28889.rrd

1276544700: 22144.43 Bytes IN
1276544700: 2484.16 Bytes OUT
1276547400: 30579.32 Bytes IN
1276547400: 3318.26 Bytes OUT
1276547700: 22904.95 Bytes IN
1276547700: 2469.39 Bytes OUT
1276548000: 21962.23 Bytes IN
1276548000: 2323.77 Bytes OUT
IN:   97590.94 Bytes
OUT:  10595.58 Bytes
TOTAL:108186.51 Bytes

- Are these values really bytes? How do I know what the values are? Is it
contained in the RRD database file somewhere so I can have the script
- Am I 100% sure that $value[0] is always "IN" and $value[1] is always
- Does this look sane or is there a better way to do this?
- What's up with my time selection? Why does 3600 seconds only produce 4
samples even though the resolution is set to 300 seconds(3600/300=12)?

Thanks for taking the time to review this post to the list.


Landon Stewart <LStewart at SUPERB.NET>
SuperbHosting.Net by Superb Internet Corp.
Toll Free (US/Canada): 888-354-6128 x 4199
Direct: 206-438-5879
Web hosting and more "Ahead of the Rest": http://www.superbhosting.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.oetiker.ch/pipermail/rrd-users/attachments/20100614/17b634b0/attachment.htm 

More information about the rrd-users mailing list