-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_mounts.pl
executable file
·59 lines (44 loc) · 1.31 KB
/
check_mounts.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/perl
# check_mounts.pl
# Author: Johan van den Dorpe <jvd@dneg.com>
# Identify hung mounts and other NFS problems
use strict;
use warnings;
use Data::Dumper;
use Getopt::Long;
use IO::CaptureOutput qw/capture_exec/;
my $timeout_cmd = '/usr/bin/timeout -s 9';
my $timeout_secs = 30;
GetOptions ("timeout|t=s" => \$timeout_secs);
# Capture df output
my @check = `$timeout_cmd $timeout_secs df -P 2>&1`;
my $result = $?;
# timeout on df - use strace to find the culprit
if ($result > 1) {
my $cmd = "$timeout_cmd $timeout_secs strace df -P";
my ($stdout, $stderr, $success, $exit_code) = capture_exec($cmd);
# strace output is in stderr - grab last line
my @straceline = split /\n/, $stderr;
my $mount = $straceline[-1];
# strace output should look like: statfs("/hosts/nfs7", <unfinished ...>
if ($mount =~ /^statfs/) {
$mount =~ s/.*\"(.*)\".*/$1/;
critical("Hung mount on $mount");
}
}
# Check for errors in df output
foreach my $line (@check) {
chomp $line;
# Ignore these: df: `/root/.gvfs': Permission denied
next if ($line =~ /Permission denied/);
# Case like: `/hosts/coffee/user_data2': Stale NFS file handle
$line =~ s/[`,']//g;
critical($line) if ($line =~ /^df: /);
}
print "OK\n";
exit 0;
sub critical {
my $msg = shift;
print "CRITICAL: $msg\n";
exit 2;
}