From: maniacikarus Date: Sun, 23 Sep 2007 08:12:07 +0000 (+0000) Subject: Meine Platte zur hddtemp.db hinzugefuegt X-Git-Tag: v2.3-beta1~361 X-Git-Url: http://git.ipfire.org/?p=people%2Fpmueller%2Fipfire-2.x.git;a=commitdiff_plain;h=471a46f7e64cdc06639e912b4bc8c3a68207a06f 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 --- diff --git a/config/cfgroot/graphs.pl b/config/cfgroot/graphs.pl index 4573449dc8..804b70a059 100644 --- a/config/cfgroot/graphs.pl +++ b/config/cfgroot/graphs.pl @@ -230,6 +230,9 @@ sub updatediskgraph { "-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", @@ -367,6 +370,9 @@ sub updatehddgraph { "--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'}", diff --git a/config/etc/hddtemp.db b/config/etc/hddtemp.db index 4a061cfcb6..a0110fde8a 100644 --- a/config/etc/hddtemp.db +++ b/config/etc/hddtemp.db @@ -272,6 +272,9 @@ #"SAMSUNG SV1204H" 194 C "Samsung 120G" "SAMSUNG SV(0401|0802|1203|1604)N" 194 C "Samsung SpinPoint V80 serie" "SAMSUNG SV4012H" 194 C "Samsung 40GB, 5400RPM, 2MB cache" +"SAMSUNG HM100JC" 194 C "Samsung 100GB,5400RPM, 8MB cache" + + ######################################## ############# Seagate drives diff --git a/src/scripts/hddshutdown b/src/scripts/hddshutdown index 853f769e4b..1a7a1d56f2 100644 --- a/src/scripts/hddshutdown +++ b/src/scripts/hddshutdown @@ -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}'`; - -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 diff --git a/src/scripts/makegraphs b/src/scripts/makegraphs index ef959684b3..eb1ee439bc 100644 --- a/src/scripts/makegraphs +++ b/src/scripts/makegraphs @@ -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 = ''; - - 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 @@ -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); + } ###