View unanswered posts    View active topics

All times are UTC - 6 hours





Post new topic Reply to topic  [ 3 posts ] 
Print view Previous topic   Next topic  
Author Message
Search for:
 Post subject: rrd_HDtemp.pl
PostPosted: Tue Jul 24, 2007 9:50 pm 
Offline
Joined: Wed Jan 18, 2006 8:36 pm
Posts: 199
I changed the HDtemp rrd script to allow logging more than one hard drive (I have 3). Instead of specifiying:
Code:
$dev = 'hda'
you can now do
Code:
$dev = 'hda sda sdb'
and get all the temperatures on the same graph.

The script will only work with 6 hard drives because I hard wired the list of colors and only picked 6, this can be fixed. This list of colors could also be moved to the /etc/rrd.config file if desired.

This script may not work well if you start with one hard drive, than add another one at a later time. The easiest way to deal with this situation is to erase the rrd database (rm -f /myth/rrd/log/HDtemp.rrd).

Code:
#!/usr/bin/perl
#
#  rrd_HDtemp.pl
#       Disk temperature data collection routine for KnoppMyth
#
########################################################################
# Configuration:
my $dev = 'hda sda sdb';
my $dbf = "HDtemp";
my $configfile = '/etc/rrd.config';
my @temps;
my @colors = ('#0000FF', '#00FF00', '#FF0000', '#00FFFF', '#FF00FF', '#FFFF00');
########################################################################
use RRDs;

if (! -d "/myth") { $configfile = "./D_rrd.config"; }   # DEBUG
do $configfile;

sub create {
    #   $_[0] = filename
    if (! -e "$log/$_[0].rrd") {
        print "Create db for $_[0] => $log/$_[0].rrd\n";
        push @args, "$log/$_[0].rrd";
        push @args, "-s 300";
        @devs = split /\s+/, $dev;
        for($i = 0; $i < scalar(@devs); $i++) {
          push @args, "DS:hdt" . ($i + 1) . ":GAUGE:600:0:U";
        }
        push @args, "RRA:AVERAGE:0.5:1:576";
        push @args, "RRA:AVERAGE:0.5:6:672";
        push @args, "RRA:AVERAGE:0.5:24:732";
        push @args, "RRA:AVERAGE:0.5:144:1460";
        RRDs::create(@args);
        $ERROR = RRDs::error;
        print "Error: RRDs::create failed for '$_[0]' : $ERROR\n" if $ERROR;
    }
}


sub gather {
    my ($dev, $hdt1, $hdtT, $hdtD, $res);
    # device names in $_[0]
    $res = "$dbf:";
    undef @temps;
    @devs = split /\s+/, $_[0];
    foreach $_ (@devs) {
        $dev = "/dev/$_";
        my $line = `/usr/sbin/hddtemp -q $dev`;
        chomp( $line );
        my ( $devN, $devD, $devT ) = split( /\:\s+/, $line );
        #print "HDtemp $_[0]: '$devN' '$devD' '$devT'\n";
        my ( $dev1, $dev2 ) = split( /\s+or\s+/, $devT );
        #print "HDtemp $_[0]: '$dev1' '$dev2'\n";
        ( $hdt1, $hdtT ) = split( /\s+/, $dev1 );
        #print "HDtemp $_[0]: '$hdt1' '$hdtT'\n";
        if ($devN ne $dev) {
            $hdt1 = 0; $hdtT = '?'; $hdtD = '';
        } else {
            $hdtD = $devD;
        }
        if ("$hdtT" eq "") {$hdt1 = "C"; }
        $out .= "$_: $hdt1, ";
        push @temps, $hdt1;
    }
    chop $out; # remove extra space
    chop $out; # remove extra comma
    print "$out\n";
}

sub update {
    #   $_[0] = filename
    my($str1, $str2);
    $str1 = '';
    $str2 = 'N:';
    for($i = 0; $i < scalar(@temps); $i++) {
      $str1 .= ("hdt" . ($i + 1) . ":");
      $str2 .= ($temps[$i] . ":");
    }
    chop $str1; # Get rid of last colon
    chop $str2; # Get rid of last colon
    RRDs::update("$log/$_[0].rrd", "-t", $str1, $str2);
    print "$str1\n$str2\n";
    $ERROR = RRDs::error;
    print "Error: RRDs::update for '$_[0]' : $ERROR\n" if $ERROR;
}

sub graph {
    #   $_[0] = time interval (ie: day...)
    #   $_[1] = filename suffix.
    undef @args;
    @devs = split /\s+/, $dev;
    @args = ( "$png/$dbf-$_[1].png", "-s -1$_[0]", "-aPNG",
        "-w $Gwd", "-h $Ght", "-E", "-l 20", "-M",
        "--color", "SHADEA$color",
        "--color", "SHADEB$color",
        "--color", "BACK$color",
        "-t Disk temperature :: $_[0]");
    for($i = 0; $i < scalar(@temps); $i++) {
        push @args, "DEF:hdt" . ($i + 1) . "=$log/$dbf.rrd:hdt" . ($i + 1) . ":A
VERAGE";
        push @args, "LINE1:hdt" . ($i+1) . "$colors[$i]: $devs[$i] degrees C\\:"
,
        "GPRINT:hdt" . ($i + 1) . ":MIN:Minimum\\: %.0lf",
        "GPRINT:hdt" . ($i + 1) . ":MAX:Maximum\\: %.0lf",
        "GPRINT:hdt" . ($i + 1) . ":AVERAGE:Average\\: %.2lf",
        "GPRINT:hdt" . ($i + 1) . ":LAST:Current\\: %.1lf\\j";
    }
    RRDs::graph(@args);
    $ERROR = RRDs::error;
    print "Error: RRDs::graph failed for '$_[0]' : $ERROR\n" if $ERROR;
}
########################################################################
create "$dbf";
gather "$dev";
update "$dbf";
graph 'day',   'Daily';
graph 'week',  'Weekly';
graph 'month', 'Monthly';
graph 'year',  'Yearly';
########################################################################
# vim: sw=4 ts=8
# End


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 25, 2007 8:48 am 
Offline
Joined: Wed Feb 14, 2007 9:10 am
Posts: 12
Nifty script! Good on ya, mate!


Top
 Profile  
 
 Post subject: Error when running
PostPosted: Sat Aug 04, 2007 12:18 pm 
Offline
Joined: Sat Aug 19, 2006 11:53 pm
Posts: 39
Location: Monterey, CA USA
First off, thank you very much. I now see the temps for both drives... sweet!!

For anyone else who might trip on this like I did...
When I first tried this, I got this error:

Error: RRDs::graph failed for 'day' : Cannot parse CF in 'DEF:hdt1=/myth/rrd/log/HDtemp.rrd:hdt1:A
VERAGE'

Being a newb, and after a lot of trial and error, I finally got it working.

Three quarters of the way down the script, on this line:
Code:
push @args, "DEF:hdt" . ($i + 1) . "=$log/$dbf.rrd:hdt" . ($i + 1) . ":A
VERAGE";

you'll notice that it's not all one line. Changing it to:
Code:
push @args, "DEF:hdt" . ($i + 1) . "=$log/$dbf.rrd:hdt" . ($i + 1) . ":AVERAGE";

makes it work.

Again, a big thank you. Couldn't have done it myself.

_________________
R5F27 combined backend/frontend
Nvidia 6200 graphics card
Intel P4 1.8, 768Meg PC133, Seagate 300GB & 500GB (PATA) in LVM
Hauppauge PVR150
Iguana Works serial IR transceiver


Top
 Profile  
 

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 


All times are UTC - 6 hours




Who is online

Users browsing this forum: No registered users and 14 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group

Theme Created By ceyhansuyu