Skip to content

Instantly share code, notes, and snippets.

@aabril
Created January 31, 2012 12:07
Show Gist options
  • Save aabril/1710181 to your computer and use it in GitHub Desktop.
Save aabril/1710181 to your computer and use it in GitHub Desktop.
Monitor and force mysql reload if it reaches 90 threads connections.
#!/bin/bash
LOGFILE="ping_mysql.log"
DBUSER="dummyuser"
DBPASS="dummypass"
DBHOST="localhost"
while :
do
mysqladmin ping -u $DBUSER -p $DBPASS -h $DBHOST >> $LOGFILE
mysqladmin status -u $DBUSER -p $DBPASS -h $DBHOST >> $LOGFILE
date >> $LOGFILE
if [ $(mysqladmin status -u $DBUSER -p $DBPASS -h localhost | awk 'BEGIN {FS=" "}{print $4}') -gt 90 ]
then echo "WARNING! MySQL server has reach 90 threads. Forcing reload." >> $LOGFILE
service mysql restart
fi
echo " " >> $LOGFILE
sleep 30
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment