[rrd-users] Best way to fetch question

Christopher Nicholas Florio florio at email.unc.edu
Sat Sep 2 00:03:20 MEST 2006


Hi!
So what I'm after is a way to fetch the latest value and time of the  
rrd file that is not a nan.


Here's what I came up with in perl.  If there are no values not a nan  
in the last day, I'm returning the last time.

Is this the best way to do this?  Is there a better way?  Is this sub  
routine even correct?

Thanks for the help!


sub get_rrd_last_value{
    my $rrdfile = $_[0];

    my ($start, $step, $names, $data) = RRDs::fetch ( $rrdfile,  
"AVERAGE");

    my $rrd_time;
    my $value;

    my $i = scalar @$data;

    while ((! defined $value) && ($i != 0)){
       $rrd_time = $start + ($i * $step);
       $value = $data->[$i]->[0];
       $i--;
    }
    if (! defined $value){
       $rrd_time = RRDs::last ($rrdfile);
    }

    return ($value, $rrd_time);
}



-- Attached file removed by Ecartis and put at URL below --
-- Type: application/pkcs7-signature
-- Size: 2k (2215 bytes)
-- URL : http://lists.ee.ethz.ch/p/04-smime.p7s


--
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://lists.ee.ethz.ch/rrd-users
WebAdmin    http://lists.ee.ethz.ch/lsg2.cgi



More information about the rrd-users mailing list