experience rrdtool fetch temp

Forum regarding Linux Software and Home Automation Domotica.

experience rrdtool fetch temp

Postby Kroonen » Sat Dec 01, 2007 10:58 pm

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
Kroonen
Member
Member
 
Posts: 302
Joined: October 2007
Location: Netherlands

experience rrdtool fetch temp

Postby Snelvuur » Sun Dec 02, 2007 12:20 am

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)
User avatar
Snelvuur
Forum Moderator
Forum Moderator
 
Posts: 3155
Joined: April 2007
Location: Netherlands

experience rrdtool fetch temp

Postby linuxha » Sun Dec 02, 2007 5:24 am

This is what I came up with:

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

Neil Cherry
[url="http://www.linuxha.com/"]Linux Home Automation[/url]
Author: Linux Smart Homes For Dummies
linuxha
Starting Member
Starting Member
 
Posts: 16
Joined: November 2007
Location: USA

experience rrdtool fetch temp

Postby Kroonen » Sun Dec 02, 2007 5:21 pm

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: October 2007
Location: Netherlands

experience rrdtool fetch temp

Postby Kroonen » Tue Dec 04, 2007 8:18 am

Can it with tail of grep?? anu ideas are welcome
Kroonen
Member
Member
 
Posts: 302
Joined: October 2007
Location: Netherlands

experience rrdtool fetch temp

Postby Snelvuur » Tue Dec 04, 2007 9:41 am

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)
User avatar
Snelvuur
Forum Moderator
Forum Moderator
 
Posts: 3155
Joined: April 2007
Location: Netherlands

experience rrdtool fetch temp

Postby Kroonen » Tue Dec 04, 2007 9:45 pm

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
Kroonen
Member
Member
 
Posts: 302
Joined: October 2007
Location: Netherlands

experience rrdtool fetch temp

Postby Asmodeo » Wed Dec 05, 2007 5:49 pm

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
Asmodeo
Starting Member
Starting Member
 
Posts: 7
Joined: July 2007
Location:


Return to Linux Forum

Who is online

Users browsing this forum: No registered users and 1 guest

cron