This repository was archived by the owner on Jun 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathcheck_haproxy_queue
More file actions
executable file
·90 lines (79 loc) · 2.31 KB
/
Copy pathcheck_haproxy_queue
File metadata and controls
executable file
·90 lines (79 loc) · 2.31 KB
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
#!/bin/bash
# ========================================================================================
# HAProxy nagios check of current queue depth.
#
# 2013 Wanelo Inc, Apache License.
#
# Usage: ./check_haproxy_queue [-s stats_socket] [-b backend ]
# [-w <warn_cnt>] [-c <critical_cnt>]
# -b --backend name of backend to watch (ie "app_servers")
# -s --stats_socket location of haproxy stats socket (default /var/run/haproxy.sock)
# -w --warning warning threshold (default 100)
# -c --critical critical threshold (default 500)
# ========================================================================================
# Nagios return codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
QUEUE=0
NODENAME=`cat /etc/nodename`
STATS_SOCKET=/var/run/haproxy.sock
# set thresholds in bytes
WARNING_THRESHOLD=100
CRITICAL_THRESHOLD=500
# Parse parameters
while [ $# -gt 0 ]; do
case "$1" in
-b | --backend)
shift
BACKEND=$1
;;
-s | --stats_socket)
shift
STATS_SOCKET=$1
;;
-w | --warning)
shift
WARNING_THRESHOLD=$1
;;
-c | --critical)
shift
CRITICAL_THRESHOLD=$1
;;
*) echo "Unknown argument: $1"
exit $STATE_UNKNOWN
;;
esac
shift
done
function result {
DESCRIPTION=$1
STATUS=$2
if [ -z "$MESSAGE" ]; then
MESSAGE="current queue size is $QUEUE"
fi
echo "QUEUE $DESCRIPTION : ${NODENAME} $MESSAGE|queue=${QUEUE};${WARNING_THRESHOLD};${CRITICAL_THRESHOLD}"
exit $STATUS
}
function exit_on_error {
if [ $1 -ne 0 ]; then
MESSAGE=$2
result "CRITICAL" $STATE_CRITICAL
fi
}
if [ -z "$BACKEND" ]; then
MESSAGE="missing backend parameter"
result "CRITICAL" $STATE_CRITICAL
fi
STATS=`echo "show stat -1 2 -1" | nc -U $STATS_SOCKET | grep $BACKEND`
exit_on_error $? "error checking stats socket"
QUEUE=`echo $STATS | cut -d',' -f3`
# Output response
if [ $QUEUE -ge $WARNING_THRESHOLD ] && [ $QUEUE -lt $CRITICAL_THRESHOLD ]; then
result "WARNING" $STATE_WARNING
elif [ $QUEUE -ge $CRITICAL_THRESHOLD ]; then
result "CRITICAL" $STATE_CRITICAL
else
result "OK" $STATE_OK
fi