- #monitor mysql service status and server load
-
#!/bin/bash
-
function Send_Email()
-
{
-
ADMIN="bruce.zuo@csoftintl.com"
-
MESSAGE_FILE="/tmp/monitor.log"
-
echo "VIP has been changed at `date`,please check it!Message:$1" > $MESSAGE_FILE
-
/bin/mail -s "VIP has been changed" $ADMIN < $MESSAGE_FILE
-
rm -r $MESSAGE_FILE
-
}
-
-
while true; do
-
sleep 1
-
CPU_NUMBER=`cat /proc/cpuinfo |grep processor |wc -l`
-
MAX_LOAD=`echo $CPU_NUMBER*2|bc`
-
KEEPALIVED_ALIVE=`ps aux |grep keepalived |grep -v "grep" |wc -l`
-
# some optional
-
# USER_NAME=$1
-
# PASSWORD=$2
-
# IS_SLAVE=$3
-
if [ `service mysql status |awk '{print $2}'` = 'running' ]
-
then
-
LOAD=`uptime`
-
LOAD=${LOAD##* }
-
# if [ `expr $LOAD \< $CPU_LOAD` = 1 ] # another method,compare integer and decimal
-
if [ `echo "$LOAD > $MAX_LOAD" | bc` = 1 ]
-
then
-
# echo "Average load is BUSY"
-
pkill keepalived # if load is greater than max load then kill keepalived,take VIP point to another server.
-
Send_Email "Mysql is alived,Average load is busy,so kill keepalived"
-
else
-
if [ `echo "$KEEPALIVED_ALIVE < 2 " | bc` = 1 ] # if keepalived is not running ,run it immediately.
-
then
-
keepalived -D
-
Send_Email "Mysql is alived,Average load is Free,Keepalived is not alived,so start keepalived"
-
fi
-
fi
-
elif [ `echo "$KEEPALIVED_ALIVE < 2 " | bc` = 0 ]
-
then
-
pkill keepalived # if mysql service is not running ,then kill keepalived,take VIP point to another server.
-
Send_Email "Mysql service is not alived,Keepalived is alived,so kill keepalived."
-
fi
-
done
-
exit 0
阅读(1405) | 评论(0) | 转发(0) |