10802af0c4
* wsrep_ready (ON)
* wsrep_connected (ON)
* wsrep_local_state_comment (Synced)
Also add --batch and --skip-column-names to mysql command (get rid
of grep)
160 lines
3.6 KiB
Bash
Executable File
160 lines
3.6 KiB
Bash
Executable File
#!/bin/bash
|
|
PROGNAME=`basename $0`
|
|
VERSION="Version 1.0,"
|
|
AUTHOR="Guillaume Coré <g@fridim.org>"
|
|
|
|
ST_OK=0
|
|
ST_WR=1
|
|
ST_CR=2
|
|
ST_UK=3
|
|
|
|
print_version() {
|
|
echo "$VERSION $AUTHOR"
|
|
}
|
|
|
|
print_help() {
|
|
print_version $PROGNAME $VERSION
|
|
echo ""
|
|
echo "$PROGNAME is a Nagios plugin to monitor Galera cluster status."
|
|
echo ""
|
|
echo "$PROGNAME -u USER -p PASSWORD [-H HOST] [-P PORT] [-w SIZE] [-c SIZE] [-f FLOAT] [-0]"
|
|
echo ""
|
|
echo "Options:"
|
|
echo " u)"
|
|
echo " MySQL user."
|
|
echo " p)"
|
|
echo " MySQL password."
|
|
echo " H)"
|
|
echo " MySQL host. Default is localhost."
|
|
echo " P)"
|
|
echo " MySQL port. Default is 3306."
|
|
echo " w)"
|
|
echo " Sets minimum number of nodes in the cluster when WARNING is raised. (default is same as critical)."
|
|
echo " c)"
|
|
echo " Sets minimum number of nodes in the cluster when CRITICAL is raised. (default is 2)."
|
|
echo " f)"
|
|
echo " Sets critical value of wsrep_flow_control_paused (default is 0.1)."
|
|
echo " 0)"
|
|
echo " Rise CRITICAL if the node is not primary"
|
|
exit $ST_UK
|
|
}
|
|
|
|
# default values
|
|
crit=2
|
|
port='3306'
|
|
mysqlhost='localhost'
|
|
fcp=0.1
|
|
|
|
while getopts “hvu:p:H:P:w:c:f:0” OPTION; do
|
|
case $OPTION in
|
|
h)
|
|
print_help
|
|
exit $ST_UK
|
|
;;
|
|
v)
|
|
print_version $PROGNAME $VERSION
|
|
exit $ST_UK
|
|
;;
|
|
u)
|
|
mysqluser=$OPTARG
|
|
;;
|
|
p)
|
|
password=$OPTARG
|
|
;;
|
|
H)
|
|
mysqlhost=$OPTARG
|
|
;;
|
|
P)
|
|
port=$OPTARG
|
|
;;
|
|
w)
|
|
warn=$OPTARG
|
|
;;
|
|
c)
|
|
crit=$OPTARG
|
|
;;
|
|
f)
|
|
fcp=$OPTARG
|
|
;;
|
|
0)
|
|
primary='TRUE'
|
|
;;
|
|
?)
|
|
echo "Unknown argument: $1"
|
|
print_help
|
|
exit $ST_UK
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ -z "$warn" ]; then
|
|
warn=$crit
|
|
fi
|
|
|
|
# MANDATORY args
|
|
if [ -z "$mysqluser" ]; then
|
|
echo "argument -u missing"
|
|
print_help
|
|
exit $ST_UK
|
|
fi
|
|
|
|
if [ -z "$password" ]; then
|
|
echo "argument -p missing"
|
|
print_help
|
|
exit $ST_UK
|
|
fi
|
|
|
|
r1=$(mysql -h$mysqlhost -P$port -u$mysqluser -p$password -B -N -e "show status like 'wsrep_cluster_size'"|cut -f 2) # 3 (GALERA_CLUSTER_SIZE)
|
|
r2=$(mysql -h$mysqlhost -P$port -u$mysqluser -p$password -B -N -e "show status like 'wsrep_cluster_status'"|cut -f 2) # Primary
|
|
r3=$(mysql -h$mysqlhost -P$port -u$mysqluser -p$password -B -N -e "show status like 'wsrep_flow_control_paused'"|cut -f 2) # < 0.1
|
|
r4=$(mysql -h$mysqlhost -P$port -u$mysqluser -p$password -B -N -e "show status like 'wsrep_ready'"|cut -f 2) # ON
|
|
r5=$(mysql -h$mysqlhost -P$port -u$mysqluser -p$password -B -N -e "show status like 'wsrep_connected'"|cut -f 2) # ON
|
|
r6=$(mysql -h$mysqlhost -P$port -u$mysqluser -p$password -B -N -e "show status like 'wsrep_local_state_comment'"|cut -f 2) # Synced
|
|
|
|
if [ -z "$r3" ]; then
|
|
echo "UNKNOWN: wsrep_flow_control_paused is empty"
|
|
ST_FINAL=$ST_UK
|
|
fi
|
|
|
|
if [ $(echo "$r3 > $fcp" | bc) = 1 ]; then
|
|
echo "CRITICAL: wsrep_flow_control_paused is > $fcp"
|
|
ST_FINAL=$ST_CR
|
|
fi
|
|
|
|
if [ "$primary" = 'TRUE' ]; then
|
|
if [ "$r2" != 'Primary' ]; then
|
|
echo "CRITICAL: node is not primary"
|
|
ST_FINAL=$ST_CR
|
|
fi
|
|
fi
|
|
|
|
if [ "$r4" != 'ON' ]; then
|
|
echo "CRITICAL: node is not ready"
|
|
ST_FINAL=$ST_CR
|
|
fi
|
|
|
|
if [ "$r5" != 'ON' ]; then
|
|
echo "CRITICAL: node is not connected"
|
|
ST_FINAL=$ST_CR
|
|
fi
|
|
|
|
if [ "$r6" != 'Synced' ]; then
|
|
echo "CRITICAL: node is not synced"
|
|
ST_FINAL=$ST_CR
|
|
fi
|
|
|
|
if [ $r1 -gt $warn ]; then
|
|
echo "OK: number of NODES = $r1"
|
|
ST_FINAL=${ST_FINAL-$ST_OK}
|
|
elif [ $r1 -le $crit ]; then
|
|
echo "CRITICAL: number of NODES = $r1"
|
|
ST_FINAL=$ST_CR
|
|
elif [ $r1 -le $warn ]; then
|
|
echo "WARNING: number of NODES = $r1"
|
|
ST_FINAL=${ST_FINAL-$ST_WR}
|
|
else
|
|
exit $ST_UK
|
|
fi
|
|
|
|
exit $ST_FINAL
|