[rrd-users] perl and lastupdate

Sean Whitney sean at visionary-networks.com
Mon Feb 21 20:28:33 CET 2011


One of the things that bugs me is that lastupdate isn't available in the perl RRDs;

So I've hacked this together.  I'm not the greatest perl person so any criticism, corrections or improvements are greatly welcome.  

When you run this you get the last updated timestamp as $ts and the values in the rrd file in the %rrdhash.


use RRDs;

my $file = 'path/and/filename/of/rrd/file.rrd';
my $ts;
my %rrdhash;
my @values;
my @keys;
my @i=0;

open (PIPE, "/usr/bin/rrdtool lastupdate $file |") || die "can't fork: $!";
while (<PIPE>) {
        chomp;
        my @temp = split;
        $i == 0 and @keys = @temp;
        $i == 2 and $ts = shift @temp;
        $ts =~ s/[^0-9]//;
        $i == 2 and @values = @temp;
        $i++;
}
close PIPE  || die "bad rrdtool: $! $?";

%rrdhash = map { $keys[$_] => $values[$_] }0..$#keys;


Take care, 

Sean


=======================================
Sean Whitney
PMB #120, 16505A SE First Street
Vancouver, WA  98684
T. 360.326.2740 
C. 360.607.7945
F. 815.364.0687
aim: seanmwhitney
email: sean at visionary-networks.com
skype: visionary_networks
=======================================








-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.oetiker.ch/pipermail/rrd-users/attachments/20110221/20c94b9f/attachment.htm 


More information about the rrd-users mailing list