1
0
Fork 0
mirror of https://github.com/munin-monitoring/contrib.git synced 2025-07-22 02:51:03 +00:00

enhancement - use only /proc/mdstat, stop using /sbin/mdadm

* mdadm needs super-user privileges, but /proc/mdstat is readable for nobody
 * fetch an array state from mdstat 'reshape|check|resync|recovery'
  * reshape, recovery: rebuilding array -> set percent to _rebuild.value
  * check, resync: data scrubbing or mirror rebuilding => set percent to _check.value
   * resync=DELAYED|PENDING => set both to zero, because details are unknown even if using mdadm

 * more info about /proc/mdstat => kernel src:/drivers/md/md.c, md_seq_show()
This commit is contained in:
Ken-ichi Mito 2015-05-04 18:28:34 +09:00
parent 9845279a30
commit 760b14f554

View file

@ -37,17 +37,17 @@ close($mdstat);
my($devinfo_re, $devstat_re, $action_re) = ( my($devinfo_re, $devstat_re, $action_re) = (
'(md\d+)\s+:\s+active\s+(\(read-only\)\s+|\(auto-read-only\)\s+|)(\w+)\s+(.*)', '(md\d+)\s+:\s+active\s+(\(read-only\)\s+|\(auto-read-only\)\s+|)(\w+)\s+(.*)',
'.*\[(\d+)\/(\d+)]\s+\[(\w+)]', '.*\[(\d+)\/(\d+)]\s+\[(\w+)]',
'(.*(check|resync)\s=\s+(\d+\.\d+)%)', '.*(reshape|check|resync|recovery)\s*=\s*(\d+\.\d+%|\w+)',
); );
# Interestingly, swap is presented as "active (auto-read-only)" # Interestingly, swap is presented as "active (auto-read-only)"
# and mdadm has '--readonly' option to make the array 'active (read-only)' # and mdadm has '--readonly' option to make the array 'active (read-only)'
my($dev, $type, $members, $nmem, $nact, $status, $proc); my($dev, $type, $members, $nmem, $nact, $status, $action, $proc);
while (@text) { while (@text) {
my $line = shift @text; my $line = shift @text;
if ($line =~ /$devinfo_re/) { if ($line =~ /$devinfo_re/) {
# first line should like "active raid1 sda1[0] sdc1[2] sdb1[1]" # first line should like "active raid1 sda1[0] sdc1[2] sdb1[1]"
$dev = $1; $dev = $1;
$type = $3; $type = $3;
$members = $4; $members = $4;
@ -67,10 +67,19 @@ while (@text) {
if ($line =~ /$action_re/) { if ($line =~ /$action_re/) {
# third line should like " [==>..................] check = 10.0% (12345/123456) finish=123min speed=12345/sec" # 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 # this line will appear only when the array is in action
$proc = $3; $action = $1;
my $percent = $2;
if ($percent =~ /(\d+\.\d+)%/) {
$proc = $1;
}
else {
# 'resync=DELAYED' or 'resync=PENDING'
$proc = -1;
}
} }
else { else {
# array is not in action # array is not in action
$action = 'idle';
unshift(@text, $line); unshift(@text, $line);
} }
} }
@ -94,19 +103,23 @@ while (@text) {
} else { } else {
my $pct = 100 * $nact / $nmem; my $pct = 100 * $nact / $nmem;
my $rpct = 100; my $rpct = 100;
if ( $pct < 100 ) { my $cpct = 100;
my @output = `/sbin/mdadm -D /dev/$dev | grep Rebuild`; if ($action =~ /reshape|recovery/) {
if( $output[0] and $output[0] =~ /([0-9]+)% complete/ ) { $rpct = $proc;
$rpct = $1; $cpct = 0; # check/resync is not done
} else { }
$rpct = 0; elsif ($action =~ /check|resync/) {
if ($proc < 0) {
# array is on DELAYED or PENDING, further info is unknown
$rpct = 0;
$cpct = 0;
}
else {
# reshape/recovery was done, $rpct => 100
$cpct = $proc;
} }
} }
if ( $proc ) {
$cpct = $proc;
} else {
$cpct = 0;
}
print "$dev.value $pct\n"; print "$dev.value $pct\n";
print $dev, "_rebuild.value $rpct\n"; print $dev, "_rebuild.value $rpct\n";
print $dev, "_check.value $cpct\n"; print $dev, "_check.value $cpct\n";