Visit Our UNIX and Linux User Community


Debian, digitemp, rrdtool


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Debian, digitemp, rrdtool
# 1  
Old 11-09-2009
Debian, digitemp, rrdtool

Mit perlscript:

Code:
#!/usr/bin/perl
#
# copyright Per Hansen 2009
#
#
# temp.pl

use lib qw(/opt/rrdtool-1.4.1/lib/perl);
use RRDs;
 

# sti til rrdtool databases
my $rrd = '/var/lib/rrd';



# sti til færdige grafer
my $img = '/var/www/rrdtool';



# sti til digitemp
my $digi = '/usr/bin'; 
 

# hvis rrd-database ikke findes, laves den her
    if (! -e "$rrd/temperature.rrd") 
    {
        print "creating rrd database for sensors ...\n";
        RRDs::create "$rrd/temperature.rrd",
         "-s 300",        
         "DS:out:GAUGE:600:-50:50",
         "DS:in:GAUGE:600:-50:50",            
         "RRA:AVERAGE:0.5:1:600",
         "RRA:AVERAGE:0.5:6:700",
         "RRA:AVERAGE:0.5:24:775",        
         "RRA:AVERAGE:0.5:288:797",
         "RRA:MIN:0.5:1:600",
         "RRA:MIN:0.5:6:700",
         "RRA:MIN:0.5:24:775",
         "RRA:MIN:0.5:288:797",
         "RRA:MAX:0.5:1:600",
         "RRA:MAX:0.5:6:700",
         "RRA:MAX:0.5:24:775", 
         "RRA:MAX:0.5:288:797" ;
   }
    if ($ERROR = RRDs::error) { print "$0: failed to create temperature database file: $ERROR\n"; }
 
    
# aflæs den udendørs-sensor
    my $read_out = `$digi/digitemp -t 0 -q -c /etc/digitemp.conf -o%C`;
       
    # aflæs kælder-sensor
    my $read_in = `$digi/digitemp -t 1 -q -c /etc/digitemp.conf -o%C`;
 
    
# fjerner eol-karaktere i den læste værdi
    chomp($read_out);
    chomp($read_in);
 
    
# check for fejl i temp-sensorerne
    if (int $read_out eq 85)
    {
        print "failed to read value from outside sensor\n";
        $read_out = "U";
    }
    if (int $read_in eq 85)
    {
        print "failed to read value from basement sensor\n";
        $read_in = "U";
    }
  

  # indsæt værdier i rrd
    RRDs::update "$rrd/temperature.rrd",
       "-t", "out", "N:$read_out";
       "-t", "in",    "N:$read_in";
 
    
if ($ERROR = RRDs::error) { print "$0: failed to insert data into rrd: $ERROR\n"; }
 
    
#print"out $read_out";
    #print"in $read_in";  
 

# generer graf
RRDs::graph "$img/temp-day.png",
"-n", "DEFAULT:0:/usr/share/fonts/truetype/msttcorefonts/arial.ttf", 
"-t Temperaturer i Auning, Danmark °C", 
"--lazy",
"-a", "PNG",
"-h", "80", "-w", "550", 
"-E",
"DEF:outside=$rrd/temperature.rrd:out:AVERAGE",
"DEF:basement=$rrd/temperature.rrd:in:AVERAGE",
"COMMENT:\\c",
"COMMENT:             MAX            MIN            AVERAGE          CURRENT\\c",
"LINE2:outside#FF0000:udendørs\\t",
"GPRINT:outside:MAX:%4.2lf °C\t",
"GPRINT:outside:MIN:%4.2lf °C\t",
"GPRINT:outside:AVERAGE:%4.2lf °C\t",
"GPRINT:outside:LAST:%4.2lf °C\\c",
"LINE2:basement#3333CC:kælder\\t",
"GPRINT:basement:MAX:%6.2lf °C\t",
"GPRINT:basement:MIN:%6.2lf °C\t",
"GPRINT:basement:AVERAGE:%6.2lf °C\t",
"GPRINT:basement:LAST:%6.2lf °C\\c",
"COMMENT:\\c",
"COMMENT:Copyright Per Hansen\\c";

  if ($ERROR = RRDs::error) { print "$0: unable to generate sensor $_[0] $_[1] graph: $ERROR\n"; }

læser to værdier via digitemp, hvorefter rrdtool genere en graf. Mit problem er dog at enten viser grafen to ens værdier eller kun den ene af dem.
Jeg har førsøgt at ændre mange ting dog uden held. Enten bliver resultatet det ene eller det andet.
Det bliver aldrig korrekt.

Er der nogen som kender rrdtool?

Det skal lige siges at jeg normalt ikke er en koder, hvilket sikkert også kan ses ud fra mit script. Hvis scriptet kan skrives om, men stadig udføre det samme er i velkommne til at gøre det.
# 2  
Old 11-10-2009
Hej Per,

Du er vel klar over dette forum for det meste er engelsktalene ?

Jeg har kigget din kode nærmere igennem og syntes du lige skal kigge din update() lidt nærmere efter:
Code:
    RRDs::update "$rrd/temperature.rrd",
       "-t", "out", "N:$read_out";
       "-t", "in",    "N:$read_in";

Hvis det ikke er fejlen, så prøv eventuelt at ændre det til
Code:
RRDs::update ("$rrd/temperature.rrd", "N:" . $read_out. ":" .$read_in);

Selvom du påstår du ikke er programmør, lader det til at være en rimelig pænt program, selve fejlen kan alle lave, det er jo svært på de sene nattetimer at se skoven for træer Smilie

Previous Thread | Next Thread
Test Your Knowledge in Computers #655
Difficulty: Medium
In the mid-1980s Microsoft developed a multitasking version of DOS.
True or False?

5 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Python-rrdtool try except rrdtool.error module object has no attribute error

I have this code that gives this error on Linux and will be grateful if you can help import rrdtool try: ret_asd = rrdtool.update(myfile.rrd,'N:%s:%s' %(metric1, metric2)); except rrdtool.error, e: print e When i run the above i get the below error except... (1 Reply)
Discussion started by: kaf3773
1 Replies

2. Shell Programming and Scripting

Bash script for rrdtool

Hello all, I am very new to shell scripting. I messed with basic examples in college, but this this the first work related project I am trying to work on. I am trying to test the rrdtool on our office wan link by measuring the bandwidth utilization. The script concept is fairly easy, but I am... (2 Replies)
Discussion started by: AdrianT04
2 Replies

3. Red Hat

Why do we use RRDtool in MRTG?

Hi Guys, Why do we use RRDtool in MRTG? I have implemented MRTG for some routers, I have read some notes about RRDTOOL also but don't know what is use of these tool. Any one one please explain me the use of RRDTOOL in their own words? (1 Reply)
Discussion started by: manalisharmabe
1 Replies

4. UNIX for Dummies Questions & Answers

rrdtool question

Hi, DEF:clients=cccam.rrd:kliensek:AVERAGE DEF:activeclients=cccam_actclient.rrd:activeclients:AVERAGE "LINE1:clients#0000FF:Connected clients" COMMENT:" \n" "LINE2:activeclients#99FF00:Active clients" COMMENT:" \n" GPRINT:clients:LAST:'Current'\%5.0lf%s COMMENT:" \n"... (2 Replies)
Discussion started by: adriankoooo
2 Replies

5. HP-UX

compiling the RRDtool

I tried to compile the RRDtool on HP-UX (IA56). I have gcc-3.4.3 and perl 5.8.0 I got this: Writing Makefile for RRDs cd perl-shared && make /opt/perl/bin/perl /opt/perl/lib/5.8.0/ExtUtils/xsubpp -typemap /opt/perl/lib/5.8.0/ExtUtils/typemap RRDs.xs > RRDs.xsc && mv... (2 Replies)
Discussion started by: Kalin
2 Replies

Featured Tech Videos