mirror of
https://github.com/munin-monitoring/contrib.git
synced 2025-07-22 14:16:00 +00:00
refactoring - replace TAB with 8 spaces, use lexical variable for file handle
* reduce indentation of local($/)
This commit is contained in:
parent
c4eb877198
commit
2e0acaca2b
1 changed files with 46 additions and 46 deletions
|
@ -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,52 @@ if ( $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
print "graph_scale no\n";
|
print "graph_scale no\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open(my $mdstat, "/proc/mdstat");
|
||||||
|
my $text;
|
||||||
{
|
{
|
||||||
local( $/, *MDSTAT ) ;
|
local($/);
|
||||||
open (MDSTAT, "/proc/mdstat") or exit 1;
|
$text = <$mdstat>;
|
||||||
#open (MDSTAT, "/etc/munin/plugins/sample.failed") or exit 1;
|
}
|
||||||
my $text = <MDSTAT>;
|
close($mdstat);
|
||||||
close MDSTAT;
|
|
||||||
|
|
||||||
# Should look like "active raid1 sda1[0] sdc1[2] sdb1[1]"
|
# Should look like "active raid1 sda1[0] sdc1[2] sdb1[1]"
|
||||||
# Interestingly, swap is presented as "active (auto-read-only)"
|
# 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)/ ) {
|
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);
|
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";
|
# print "$text\nitem: $dev $type ($members) status=$status $proc\n";
|
||||||
if ( $ARGV[0] and $ARGV[0] eq "config" ) {
|
if ( $ARGV[0] and $ARGV[0] eq "config" ) {
|
||||||
print "$dev.label $dev\n";
|
print "$dev.label $dev\n";
|
||||||
print "$dev.info $type $members\n";
|
print "$dev.info $type $members\n";
|
||||||
# 100: means less than 100
|
# 100: means less than 100
|
||||||
# Because of an unfound bug, sometimes reported as 99.XX even when OS reports 100.
|
# Because of an unfound bug, sometimes reported as 99.XX even when OS reports 100.
|
||||||
print "$dev.critical 98:\n";
|
print "$dev.critical 98:\n";
|
||||||
print $dev, "_rebuild.label $dev rebuilt\n";
|
print $dev, "_rebuild.label $dev rebuilt\n";
|
||||||
print $dev, "_rebuild.info $type\n";
|
print $dev, "_rebuild.info $type\n";
|
||||||
# Because of an unfound bug, sometimes reported as 99.XX even when OS reports 100.
|
# Because of an unfound bug, sometimes reported as 99.XX even when OS reports 100.
|
||||||
print $dev, "_rebuild.critical 98:\n";
|
print $dev, "_rebuild.critical 98:\n";
|
||||||
print $dev, "_check.label $dev check/resync \n";
|
print $dev, "_check.label $dev check/resync \n";
|
||||||
print $dev, "_check.info $type\n";
|
print $dev, "_check.info $type\n";
|
||||||
} else {
|
} else {
|
||||||
my $pct = 100 * $nact / $nmem;
|
my $pct = 100 * $nact / $nmem;
|
||||||
my $rpct = 100;
|
my $rpct = 100;
|
||||||
if ( $pct < 100 ) {
|
if ( $pct < 100 ) {
|
||||||
my @output = `/sbin/mdadm -D /dev/$dev | grep Rebuild`;
|
my @output = `/sbin/mdadm -D /dev/$dev | grep Rebuild`;
|
||||||
if( $output[0] and $output[0] =~ /([0-9]+)% complete/ ) {
|
if( $output[0] and $output[0] =~ /([0-9]+)% complete/ ) {
|
||||||
$rpct = $1;
|
$rpct = $1;
|
||||||
} else {
|
|
||||||
$rpct = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if ( $proc ) {
|
|
||||||
$cpct = $proc;
|
|
||||||
} else {
|
} else {
|
||||||
$cpct = 0;
|
$rpct = 0;
|
||||||
}
|
}
|
||||||
print "$dev.value $pct\n";
|
}
|
||||||
print $dev, "_rebuild.value $rpct\n";
|
if ( $proc ) {
|
||||||
print $dev, "_check.value $cpct\n";
|
$cpct = $proc;
|
||||||
}
|
} else {
|
||||||
$text = $';
|
$cpct = 0;
|
||||||
|
}
|
||||||
|
print "$dev.value $pct\n";
|
||||||
|
print $dev, "_rebuild.value $rpct\n";
|
||||||
|
print $dev, "_check.value $cpct\n";
|
||||||
}
|
}
|
||||||
|
$text = $';
|
||||||
}
|
}
|
||||||
|
|
||||||
exit 0;
|
exit 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue