Page 1 of 1

experience rrdtool fetch temp

Posted: Sat Dec 01, 2007 11:58 pm
by Kroonen
I;m trying to fetch the laste temperature from a rrd database, with the follwing command:
[root@kroonen thgr228n.1f]# rrdtool fetch temp.rrd AVERAGE -r 600 -s -1min
timestamp temp

1196546040: 1.8300000000e+01
1196546100: nan
1196546160: nan

How do i get only the value 1.8300000+01 but as value 18,3 with scipt or cut, if it is under 10 degrees it must also work 9,90000+0 as 9,9

experience rrdtool fetch temp

Posted: Sun Dec 02, 2007 1:20 am
by Snelvuur
I come as far as this:

awk 'BEGIN {printf "%.3f\n", 18.200000}'

This works pretty ok, but when there is a "+01" behind it, it doesn't work. It will count 1 to the output, dont know quickly how to solve that. Its bound to be possible in perl though.

Update:

printf %f `echo "1.8300000000e+01"|sed -e s/+//;`

Will give you 18.300000.. hope that helps.

// Erik (binkey.nl)

experience rrdtool fetch temp

Posted: Sun Dec 02, 2007 6:24 am
by linuxha
This is what I came up with:

perl -e '$a="1.8300000+01";$a=~s/\+/E/g;printf("%.2f\n",$a);'

Neil Cherry
Linux Home Automation
Author: Linux Smart Homes For Dummies

experience rrdtool fetch temp

Posted: Sun Dec 02, 2007 6:21 pm
by Kroonen
thanks for that one, the perl is vey nice, now I need to get the right line


i have aleady this

rrdtool fetch temp.rrd AVERAGE --start -2min --end -1min | awk '{print $2}'

with result

temp

1.6300000000e+01
1.6300000000e+01
nan

I need line 3 only, how can I awk the right line?

experience rrdtool fetch temp

Posted: Tue Dec 04, 2007 9:18 am
by Kroonen
Can it with tail of grep?? anu ideas are welcome

experience rrdtool fetch temp

Posted: Tue Dec 04, 2007 10:41 am
by Snelvuur
perhaps with "head" .. but check google this should not be that hard. If it doesn't work i'll look further into it. I'am trying to get some zenah sql's now, but i can allready tell you that response times are 10x quicker..


// Erik (binkey.nl)

experience rrdtool fetch temp

Posted: Tue Dec 04, 2007 10:45 pm
by Kroonen
Well finally I have a script, maybe not so nice written but it gives nice output

#!/bin/sh
/usr/bin/rrdtool fetch temp.rrd AVERAGE --start -120 --end -60 | awk '{print $2}' | grep 0 > test
read=`head -n1 test`
printf %f `echo $read|sed -e s/+//;` > test
cat test | cut -b 1,2,3,4,5

experience rrdtool fetch temp

Posted: Wed Dec 05, 2007 6:49 pm
by Asmodeo
kroon040

This is what I'm currently using to do something similar:
Please consider that I'm fetching the average temp form the last 30min from an rrd database that store several resolutions (5min, 30min, etc)


$ctime = time;
$rrdres = 1800;
$etime = (int($ctime/$rrdres))*$rrdres-1;
$stime = (($etime)-1799);

my ($start,$step,$names,$array) =
RRDs::fetch("$RRD/temp.rrd", "AVERAGE",
"-r", "$rrdres", "-s", "$stime", "-e", "$etime");

I hope this help
Asmodeo