-
Notifications
You must be signed in to change notification settings - Fork 4
/
check_ndb_usage.sh
executable file
·133 lines (116 loc) · 3.17 KB
/
check_ndb_usage.sh
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
#!/bin/bash
NDB_MGM=$(which ndb_mgm)
function printHelp() {
cat >&2 <<EOF
$@
Usage: $(basename $0)
--warning|-w Used memory warning threshhold
--critical|-c used memory critical threshold
--node-id|-n Specify which node you want to monitor
EOF
exit 3
}
# main starts here
while [ $# -gt 0 ]
do
case "$1" in
--warning|-w) WARN="$2"; shift 2;;
--critical|-c) CRIT="$2"; shift 2;;
--node-id|-n) NODE="$2"; shift 2;;
*) printHelp "Missing parameter" ;;
esac
done
test -z ${NDB_MGM} && { echo "Cannot find the ndb_mgm executable. Aborting."; exit 3; }
test -x ${NDB_MGM} || { echo "Cannot execute ndb_mgm. Aborting."; exit 3; }
if [ -z "${WARN}" ];
then
printHelp "Please specify a warning threshold"
fi
if [ -z "${CRIT}" ];
then
printHelp "Please specify a critical threshold"
fi
if [ -z "${NODE}" ];
then
printHelp "Please specify a node ID"
fi
${NDB_MGM} -e "${NODE} status"|grep -i "not connected" > /dev/null
if [ $? -eq 0 ]; then
# data node offline
echo "Data: CRITICAL node: ${NODE} is OFFLINE"
exit 2
fi
${NDB_MGM} -e "${NODE} status"|grep -i "starting" > /dev/null
if [ $? -eq 0 ]; then
# data node starting
echo "Data: WARNING node: ${NODE} is STARTING"
exit 2
fi
DATA=$(${NDB_MGM} -e "${NODE} report memory"|grep "Data usage is"|awk '{print $6}'|awk -F "%" "{ if (\$1 > ${CRIT}) {
exit 2
} else if (\$1 > ${WARN}) {
exit 1
}
} END { print \$1 }")
RET=$?
# checking index usage
# IF ... critical .. ELSE IF .. warning
IDX=$(${NDB_MGM} -e "${NODE} report memory"|grep "Index usage is"|awk '{print $6}'|awk -F "%" "{ if (\$1 > ${CRIT}) {
exit 8
} else if (\$1 > ${WARN}) {
exit 4
}
} END { print \$1 }")
((RET+=$?))
case ${RET} in
0)
# everything OK
echo "Data: OK (${DATA}%) Index: OK (${IDX}%)"
exit 0
;;
1)
# data usage warning
echo "Data: WARNING (${DATA}%) Index: OK (${IDX}%)"
exit 1
;;
2)
# data usage critical
echo "Data: CRITICAL (${DATA}%) Index: OK (${IDX}%)"
exit 2
;;
4)
# index usage warning
echo "Data: OK (${DATA}%) Index: WARNING (${IDX}%)"
exit 1
;;
5)
# data usage warning + index usage warning
echo "Data: WARNING (${DATA}%) Index: WARNING (${IDX}%)"
exit 1
;;
6)
# data usage critical + index usage warning
echo "Data: CRITICAL (${DATA}%) Index: WARNING (${IDX}%)"
exit 2
;;
8)
# index usage critical
echo "Data: OK (${DATA}%) Index: CRITICA (${IDX}%)"
exit 2
;;
9)
# data usage warning + index usage critical
echo "Data: WARNING (${DATA}%) Index: CRITICAL (${IDX}%)"
exit 2
;;
10)
# data usage critical + index usage critical
echo "Data: CRITICAL (${DATA}%) Index: CRITICAL (${IDX}%)"
exit 2
;;
*)
# unexpected condition
echo "Unknown error"
exit 3
;;
esac