forked from HariSekhon/Nagios-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_linux_system_file_descriptors.pl
executable file
·83 lines (67 loc) · 2.77 KB
/
check_linux_system_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl -T
# nagios: -epn
#
# Author: Hari Sekhon
# Date: 2012-12-03 11:02:52 +0000 (Mon, 03 Dec 2012)
#
# https://github.com/harisekhon/nagios-plugins
#
# License: see accompanying LICENSE file
#
$DESCRIPTION = "Nagios Plugin to check the Linux system file descriptors % used on the local system. Call remotely via NRPE.
See also check_ulimit.pl in the Advanced Nagios Plugins Collection";
$VERSION = "0.1";
use strict;
use warnings;
BEGIN {
use File::Basename;
use lib dirname(__FILE__) . "/lib";
}
use HariSekhonUtils;
set_threshold_defaults(70, 90);
%options = (
%thresholdoptions,
);
get_options();
validate_thresholds();
linux_only();
vlog2;
set_timeout();
# same as the 3rd number from file-nr
#my $fh = open_file "/proc/sys/fs/file-max";
#my $limit = <$fh>;
#isInt $limit or quit "UNKNOWN", "failed to get system file max";
#vlog2 "system file max: $limit";
# http://www.netadmintools.com/part295.html
# https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Tuning_and_Optimizing_Red_Hat_Enterprise_Linux_for_Oracle_9i_and_10g_Databases/chap-Oracle_9i_and_10g_Tuning_Guide-Setting_File_Handles.html
my $fh = open_file "/proc/sys/fs/file-nr";
vlog3 sprintf("\ncontents:\n\n%s\n", <$fh>);
seek($fh, 0, 0);
my ($allocated, $allocated_free, $limit) = split(/\s+/, <$fh>, 3);
isInt $allocated or quit "UNKNOWN", "failed to get system files allocated";
isInt $allocated_free or quit "UNKNOWN", "failed to get system files unallocated";
isInt $limit or quit "UNKNOWN", "failed to get system files limit";
($allocated < $allocated_free) and quit "UNKNOWN", "code or /proc error, system file allocated < allocated_free!";
# second field was used file handles in 2.4 kernels so need to check kernel version
# see also http://man7.org/linux/man-pages/man5/proc.5.html:
# /proc/sys/kernel/ostype => Linux
# /proc/sys/kernel/osrelease => 2.6.32-358.2.1.el6.x86_64
# /proc/sys/kernel/version => #1 SMP Wed Mar 13 00:26:49 UTC 2013
$fh = open_file "/proc/version";
<$fh> =~ /^Linux\s+version\s+(\d+\.\d+)\./ or quit "UNKNOWN", "failed to determine Linux kernel version to accurately calculate used file handles";
my $kernel_version = $1;
vlog2 "kernel version $kernel_version";
my $used;
if($kernel_version <= 2.4){
$used = $allocated_free;
} else {
$used = $allocated - $allocated_free;
}
vlog2 "system file descriptors used: $used";
vlog2 "system file descriptors limit: $limit";
$status = "OK";
my $percentage = sprintf("%.2f", $used / $limit * 100);
$msg = sprintf("%.2f%% system file descriptors used [%d/%d]", $percentage, $used, $limit);
check_thresholds($percentage);
$msg .= sprintf(" | 'system file descriptors %% used'=%.2f%%%s 'system file descriptors used'=%d", $percentage, msg_perf_thresholds(1), $used);
quit $status, $msg;