Meine Platte zur hddtemp.db hinzugefuegt

hddshutdown Routine verbessert


git-svn-id: http://svn.ipfire.org/svn/ipfire/trunk@915 ea5c0bd1-69bd-2848-81d8-4f18e57aeed8
This commit is contained in:
maniacikarus
2007-09-23 08:12:07 +00:00
parent 0872e5501d
commit 471a46f7e6
4 changed files with 151 additions and 73 deletions

View File

@@ -5,7 +5,7 @@
# This code is distributed under the terms of the GPL
#
# 18.09.2007 Maniacikarus - IPFire.org - maniacikarus@ipfire.org
#
# 22.09.2007 Arne_F - fitzenreiter.de - arne@fitzenreiter.de
# begin
@@ -13,38 +13,48 @@ my @devices = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
my $diskstats = "";
my $newdiskstats = "";
my $debug = 1;
my $status = "unknown";
my $status = "";
if ($debug){print "### Searching for available Disks ###\n";}
foreach (@devices){
chomp $_;
$diskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
chomp $_;
$diskstats = `cat /tmp/hddstats-$_`;
chomp $diskstats;
$newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
chomp $newdiskstats;
$status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;
chomp $status;
if ( $_ =~ /^s/ ){$status = `sdparm --command=ready /dev/$_ | tail -1`;}
else {$status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;}
if ($debug){print "Device ".$_." IDE Power status:".$status."\n";}
if (-e "/tmp/hddshutdown-$_" && $status !~/standby/)
{
if ($debug){print "Remove wrong standby marking\n";}
if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
}
chomp $status;
chomp $diskstats;
if ($debug){print "Device ".$_." is in status ".$status." and has ".$diskstats." write and read Requests.\n";}
sleep 30;
$newdiskstats = `iostat -d -t $_ | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
chomp $newdiskstats;
if ($diskstats eq $newdiskstats && $status !~/standby/){
if ($debug){print "Device ".$_." is set to standy.\n";}
if ( $_ =~ /^s/ ){system("sdparm --command=stop /dev/$_");}
else {system("/sbin/hdparm -y /dev/$_");}
system("touch /tmp/hddshutdown-$_");
}
elsif ($diskstatus{$_} ne "0" ){
if ($debug){print "Device ".$_." is active.\n";}
if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
}
elsif ( $status =~/standby/ ){
if ($debug){print "Device ".$_." is in standby mode.\n";}
}
if ($debug){print "Device ".$_." has ".$newdiskstats." write and read Requests, was ".$diskstats." at last run.\n";}
if ($diskstats eq $newdiskstats && (! -e "/tmp/hddshutdown-$_") )
{
if ($debug){print "Setting Device ".$_." to standby ... ";}
$status = `hdparm -y /dev/$_ 2>&1`;
chomp $status;
if ($status !~/failed/)
{
if ($debug){print "OK\n";}
system("touch /tmp/hddshutdown-$_");
}
else
{
if ($debug){print "FAIL\n";}
}
}
if ($diskstats ne $newdiskstats)
{
if ($debug){print "Device ".$_." is active.\n";}
if ( -e "/tmp/hddshutdown-$_" ) { system("unlink /tmp/hddshutdown-$_"); }
}
system("echo $newdiskstats > /tmp/hddstats-$_");
}
# end

View File

@@ -403,6 +403,28 @@ sub updatelq {
sub updatehdddata
{
my $disk = $_[0];
my $standby;
if ( ! -e "$rrdlog/hddshutdown-$disk.rrd")
{
# database did not exist -> create
RRDs::create ("$rrdlog/hddshutdown-$disk.rrd", "--step=300",
"DS:standby:GAUGE:600:0:1",
"RRA:AVERAGE:0.5:1:576",
"RRA:AVERAGE:0.5:6:672",
"RRA:AVERAGE:0.5:24:732",
"RRA:AVERAGE:0.5:144:1460");
$ERROR = RRDs::error;
print "Error in RRD::create for hddshutdown-$disk: $ERROR\n" if $ERROR;
}
if (-e "/tmp/hddshutdown-$disk") {$standby = 1;}
else {$standby = 0;}
RRDs::update ("$rrdlog/hddshutdown-$disk.rrd", "-t", "standby", "N:$standby");
$ERROR = RRDs::error;
print "Error in RRD::update for hddshutdown-$disk: $ERROR\n" if $ERROR;
if ( ! -e "$rrdlog/hddtemp-$disk.rrd")
{
# database did not exist -> create
@@ -415,62 +437,70 @@ sub updatehdddata
$ERROR = RRDs::error;
print "Error in RRD::create for hdd-$disk: $ERROR\n" if $ERROR;
}
$temp = 0;
my $hdd_output = '';
my $smart_output = '';
# Temperaturlesen w<>rde die Platte aufwecken!!!
if (!$standby)
{
$temp = 0;
my $hdd_output = '';
my $smart_output = '';
if ( -e "$path_smartctl" )
{
system("$path_smartctl -iHA -d ata /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");
}
if ( -e "$path_smartctl" )
{
system("$path_smartctl -iHA -d ata /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");
}
if ( -e "$path_hddtemp" )
{
$hdd_output = `$path_hddtemp -qn /dev/$disk`;
if ( -e "$path_hddtemp" )
{
$hdd_output = `$path_hddtemp -qn /dev/$disk`;
# I know 4 response possible responses:
#
# /dev/harddisk: harddisk type: S.M.A.R.T. not available
# /dev/harddisk: harddisk type: no sensor
# /dev/harddisk: harddisk type: 37?C or ?F
# 37
# I know 4 response possible responses:
#
# /dev/harddisk: harddisk type: S.M.A.R.T. not available
# /dev/harddisk: harddisk type: no sensor
# /dev/harddisk: harddisk type: 37?C or ?F
# 37
if ( index($hdd_output, "S.M.A.R.T.") != -1 )
{
$temp = 0;
if ( index($hdd_output, "S.M.A.R.T.") != -1 )
{
$temp = 0;
}
elsif ( index($hdd_output, "no sensor") != -1 )
{
$temp = 1;
}
elsif ( index($hdd_output, "$disk") != -1 )
{
$hdd_output =~ /.*:.*:\s*(\d+).*\s/;
$temp = $1;
}
else
{
$hdd_output =~ /(\d+)\s/;
$temp = $1;
}
}
elsif ( index($hdd_output, "no sensor") != -1 )
elsif ( -e "/var/log/smartctl_out_hddtemp-$disk" )
{
$temp = 1;
}
elsif ( index($hdd_output, "$disk") != -1 )
{
$hdd_output =~ /.*:.*:\s*(\d+).*\s/;
$temp = $1;
$hdd_output = `cat /var/log/smartctl_out_hddtemp-$disk | grep Temperature_`;
my @t = split(/\s+/,$hdd_output);
$temp = $t[9];
}
else
{
$hdd_output =~ /(\d+)\s/;
$temp = $1;
$temp = 0;
}
}
elsif ( -e "/var/log/smartctl_out_hddtemp-$disk" )
{
$hdd_output = `cat /var/log/smartctl_out_hddtemp-$disk | grep Temperature_`;
my @t = split(/\s+/,$hdd_output);
$temp = $t[9];
}
else
{
$temp = 0;
}
print "Temperature for ".$disk."->".$temp."<-\n";
RRDs::update ("$rrdlog/hddtemp-$disk.rrd", "-t", "temperature", "N:$temp");
$ERROR = RRDs::error;
print "Error in RRD::update for hdd-$disk: $ERROR\n" if $ERROR;
print "Temperature for ".$disk."->".$temp."<-\n";
# Nur ins RDD wenn nicht 0 (sonst klappt die min Anzeige nicht)
if ($temp)
{
RRDs::update ("$rrdlog/hddtemp-$disk.rrd", "-t", "temperature", "N:$temp");
$ERROR = RRDs::error;
print "Error in RRD::update for hdd-$disk: $ERROR\n" if $ERROR;
}
}
}
sub updatembmondata
@@ -572,13 +602,42 @@ my $disk = $_;
chomp $disk;
print "Working on disk ".$disk.".\n";
updatediskdata($disk);
updatehdddata($disk);
my $status = "";
my $diskstats = "";
my $newdiskstats = "";
$diskstats = `cat /tmp/hddstats-$disk`;
chomp $diskstats;
my $newdiskstats = `/usr/bin/iostat -d -t $disk | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
chomp $newdiskstats;
my $status = `hdparm -C /dev/$disk | tail -1 | cut -d: -f2`;
chomp $status;
if ($status !~/standby/ || $diskstats ne $newdiskstats)
{
if (-e "/tmp/hddshutdown-$disk")
{
system("unlink /tmp/hddshutdown-$disk");
}
}
if (-e "/tmp/hddshutdown-$disk")
{
$status = " standby\n";
}
else
{
$status = " active\n";
}
open(DATEI, ">>/tmp/hddstatus") || die "Datei nicht gefunden";
print DATEI $disk."-".$status;
close(DATEI);
updatediskdata($disk);
updatehdddata($disk);
}
###