[galera] Improve clustercheck script
This commit is contained in:
parent
4075c5f08b
commit
24bd6bc3d8
@ -4,35 +4,54 @@
|
||||
#
|
||||
# Script to make a proxy (ie HAProxy) capable of monitoring Percona XtraDB Cluster nodes properly
|
||||
#
|
||||
# Author: Olaf van Zandwijk olaf.vanzandwijk@nedap.com
|
||||
# Author: Olaf van Zandwijk <olaf.vanzandwijk@nedap.com>
|
||||
# Mehdi Abaakouk <mehdi.abaakouk@enovance.com>
|
||||
#
|
||||
# Documentation and download: https://github.com/olafz/percona-clustercheck
|
||||
#
|
||||
# Based on the original script from Unai Rodriguez
|
||||
#
|
||||
MYSQL_USERNAME='<%= @galera_clustercheck_dbuser %>'
|
||||
MYSQL_PASSWORD='<%= @galera_clustercheck_dbpassword %>'
|
||||
|
||||
MYSQL_USERNAME="<%= @galera_clustercheck_dbuser %>"
|
||||
MYSQL_PASSWORD="<%= @galera_clustercheck_dbpassword %>"
|
||||
TIMEOUT=10
|
||||
ERR_FILE="/dev/null"
|
||||
AVAILABLE_WHEN_DONOR=0
|
||||
|
||||
#
|
||||
# Perform the query to check the wsrep_local_state
|
||||
#
|
||||
WSREP_STATUS=`mysql --user=${MYSQL_USERNAME} --password=${MYSQL_PASSWORD} -e "SHOW STATUS LIKE 'wsrep_local_state';" 2>${ERR_FILE} | awk '{if (NR!=1){print $2}}' 2>${ERR_FILE}`
|
||||
MYSQL_CMDLINE="mysql -nNE --connect-timeout=$TIMEOUT --user=${MYSQL_USERNAME} --password=${MYSQL_PASSWORD} "
|
||||
|
||||
if [[ "${WSREP_STATUS}" == "4" ]] || [[ "${WSREP_STATUS}" == "2" && ${AVAILABLE_WHEN_DONOR} == 1 ]]
|
||||
then
|
||||
# Percona XtraDB Cluster node local state is 'Synced' == return HTTP 200
|
||||
/bin/echo -en "HTTP/1.1 200 OK\r\n"
|
||||
mysql_get_status(){
|
||||
( $MYSQL_CMDLINE -e "SHOW STATUS LIKE '$1';" | tail -1 ) 2>>${ERR_FILE}
|
||||
}
|
||||
mysql_get_var(){
|
||||
( $MYSQL_CMDLINE -e "SHOW GLOBAL VARIABLES LIKE '$1';" | tail -1 ) 2>>${ERR_FILE}
|
||||
}
|
||||
|
||||
http_response(){
|
||||
status=$1
|
||||
shift
|
||||
msg="$@"
|
||||
if [ "$status" == 200 ]; then
|
||||
/bin/echo -en "HTTP/1.1 200 OK\r\n"
|
||||
else
|
||||
/bin/echo -en "HTTP/1.1 503 Service Unavailable\r\n"
|
||||
fi
|
||||
/bin/echo -en "Content-Type: text/plain\r\n"
|
||||
/bin/echo -en "\r\n"
|
||||
/bin/echo -en "Mariadb Cluster Node is synced.\r\n"
|
||||
/bin/echo -en "$msg\r\n"
|
||||
/bin/echo -en "\r\n"
|
||||
else
|
||||
# Percona XtraDB Cluster node local state is not 'Synced' == return HTTP 503
|
||||
/bin/echo -en "HTTP/1.1 503 Service Unavailable\r\n"
|
||||
/bin/echo -en "Content-Type: text/plain\r\n"
|
||||
/bin/echo -en "\r\n"
|
||||
/bin/echo -en "Mariadb Cluster Node is not synced.\r\n"
|
||||
/bin/echo -en "\r\n"
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
WSREP_LOCAL_STATE=$(mysql_get_status wsrep_local_state)
|
||||
WSREP_READY=$(mysql_get_status wsrep_ready)
|
||||
WSREP_CONNECTED=$(mysql_get_status wsrep_connected)
|
||||
READY_ONLY=$(mysql_get_var read_only)
|
||||
|
||||
case ${AVAILABLE_WHEN_DONOR}-${WSREP_LOCAL_STATE}-${WSREP_READY}-${WSREP_CONNECTED}-${READY_ONLY} in
|
||||
1-2-ON-ON-OFF|0-4-ON-ON-OFF) http_response 200 "Mariadb Cluster Node is synced, ready and connected." ;;
|
||||
*-*-OFF-*-*) http_response 503 "Mariadb Cluster Node is not ready." ;;
|
||||
*-*-*-OFF-*) http_response 503 "Mariadb Cluster Node is not connected" ;;
|
||||
*-*-*-*-ON) http_response 503 "Mariadb Cluster Node is readonly" ;;
|
||||
*) http_response 503 "Mariadb Cluster Node is not synced" ;;
|
||||
esac
|
||||
|
Loading…
x
Reference in New Issue
Block a user