[rrd-developers] Re: RRDs::fetch zero values returns NaN

Mark Mills mark at xodiax.com
Thu Mar 15 19:36:22 MET 2001


It is just a Perl thing.  Perl promotes undef to a 0 in 
printf since he treats it as a number ala "%1.10e " and
the truth test ( ! $val ) treats 0, 0.0, "" and undef all
as false. Thus it prints "0.00000" and then says "(undef)"
because perl is trying to do-the-right-thing for you.

Returning undef as you do now is correct, we should just
get a few more perl examples out there that deal with
the difference between "define"d and false when it comes
to the values returned by fetch.

--mark

-----Original Message-----
From: Tobias Oetiker [mailto:oetiker at ee.ethz.ch]
Sent: Thursday, March 15, 2001 1:21 PM
To: steve rader
Cc: rrd-developers at list.ee.ethz.ch
Subject: [rrd-developers] Re: RRDs::fetch zero values returns NaN 



Today steve rader wrote:

 |
 |  > From: me
 |  > The problem is that NaN values fetched with RRDs::fetch are now
 |  > returned as 'undef' instead of the string 'NaN'.
 |
 | Now I find that RRDs::fetch is broke with respect to zero values:
 | with 1.0.33, RRDs::fetch of zero values returns 'undef'.
 |
 | I wrote a little script to demonstrate the problem... and here's
 | the results...
 |
 |  chive(rader): rrdtool fetch -s -10min -e now \
 |    /usr/local/nrg/web/apache/Chive/Chive-tp.rrd AVERAGE \
 |    | tail -4
 |  984673800: 1.1650888889e+00
 |  984674100: 0.0000000000e+00
 |  984674400: 0.0000000000e+00
 |  984674700:        NaN
 |
 |  chive(rader): ./rrdfetch.pl \
 |    /usr/local/nrg/web/apache/Chive/Chive-tp.rrd AVERAGE \
 |    | tail -4
 |  984673800: 1.1650888889e+00
 |  984674100: 0.0000000000e+00  (undef)
 |  984674400: 0.0000000000e+00  (undef)
 |  984674700: 0.0000000000e+00  (undef)

hmm not sure what is happening here, but the line in the perl
bindings looks quite simple to me:

                av_push(line,(isnan(*datai) ? &PL_sv_undef :
newSVnv(*datai)));

anyone ?

tobi

 | #
 |
 | use lib '/usr/local/rrdtool-1.0.33/lib/perl';
 | use RRDs;
 | ($start,$step,$names,$data) = RRDs::fetch ("$ARGV[0]",'AVERAGE');
 | if ( $error = RRDs::error ) {
 |   print "rrdtool fetch failed: \"$error\"\n";
 |   exit 1;
 | }
 | $d_start = $start;
 | foreach $line (@$data) {
 |   print " $d_start: ";
 |   $d_start += $step;
 |   foreach $val (@$line) {
 |     printf "%1.10e ", $val;
 |     if ( ! $val ) { print " (undef)"; }
 |   }
 |   print "\n";
 | }
 |
 |
 | --
 | Unsubscribe
mailto:rrd-developers-request at list.ee.ethz.ch?subject=unsubscribe
 | Help        mailto:rrd-developers-request at list.ee.ethz.ch?subject=help
 | Archive     http://www.ee.ethz.ch/~slist/rrd-developers
 | WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi
 |
 |

-- 
 ______    __   _
/_  __/_  / /  (_) Oetiker, Timelord & SysMgr @ EE-Dept ETH-Zurich
 / // _ \/ _ \/ / TEL: +41(0)1-6325286  FAX:...1517  ICQ: 10419518
/_/ \.__/_.__/_/ oetiker at ee.ethz.ch http://ee-staff.ethz.ch/~oetiker


--
Unsubscribe
mailto:rrd-developers-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-developers-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-developers
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi


--
Unsubscribe mailto:rrd-developers-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-developers-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-developers
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-developers mailing list