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

Merge pull request #613 from mittyorz/disk/raid/refactor

refactoring, bugfix and enhancement for disk/raid plugin
This commit is contained in:
Stig Sandbeck Mathisen 2015-05-05 13:38:08 +02:00
commit b6bec53396

View file

@ -12,11 +12,11 @@
if ($ARGV[0] and $ARGV[0] eq "autoconf") { if ($ARGV[0] and $ARGV[0] eq "autoconf") {
if (-r "/proc/mdstat" and `grep md /proc/mdstat`) { if (-r "/proc/mdstat" and `grep md /proc/mdstat`) {
print "yes\n"; print "yes\n";
exit 0; exit 0;
} else { } else {
print "no RAID devices\n"; print "no RAID devices\n";
exit 1; exit 1;
} }
} }
@ -29,52 +29,105 @@ if ( $ARGV[0] and $ARGV[0] eq "config" ) {
print "graph_scale no\n"; print "graph_scale no\n";
} }
{ open(my $mdstat, "/proc/mdstat");
local( $/, *MDSTAT ) ; my(@text) = <$mdstat>;
open (MDSTAT, "/proc/mdstat") or exit 1; # contents of <$mdstat> may be changed at next reading, so fetch the contents at a time
#open (MDSTAT, "/etc/munin/plugins/sample.failed") or exit 1; close($mdstat);
my $text = <MDSTAT>;
close MDSTAT;
# Should look like "active raid1 sda1[0] sdc1[2] sdb1[1]" my($devinfo_re, $devstat_re, $action_re) = (
# Interestingly, swap is presented as "active (auto-read-only)" '(md\d+)\s+:\s+active\s+(\(read-only\)\s+|\(auto-read-only\)\s+|)(\w+)\s+(.*)',
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)/ ) { '.*\[(\d+)\/(\d+)]\s+\[(\w+)]',
my($dev,$dummy,$type,$members,$nmem,$nact,$status,$dummy2,$dummy3,$proc) = ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10); '.*(reshape|check|resync|recovery)\s*=\s*(\d+\.\d+%|\w+)(.*finish=(.*min))?',
# print "$text\nitem: $dev $type ($members) status=$status $proc\n"; );
if ( $ARGV[0] and $ARGV[0] eq "config" ) { # Interestingly, swap is presented as "active (auto-read-only)"
print "$dev.label $dev\n"; # and mdadm has '--readonly' option to make the array 'active (read-only)'
print "$dev.info $type $members\n";
# 100: means less than 100 my($dev, $ro, $type, $members, $nmem, $nact, $status, $action, $proc, $minute);
# Because of an unfound bug, sometimes reported as 99.XX even when OS reports 100. while (@text) {
print "$dev.critical 98:\n"; my $line = shift @text;
print $dev, "_rebuild.label $dev rebuilt\n"; if ($line =~ /$devinfo_re/) {
print $dev, "_rebuild.info $type\n"; # first line should like "active raid1 sda1[0] sdc1[2] sdb1[1]"
# Because of an unfound bug, sometimes reported as 99.XX even when OS reports 100. $dev = $1;
print $dev, "_rebuild.critical 98:\n"; $ro = $2 || '';
print $dev, "_check.label $dev check/resync \n"; $type = $3;
print $dev, "_check.info $type\n"; $members = $4;
} else {
my $pct = 100 * $nact / $nmem; $line = shift @text;
my $rpct = 100; if ($line =~ /$devstat_re/) {
if ( $pct < 100 ) { # second line should like "123456 blocks super 1.2 [2/2] [UU]"
my @output = `/sbin/mdadm -D /dev/$dev | grep Rebuild`; $nmem = $1;
if( $output[0] and $output[0] =~ /([0-9]+)% complete/ ) { $nact = $2;
$rpct = $1; $status = $3;
} else { }
$rpct = 0; else {
} # sencond line did not exist on /proc/mdstat
} next;
if ( $proc ) { }
$cpct = $proc;
} else { $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
$action = $1;
my $percent = $2;
$minute = $4 || '';
if ($percent =~ /(\d+\.\d+)%/) {
$proc = $1;
}
else {
# 'resync=DELAYED' or 'resync=PENDING'
$action .= " ($percent)";
$proc = -1;
}
}
else {
# array is not in action
$action = 'idle';
$minute = '';
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 $ro$members\n";
# 100: means less than 100
# Because of an unfound bug, sometimes reported as 99.XX even when OS reports 100.
print "$dev.critical 98:\n";
print $dev, "_rebuild.label $dev reshape/recovery\n";
print $dev, "_rebuild.info $action $minute\n";
# Because of an unfound bug, sometimes reported as 99.XX even when OS reports 100.
print $dev, "_rebuild.critical 98:\n";
print $dev, "_check.label $dev check/resync \n";
print $dev, "_check.info $action $minute\n";
} else {
my $pct = 100 * $nact / $nmem;
my $rpct = 100;
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;
$cpct = 0; $cpct = 0;
} }
print "$dev.value $pct\n"; else {
print $dev, "_rebuild.value $rpct\n"; # reshape/recovery was done, $rpct => 100
print $dev, "_check.value $cpct\n"; $cpct = $proc;
} }
$text = $'; }
}
print "$dev.value $pct\n";
print $dev, "_rebuild.value $rpct\n";
print $dev, "_check.value $cpct\n";
}
} }
exit 0; exit 0;