<span class="postbody">Hello RRD-Users,<br><br>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.<br>
<br>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.
<br>
<br>
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:
<br>
<br>
</span><table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr>          <td><span class="genmed"><b>Code:</b></span></td>
        </tr>        <tr>         <td class="code">
<br>
#!/usr/bin/perl
<br>
use RRDTool::OO;
<br>
<br>
# code to get the rrd file name from the cacti database omitted.
Instead
<br>
# I'll define it as:
<br>
$rrdfile = "/var/www/html/cacti/rra/326/28889.rrd";
<br>
<br>
$rrd = RRDTool::OO->new( file => $rrdfile );
<br>
@ARGV[2] = time()-3600 if !@ARGV[2];
<br>
@ARGV[3] = time() if !@ARGV[3];
<br>
$rrd->fetch_start(
<br>
start => @ARGV[2],
<br>
end => @ARGV[3],
<br>
resolution => "300",
<br>
cfunc => "AVERAGE"
<br>
);
<br>
$rrd->fetch_skip_undef();
<br>
print "Start: ",time()-3600,"\nEnd: ",time(),"\n";
<br>
print "Device: $devname\n";
<br>
print "RRDFile: $rrdpath\n\n";
<br>
while(my($time, @value) = $rrd->fetch_next()) {
<br>
print "$time: ",sprintf("%.2f", $value[0])," Bytes IN\n" if $value[0];
<br>
print "$time: ",sprintf("%.2f", $value[1])," Bytes OUT\n" if
$value[1];
<br>
$sumin = $sumin + $value[0];
<br>
$sumout = $sumout + $value[1];
<br>
}
<br>
print "IN: ",sprintf("%.2f", $sumin)," Bytes\n";
<br>
print "OUT: ",sprintf("%.2f", $sumout)," Bytes\n";
<br>
print "TOTAL:",sprintf("%.2f", $sumin+$sumout)," Bytes\n";
<br>
</td>        </tr></tbody></table><span class="postbody">
<br>
<br>
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.
<br>
<br>
</span><table align="center" border="0" cellpadding="3" cellspacing="1" width="90%"><tbody><tr>          <td><span class="genmed"><b>Code:</b></span></td>
        </tr>        <tr>         <td class="code">
<br>
[root@traf ~]# ./<a href="http://rrd-read.pl">rrd-read.pl</a> aa11 Fa0/14
<br>
Start: 1276544454
<br>
End: 1276548054
<br>
Device: Fa0/14
<br>
RRDFile: /var/www/html/cacti/rra/326/28889.rrd
<br>
<br>
1276544700: 22144.43 Bytes IN
<br>
1276544700: 2484.16 Bytes OUT
<br>
1276547400: 30579.32 Bytes IN
<br>
1276547400: 3318.26 Bytes OUT
<br>
1276547700: 22904.95 Bytes IN
<br>
1276547700: 2469.39 Bytes OUT
<br>
1276548000: 21962.23 Bytes IN
<br>
1276548000: 2323.77 Bytes OUT
<br>
IN: 97590.94 Bytes
<br>
OUT: 10595.58 Bytes
<br>
TOTAL:108186.51 Bytes
<br>
</td>        </tr></tbody></table><span class="postbody">
<br>
<br>
<span style="font-weight: bold;">Questions:</span>
<br>
- 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 auto-adapt?
<br>
- Am I 100% sure that $value[0] is always "IN" and $value[1] is always
"OUT"?
<br>
- Does this look sane or is there a better way to do this?
<br>
- 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)?
<br>
<br>
Thanks for taking the time to review this post to the list.<br>
<br>
Regards,
<br>
</span><br>Landon Stewart <<a href="mailto:LStewart@SUPERB.NET">LStewart@SUPERB.NET</a>><br>SuperbHosting.Net by Superb Internet Corp.<br>Toll Free (US/Canada): 888-354-6128 x 4199<br>Direct: 206-438-5879<br>Web hosting and more "Ahead of the Rest": <a href="http://www.superbhosting.net">http://www.superbhosting.net</a><br>