munin-nodeでSSDのwrite countを記録する
暮れにSSDを2台購入し、サーバとWinマシンのそれぞれに取り付けて使っておりましたが、MLCですので寿命が心配。Winの方には幸いにもJSMonitorなるsmart値のMaxWriteCountとAverageWriteCountから寿命を逆算するソフトがあるので非常に便利なのですが、Linux用のものは用意されている訳でもないので(VS2005用のソースは付属)munin-nodeで記録できるように作成してみました。
こんな感じです。まぁ変化の具合が一目でわかるので便利ですね。
とりあえず、ヘナチョでっちあげですが、以下にソースを。
こんな感じです。まぁ変化の具合が一目でわかるので便利ですね。
とりあえず、ヘナチョでっちあげですが、以下にソースを。
-- ssd_count
| #!/usr/bin/perl -w use strict; my $smartctl = exists $ENV{smartctl} ? $ENV{smartctl} : undef; # If the envvar is not set, look for smartctl # first, try $PATH $smartctl = `which smartctl` unless $smartctl; chomp $smartctl; $smartctl = undef unless -x $smartctl; # Still not found? Check obvious places my @dirs = qw(/usr/bin /usr/sbin /usr/local/bin /usr/local/sbin); until ($smartctl or @dirs == 0) { my $dir = shift @dirs; my $path = $dir.'/smartctl'; $smartctl = $path if -x $path; } $ENV{LANG} = 'C'; $ENV{LC_ALL} = 'C'; # Sort list of drives if (defined $ARGV[0]) { if ($ARGV[0] eq 'autoconf') { if ($smartctl and -x $smartctl) { print "yes\n"; exit 0; } else { print "no (smartctl not found)\n"; exit 1; } } elsif ($ARGV[0] eq 'config') { print "graph_title SSD writecount\n"; print "graph_args --base 1000 -l 0\n"; print "graph_vlabel count\n"; print "graph_category sensors\n"; print "graph_info This graph shows the SSD write count.\n"; print "max.label max\n"; print "ave.label ave\n"; print "remain.label remain\n"; exit 0; } } my $cmd = $smartctl.' -A '; $cmd .= '/dev/sdi'; ←ここは対象となるSSDを直接指定 my $output = `$cmd`; if ($output =~ /^(234 Unknown_Attribute.*)/m) { my @F = split ' ', $1; # my $upp = sprintf("%ld", $F[9]/4294967296); my $bot = sprintf("%ld", ($F[9]-4294967296*$upp)); my $uppa = sprintf("%08x", $upp); my $bota = sprintf("%08x", $bot); my $maxlo = hex(substr($uppa,6,2)); my $maxhi = hex(substr($bota,0,2)); my $max = sprintf("%d", $maxhi*256+$maxlo); my $avelo = hex(substr($bota,4,2)); my $avehi = hex(substr($bota,6,2)); my $ave = sprintf("%d", $avehi*256+$avelo); my $remain = 1000-$avehi; print "max.value $max\n"; print "ave.value $ave\n"; print "remain.value $ave\n"; } |
コメントする