Skip to content

Commit

Permalink
improve usage file errors for mogadm
Browse files Browse the repository at this point in the history
if usage file is corrupt, try to tell the user a little more about why and
hide spurious errors.
  • Loading branch information
dormando committed Oct 28, 2011
1 parent 761ec9e commit 36a7bd6
Showing 1 changed file with 34 additions and 24 deletions.
58 changes: 34 additions & 24 deletions mogadm
Original file line number Diff line number Diff line change
Expand Up @@ -468,39 +468,49 @@ sub cmd_check {
foreach my $hosturl (@urls) {
my ($hostid, $url) = @$hosturl;
my $devs = $devices->{$hostid};
foreach my $devid (sort { $a <=> $b } keys %$devs) {
DEV: foreach my $devid (sort { $a <=> $b } keys %$devs) {
my $dev = $devs->{$devid};
my $status = $dev->{status} || "??";
next if $status eq "dead";

printf " [%2d] %-7s", $hostid, "dev$devid";

my $usage = get($url . "/dev$devid/usage");
if (defined $usage) {
my %data = ( map { split(/:\s+/, $_) } split(/\r?\n/, $usage) );
foreach (qw(time used total avail)) {
$data{$_} = 0 if (!$data{$_} ||
$data{$_} !~ /\A\d+(\.\d+)?\Z/);
if (! defined $usage) {
print "REQUEST FAILURE FETCHING: $url" . "dev$devid/usage\n";
next;
}
if (length($usage) < 1) {
print "USAGE FILE BROKEN OR EMPTY: $url" . "dev$devid/usage\n";
next;
}
my %data = ( map { split(/:\s+/, $_) } split(/\r?\n/, $usage) );
foreach (qw(time used total avail)) {
$data{$_} = 0 if (!$data{$_} ||
$data{$_} !~ /\A\d+(\.\d+)?\Z/);
}
foreach (qw(available device disk)) {
if (! exists $data{$_} || !$data{$_}) {
print "MISSING FIELD ($_) FROM USAGE FILE: $url" . "dev$devid/usage\n";
next DEV;
}
$data{age} = $now - $data{time};
$data{used} /= 1024**2;
$data{total} /= 1024**2;
$data{available} /= 1024**2;
$data{avail} = $data{available};
my $pct = 100 - $data{available}/$data{total}*100;
$total{used} += $data{used};
$total{avail} += $data{avail};
$total{total} += $data{total};

$dev->{utilization} = 0 if (!defined($dev->{utilization}) ||
$dev->{utilization} !~ /\A\d+(\.\d+)?\Z/);
printf(" %10.3f %10.3f %10.3f %6.2f%% %-7s %5.1f\n",
(map { $data{$_} } qw(total used avail)),
$pct, ($dev->{observed_state} || "?"),
$dev->{utilization});
} else {
print "REQUEST FAILURE FETCHING: $url" . "/dev$devid/usage\n";
}
$data{age} = $now - $data{time};
$data{used} /= 1024**2;
$data{total} /= 1024**2;
$data{available} /= 1024**2;
$data{avail} = $data{available};
my $pct = 100 - $data{available}/$data{total}*100;
$total{used} += $data{used};
$total{avail} += $data{avail};
$total{total} += $data{total};

$dev->{utilization} = 0 if (!defined($dev->{utilization}) ||
$dev->{utilization} !~ /\A\d+(\.\d+)?\Z/);
printf(" %10.3f %10.3f %10.3f %6.2f%% %-7s %5.1f\n",
(map { $data{$_} } qw(total used avail)),
$pct, ($dev->{observed_state} || "?"),
$dev->{utilization});
}
}
my $pct = 0;
Expand Down

0 comments on commit 36a7bd6

Please sign in to comment.