forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check_file_descriptors.pl
executable file
·57 lines (44 loc) · 1.94 KB
/
check_file_descriptors.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
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2010-10-28 13:48:49 +0100 (Thu, 28 Aug 2010)
#
# http://github.com/harisekhon/nagios-plugins
#
# License: see accompanying LICENSE file
#
$DESCRIPTION = "Nagios Plugin to count the number of total allocated file descriptors on a system. Designed to be called over NRPE";
$VERSION = 0.3;
use strict;
use warnings;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
my $procfile = "/proc/sys/fs/file-nr";
my $process;
%options = (
"w|warning=s" => [ \$warning, "Warning threshold or ran:ge (inclusive)" ],
"c|critical=s" => [ \$critical, "Critical threshold or ran:ge (inclusive)" ],
);
get_options();
validate_thresholds(1,1);
vlog2;
linux_only();
set_timeout();
my $fh = open_file $procfile;;
my ($file_descriptors_allocated, $file_descriptors_free, $max_file_descriptors) = split(/\s+/,<$fh>);
close $fh;
vlog2 "\nfile descriptors allocated = $file_descriptors_allocated";
vlog2 "file descriptors free = $file_descriptors_free";
vlog2 "file descriptors max = $max_file_descriptors\n";
isInt($file_descriptors_allocated) or quit "UNKNOWN", "failed to retrieve number of file descriptors, non-numeric value found for file_descriptors_allocated";
isInt($file_descriptors_free) or quit "UNKNOWN", "failed to retrieve number of file descriptors, non-numeric value found for file_descriptors_free";
isInt($max_file_descriptors) or quit "UNKNOWN", "failed to retrieve number of file descriptors, non-numeric value found for max_file_descriptors";
$status = "OK";
$msg = "$file_descriptors_allocated file descriptors allocated, $file_descriptors_free free, $max_file_descriptors max";
check_thresholds($file_descriptors_allocated);
$msg .= " | 'File Descriptors Allocated'=$file_descriptors_allocated;$warning;$critical 'File Descriptors Free'=$file_descriptors_free 'File Descriptors Maximum'=$max_file_descriptors";
quit $status, $msg;