mirror of
https://github.com/munin-monitoring/contrib.git
synced 2018-11-08 00:59:34 +01:00
760b14f554
* 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()
131 lines
4.0 KiB
Perl
Executable File
131 lines
4.0 KiB
Perl
Executable File
#!/usr/bin/perl -w
|
|
#
|
|
# (c) 2007 Nathan Rutman nathan@clusterfs.com
|
|
#
|
|
# Plugin to monitor RAID status
|
|
#
|
|
# Results are % of healthy drives in a raid device
|
|
# and % rebuilt of devices that are resyncing.
|
|
#
|
|
#%# family=contrib
|
|
#%# capabilities=autoconf
|
|
|
|
if ($ARGV[0] and $ARGV[0] eq "autoconf") {
|
|
if (-r "/proc/mdstat" and `grep md /proc/mdstat`) {
|
|
print "yes\n";
|
|
exit 0;
|
|
} else {
|
|
print "no RAID devices\n";
|
|
exit 1;
|
|
}
|
|
}
|
|
|
|
if ( $ARGV[0] and $ARGV[0] eq "config" ) {
|
|
print "graph_title RAID status\n";
|
|
print "graph_category disk\n";
|
|
print "graph_info This graph monitors RAID disk health. Values are percentage of healthy drives in each raid group. Degraded devices are marked Critical.\n";
|
|
print "graph_args --base 1000 -l 0\n";
|
|
print "graph_vlabel % healthy/rebuilt\n";
|
|
print "graph_scale no\n";
|
|
}
|
|
|
|
open(my $mdstat, "/proc/mdstat");
|
|
my(@text) = <$mdstat>;
|
|
# contents of <$mdstat> may be changed at next reading, so fetch the contents at a time
|
|
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+)]',
|
|
'.*(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, $action, $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
|
|
$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);
|
|
}
|
|
}
|
|
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";
|
|
# 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 rebuilt\n";
|
|
print $dev, "_rebuild.info $type\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 $type\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;
|
|
}
|
|
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";
|
|
}
|
|
}
|
|
|
|
exit 0;
|
|
|