blob: 170fe45627f080d6f9a94c7a0d7da0b75729d0f5 (
plain)
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
#!/bin/sh
# File: /usr/lib64/nagios/plugins/check_apache_threads
# Author: bgstack15@gmail.com
# Startdate: 2017-01-09 15:53
# Title: Nagios Check for Apache Threads
# Purpose: For a troublesome dmz wordpress host
# Package: nagios-plugins-apache-threads
# History:
# Usage:
# In nagios/nconf, use this checkcommand check command line: $USER1$/check_by_ssh -H $HOSTADDRESS$ -C "$USER1$/check_apache_threads -w $ARG1$ -c $ARG2$"
# Reference: general design /usr/lib64/nagios/plugins/check_sensors
# general design http://www.kernel-panic.it/openbsd/nagios/nagios6.html
# case -w http://www.linuxquestions.org/questions/programming-9/ash-test-is-string-a-contained-in-string-b-671773/
# Improve:
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION="0.0.1"
. $PROGPATH/utils.sh
print_usage() {
cat <<EOF
Usage: $PROGNAME -w <thresh_warn> -c <thresh_crit>
EOF
}
print_help() {
print_revision $PROGNAME $REVISION
echo ""
print_usage
echo ""
echo "This plugin checks for the number of active apache threads."
echo ""
support
exit $STATE_OK
}
# MAIN
# Total httpd threads
tot_apache_threads="$( ps -ef | grep -ciE "httpd$" )"
verbosity=0
thresh_warn=
thresh_crit=
while test -n "${1}";
do
case "$1" in
--help|-h)
print_help
exit $STATE_OK
;;
--version|-V)
print_revision $PROGNAME $REVISION
exit $STATE_OK
;;
-v | --verbose)
verbosity=$(( verbosity + 1 ))
shift
;;
-w | --warning | -c | --critical)
if [[ -z "$2" || "$2" = -* ]];
then
# Threshold not provided
echo "$PROGNAME: Option '$1' requires an argument."
print_usage
exit $STATE_UNKNOWN
elif [[ "$2" = +([0-9]) ]];
then
# Threshold is a number
thresh="$2"
# use for a percentage template, from reference 2
#elif [[ "$2" = +([0-9])% ]]; then
# # Threshold is a percentage
# thresh=$(( tot_mem * ${2%\%} / 100 ))
else
# Threshold is not a number or other valid input
echo "$PROGNAME: Threshold must be an integer."
print_usage
exit $STATE_UNKNOWN
fi
case "$1" in *-w*) thresh_warn=$thresh;; *) thresh_crit=$thresh;; esac
shift 2
;;
-?)
print_usage
exit $STATE_OK
;;
*)
echo "$PROGNAME: Invalid option '$1'"
print_usage
exit $STATE_UNKNOWN
;;
esac
done
if test -z "$thresh_warn" || test -z "$thresh_crit";
then
# One or both values were unspecified
echo "$PROGNAME: Threshold not set"
print_usage
exit $STATE_UNKNOWN
elif test "$thresh_crit" -le "$thresh_warn";
then
echo "$PROGNAME: Critical value must be greater than warning value."
print_usage
exit $STATE_UNKNOWN
fi
if test "$verbosity" -ge 2;
then
# Print debugging information
/bin/cat <<EOF
Debugging information:
Warning threshold: $thresh_warn
Critical threshold: $thresh_crit
Verbosity level: $verbosity
Apache threads: ${tot_apache_threads}
EOF
fi
if test "${tot_apache_threads}" -gt "${thresh_crit}";
then
# too many apache threads
echo "APACHE CRITICAL - $tot_apache_threads"
exit $STATE_CRITICAL
elif test "${tot_apache_threads}" -gt "${thresh_warn}";
then
echo "APACHE WARNING - $tot_apache_threads"
exit $STATE_WARNING
else
# fine
echo "APACHE OK - $tot_apache_threads"
exit $STATE_OK
fi
|