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:
parent
9845279a30
commit
760b14f554
1 changed files with 28 additions and 15 deletions
|
@ -37,12 +37,12 @@ close($mdstat);
|
|||
my($devinfo_re, $devstat_re, $action_re) = (
|
||||
'(md\d+)\s+:\s+active\s+(\(read-only\)\s+|\(auto-read-only\)\s+|)(\w+)\s+(.*)',
|
||||
'.*\[(\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)"
|
||||
# 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) {
|
||||
my $line = shift @text;
|
||||
if ($line =~ /$devinfo_re/) {
|
||||
|
@ -67,10 +67,19 @@ while (@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;
|
||||
$action = $1;
|
||||
my $percent = $2;
|
||||
if ($percent =~ /(\d+\.\d+)%/) {
|
||||
$proc = $1;
|
||||
}
|
||||
else {
|
||||
# 'resync=DELAYED' or 'resync=PENDING'
|
||||
$proc = -1;
|
||||
}
|
||||
}
|
||||
else {
|
||||
# array is not in action
|
||||
$action = 'idle';
|
||||
unshift(@text, $line);
|
||||
}
|
||||
}
|
||||
|
@ -94,19 +103,23 @@ while (@text) {
|
|||
} else {
|
||||
my $pct = 100 * $nact / $nmem;
|
||||
my $rpct = 100;
|
||||
if ( $pct < 100 ) {
|
||||
my @output = `/sbin/mdadm -D /dev/$dev | grep Rebuild`;
|
||||
if( $output[0] and $output[0] =~ /([0-9]+)% complete/ ) {
|
||||
$rpct = $1;
|
||||
} else {
|
||||
my $cpct = 100;
|
||||
if ($action =~ /reshape|recovery/) {
|
||||
$rpct = $proc;
|
||||
$cpct = 0; # check/resync is not done
|
||||
}
|
||||
elsif ($action =~ /check|resync/) {
|
||||
if ($proc < 0) {
|
||||
# array is on DELAYED or PENDING, further info is unknown
|
||||
$rpct = 0;
|
||||
}
|
||||
}
|
||||
if ( $proc ) {
|
||||
$cpct = $proc;
|
||||
} else {
|
||||
$cpct = 0;
|
||||
}
|
||||
else {
|
||||
# reshape/recovery was done, $rpct => 100
|
||||
$cpct = $proc;
|
||||
}
|
||||
}
|
||||
|
||||
print "$dev.value $pct\n";
|
||||
print $dev, "_rebuild.value $rpct\n";
|
||||
print $dev, "_check.value $cpct\n";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue