-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_mysql_threads.sh
71 lines (63 loc) · 1.97 KB
/
check_mysql_threads.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
#!/bin/bash
mysqlhost='localhost'
port=3306
mysqluser=$(grep user /root/.my.cnf|cut -f2 -d '=')
password=$(grep password /root/.my.cnf|cut -f2 -d '=')
ST_OK=0
ST_WR=1
ST_CR=2
ST_UK=3
while getopts “hvu:p:H:P:w:c:f:0” OPTION; do
case $OPTION in
w)
warn=$OPTARG
;;
c)
crit=$OPTARG
;;
?)
echo "Unknown argument: $1"
exit $ST_UK
;;
esac
done
r1=$(mysql -h$mysqlhost -P$port -u$mysqluser -p$password -B -N -e "show status like 'Threads_connected'"|cut -f 2)
r2=$(mysql -h$mysqlhost -P$port -u$mysqluser -p$password -B -N -e "show status like 'Max_used_connections'"|cut -f 2)
if [ $r1 -le $warn ]; then
ST_FINAL=${ST_FINAL-$ST_OK}
ST_TEXT='OK'
# echo "$ST_FINAL mysql_galera_threads - OK - number of threads = $r1"
elif [ $r1 -gt $crit ]; then
ST_FINAL=$ST_CR
ST_TEXT='CRITICAL'
# echo "$ST_FINAL mysql_galera_threads - CRITICAL - number of threads = $r1"
elif [ $r1 -gt $warn ]; then
ST_FINAL=${ST_FINAL-$ST_WR}
ST_TEXT='WARNING'
# echo "$ST_FINAL mysql_galera_threads - WARNING - number of threads = $r1"
else
ST_FINAL=${ST_FINAL-$ST_UK}
ST_TEXT='UNKNOWN'
# echo "$ST_FINAL mysql_galera_threads - UNKNOWN - $ST_UK"
fi
if [ $r2 -le $warn ]; then
ST2_FINAL=${ST2_FINAL-$ST_OK}
ST2_TEXT='OK'
# echo "$ST_FINAL mysql_galera_threads - OK - number of threads = $r1"
elif [ $r2 -gt $crit ]; then
ST2_FINAL=$ST_CR
ST2_TEXT='CRITICAL'
# echo "$ST_FINAL mysql_galera_threads - CRITICAL - number of threads = $r1"
elif [ $r2 -gt $warn ]; then
ST2_FINAL=${ST2_FINAL-$ST_WR}
ST2_TEXT='WARNING'
# echo "$ST_FINAL mysql_galera_threads - WARNING - number of threads = $r1"
else
ST2_FINAL=${ST2_FINAL-$ST_UK}
ST2_TEXT='UNKNOWN'
# echo "$ST_FINAL mysql_galera_threads - UNKNOWN - $ST_UK"
fi
echo "$ST_FINAL mysql_threads - $ST_TEXT number of threads = $r1 |threads=$r1;$warn;$crit"
# not really ready yet
#echo "$ST2_FINAL mysql_max_threads - $ST2_TEXT max number of threads = $r2 |threads=$r2;$warn;$crit"
exit $ST_FINAL