diff --git a/plugins/disk/raid b/plugins/disk/raid index ca617eaa..f3ff22df 100755 --- a/plugins/disk/raid +++ b/plugins/disk/raid @@ -30,18 +30,53 @@ if ( $ARGV[0] and $ARGV[0] eq "config" ) { } open(my $mdstat, "/proc/mdstat"); -my $text; -{ - local($/); - $text = <$mdstat>; -} +my(@text) = <$mdstat>; +# contents of <$mdstat> may be changed at next reading, so fetch the contents at a time close($mdstat); -# Should look like "active raid1 sda1[0] sdc1[2] sdb1[1]" -# Interestingly, swap is presented as "active (auto-read-only)" -while ($text =~ /(md\d+)\s+:\s+active\s+(\(auto-read-only\)\s+|)(\w+)\s+(.*)\n.*\[(\d+)\/(\d+)]\s+\[(\w+)]\n(.*(check|resync)\s=\s+(\d+\.\d+)%|.*\n)/ ) { - my($dev,$dummy,$type,$members,$nmem,$nact,$status,$dummy2,$dummy3,$proc) = ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10); -# print "$text\nitem: $dev $type ($members) status=$status $proc\n"; +my($devinfo_re, $devstat_re, $action_re) = ( + '(md\d+)\s+:\s+active\s+(\(auto-read-only\)\s+|)(\w+)\s+(.*)', + '.*\[(\d+)\/(\d+)]\s+\[(\w+)]', + '(.*(check|resync)\s=\s+(\d+\.\d+)%)', +); + +my($dev, $type, $members, $nmem, $nact, $status, $proc); +while (@text) { + my $line = shift @text; + if ($line =~ /$devinfo_re/) { + # first line should like "active raid1 sda1[0] sdc1[2] sdb1[1]" + $dev = $1; + $type = $3; + $members = $4; + + $line = shift @text; + if ($line =~ /$devstat_re/) { + # second line should like "123456 blocks super 1.2 [2/2] [UU]" + $nmem = $1; + $nact = $2; + $status = $3; + } + else { + # sencond line did not exist on /proc/mdstat + next; + } + + $line = shift @text; + if ($line =~ /$action_re/) { + # third line should like " [==>..................] check = 10.0% (12345/123456) finish=123min speed=12345/sec" + # this line will appear only when the array is in action + $proc = $3; + } + else { + # array is not in action + unshift(@text, $line); + } + } + else { + # skip until first line is found + next; + } + if ( $ARGV[0] and $ARGV[0] eq "config" ) { print "$dev.label $dev\n"; print "$dev.info $type $members\n"; @@ -74,7 +109,6 @@ while ($text =~ /(md\d+)\s+:\s+active\s+(\(auto-read-only\)\s+|)(\w+)\s+(.*)\n.* print $dev, "_rebuild.value $rpct\n"; print $dev, "_check.value $cpct\n"; } - $text = $'; } exit 0;