"-t $Lang::tr{'disk access per'} $Lang::tr{$period} $disk",
"DEF:read=$rrdlog/disk-$disk.rrd:readsect:AVERAGE",
"DEF:write=$rrdlog/disk-$disk.rrd:writesect:AVERAGE",
+ "DEF:standby=$rrdlog/hddshutdown-$disk.rrd:standby:AVERAGE",
+ "CDEF:st=standby,INF,*",
+ "AREA:st".$color{"color19"}.":standby\\j",
"AREA:read".$color{"color11"}.":$Lang::tr{'sectors read from disk per second'}",
"STACK:write".$color{"color12"}.":$Lang::tr{'sectors written to disk per second'}\\j",
"COMMENT: \\j",
"--color", "BACK".$color{"color21"},
"-t $Lang::tr{'harddisk temperature'} ($Lang::tr{'graph per'} $Lang::tr{$period})",
"DEF:temperature=$rrdlog/hddtemp-$disk.rrd:temperature:AVERAGE",
+ "DEF:standby=$rrdlog/hddshutdown-$disk.rrd:standby:AVERAGE",
+ "CDEF:st=standby,INF,*",
+ "AREA:st".$color{"color19"}.":standby\\j",
"LINE2:temperature".$color{"color11"}.":$Lang::tr{'hdd temperature in'} C\\j",
"COMMENT:$Lang::tr{'maximal'}",
"COMMENT:$Lang::tr{'average'}",
# 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
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}'`;
-
-if ( $_ =~ /^s/ ){$status = `sdparm --command=ready /dev/$_ | tail -1`;}
-else {$status = `hdparm -C /dev/$_ | tail -1 | cut -d: -f2`;}
-
-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";}
- }
+ 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 ($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-$_"); }
+ }
+
+ 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
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
$ERROR = RRDs::error;
print "Error in RRD::create for hdd-$disk: $ERROR\n" if $ERROR;
}
- $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_hddtemp" )
+ # Temperaturlesen wÃrde die Platte aufwecken!!!
+ if (!$standby)
{
- $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
-
- if ( index($hdd_output, "S.M.A.R.T.") != -1 )
+ $temp = 0;
+ my $hdd_output = '';
+ my $smart_output = '';
+
+ if ( -e "$path_smartctl" )
{
- $temp = 0;
+ system("$path_smartctl -iHA -d ata /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");
}
- elsif ( index($hdd_output, "no sensor") != -1 )
+
+ if ( -e "$path_hddtemp" )
{
- $temp = 1;
+ $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
+
+ 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, "$disk") != -1 )
+ elsif ( -e "/var/log/smartctl_out_hddtemp-$disk" )
{
- $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
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);
+
}
###