[rrd-users] Re: determining invalid values using RRDs vs rrdtool fetch

D. Walsh info at daleenterprise.com
Sat Mar 18 07:38:12 MET 2006


On Mar 17, 2006, at 13:01 , Ann Gentile wrote:

> Hello,
>
> I would like to be able distinguish values that are invalid
> calling RRDs::fetch vs using rrdtool fetch. That is:
>
> at time 1142539176
>
> calling:
> 	rrdtool fetch "<myrrdhere>" AVERAGE -r 1 -e now -s e-1min
>
> returns:
>
> 	timestamp    sum
> 	
> 	1142539080:  2.3500000000e+01
> 	1142539140:  nan
> 	1142539200:  nan

This is two minutes.

The numerical results are: (NaN is 0 or infinity)
1142539080		23.5
1142539140 	0.0
1142539200 	0.0

>
>
> whereas using:

If you're on a POSIX system, Perl supports the "POSIX::strtod"  
function. Its semantics are somewhat cumbersome, so here's a "getnum"  
wrapper function for more convenient access. This function takes a  
string and returns the number it found, or "undef" for input that  
isn't a C float. The "is_numeric" function is a front end to "getnum"  
if you just want to say, ``Is this a float?''


     sub getnum {
         use POSIX qw(strtod);
         my $str = shift;
         $str =~ s/^\s+//;
         $str =~ s/\s+$//;
         $! = 0;
         my($num, $unparsed) = strtod($str);
         if (($str eq '') || ($unparsed != 0) || $!) {
             return undef;
         } else {
             return $num;
         }
     }

     sub is_numeric { defined getnum($_[0]) }



> 	my ($start,$step,$names,$data) = RRDs::fetch ...
> 	 foreach my $line (@$data) {
> 	   print "  ", scalar localtime($start), " ($start) ";
> 	   $start += $step;
> 	   foreach my $val (@$line) {

		if (! is_numeric($val)) {
			printf "$val"; # there's no number to return.
		} else {
			printf "%12.1f ", $val; # there's a number to return
		}
> 	   }
> 	   print "\n";
> 	 }
>
> prints out:
> 	1142539080         23.5
>         1142539140          0.0
>
>
> Two questions:
> 1) Since at time 1142539176 rrdtool fetch returns
>    nan for times 1142539140 & 1142539200, but later fills
>    them in I assume that they are just not calculated yet, as
>    opposed to nan results due to data points that will never
>    come in -- is there a way to determine that this is the case ?
> 2) Is there someother way I can use RRDs::fetch to get back
>    something other than 0.0 for the values that appear as nan
>    when I call rrdtool fetch, since 0.0 may be a valid return
>    value for my calculation?

It wasn't returning 0.0, you forced this with:  printf "%12.1f ", $val;

> Thank you,
> Ann
>
> --
> 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
>
>



--
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