Created
January 23, 2015 17:41
-
-
Save erincerys/48dd2d5cb91d5454ffd4 to your computer and use it in GitHub Desktop.
A shell script to monitor a MySQL replication connection.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Monitor and report a status code somewhere about a MySQL slave's replication connection | |
# Useful for when traditional monitoring cannot be achieved due to firewalling. | |
D=`date -u +"%Y%m%d%H%M"` | |
mysqlparams='-h... -ureplicator -p...' | |
query='show slave status\G' | |
logfile='/var/log/replication_check.log' | |
io_thread=$(mysql $mysqlparams -e "${query}" | grep -iE 'io_running\:' | awk '{print $2}') | |
sql_thread=$(mysql $mysqlparams -e "${query}" | grep -iE 'sql_running\:' | awk '{print $2}') | |
if [[ "${io_thread}" == 'No' || "${sql_thread}" == 'No' ]] ; then | |
if [[ "${io_thread}" == 'No' && "${sql_thread}" == 'No' ]] ; then | |
postcode=400 | |
postmsg='Replication%20has%20stopped!' | |
elif [[ "${io_thread}" == 'Yes' && "${sql_thread}" == 'No' ]] ; then | |
postcode=300 | |
postmsg='Replication%20has%20stalled' | |
fi | |
slave_error=$(mysql $mysqlparams -e "${query}" | grep -iE 'last_error\:' | awk '{print $2}') | |
echo '[${D}] $postmsg -- $slave_error' >> $logfile | |
else | |
postcode=200 | |
postmsg='Replicating%20OK' | |
fi | |
# Custom monitoring reporting logic goes here |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment