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