experience rrdtool fetch temp

Forum regarding Linux Software and Home Automation Domotica.
Post Reply
Kroonen
Member
Member
Posts: 302
Joined: Mon Oct 01, 2007 6:38 pm
Location: Netherlands

experience rrdtool fetch temp

Post 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
User avatar
Snelvuur
Forum Moderator
Forum Moderator
Posts: 3156
Joined: Fri Apr 06, 2007 11:01 pm
Location: Netherlands
Contact:

experience rrdtool fetch temp

Post 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)
linuxha
Starting Member
Starting Member
Posts: 16
Joined: Mon Nov 12, 2007 3:17 am
Location: USA
Contact:

experience rrdtool fetch temp

Post 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
Kroonen
Member
Member
Posts: 302
Joined: Mon Oct 01, 2007 6:38 pm
Location: Netherlands

experience rrdtool fetch temp

Post 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?
Kroonen
Member
Member
Posts: 302
Joined: Mon Oct 01, 2007 6:38 pm
Location: Netherlands

experience rrdtool fetch temp

Post by Kroonen »

Can it with tail of grep?? anu ideas are welcome
User avatar
Snelvuur
Forum Moderator
Forum Moderator
Posts: 3156
Joined: Fri Apr 06, 2007 11:01 pm
Location: Netherlands
Contact:

experience rrdtool fetch temp

Post 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)
Kroonen
Member
Member
Posts: 302
Joined: Mon Oct 01, 2007 6:38 pm
Location: Netherlands

experience rrdtool fetch temp

Post 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
Asmodeo
Starting Member
Starting Member
Posts: 7
Joined: Wed Jul 11, 2007 2:01 pm

experience rrdtool fetch temp

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

Return to “Linux Forum”