mysql 从库状态监控shell

监控mysql 

Slave_IO_Running: 

Slave_SQL_Running:

状态,为NO 邮件报警

最近刚发现一个发邮件的工具,简单好用 sendEmail,免安装的 个人感觉非常好用

参考:http://blog.chinaunix.net/uid-10697776-id-3185073.html

vim slave.sh

思路:

过滤Slave_IO_Running && Slave_SQL_Running的值。为No邮件报警,同时写入日志slave.log。。当然就得定期清空日志(我做的是每次查看日志的行数超过1152行,清空日志。同时判断日志中是否有No

字段,有则不执行清空操作,方便记录故障时间)

变量:TEST_TIME=记录时间

      SLAVE_IO=Slave_IO_Running:的状态

      SLAVE_SQL=Slave_SQL_Running:的状态

相关:mysql -uuser -h ip -ppasswd -e "命令"(不登陆mysql执行mysql命令)


#!/bin/bash
TEST_TIME=`date -d today +"%Y%m%d--%H:%M:%S"`
SLAVE_IO=`/usr/local/bin/mysql -uroot -h 127.0.0.1  -e "show slave status\G;"|grep Slave_IO_Running|awk '{print $2}'`
SLAVE_SQL=`/usr/local/bin/mysql -uroot -h 127.0.0.1  -e "show slave status\G;"|grep Slave_SQL_Running|sed -n '1p'|awk '{print $2}'`
CAT_LOG=`cat /tmp/shell/slave/slave.log|wc -l`
if [ ${SLAVE_IO} = Yes ];
 then
        echo "Slave_IO_Running: Yes"${TEST_TIME} >> /tmp/shell/slave/slave.log
 else
        echo "Slave_IO_Running: No"${TEST_TIME} >> /tmp/shell/slave/slave.log
        /usr/local/sendEmail/sendEmail-v1.56/sendEmail -f [email protected] -t [email protected] -xp xxx -s smtp.163.com -xu xxx -u test -m Slave_IO
_Running: No__${TEST_TIME}
fi
###
if [ ${SLAVE_SQL} = Yes ];
 then
        echo "Slave_SQL_Running: Yes"${TEST_TIME} >> /tmp/shell/slave/slave.log
 else
        echo "Slave_SQL_Running: No"${TEST_TIME} >> /tmp/shell/slave/slave.log
        /usr/local/sendEmail/sendEmail-v1.56/sendEmail -f [email protected] -t [email protected] -xp xxx -s smtp.163.com -xu xxx -u test -m Slave_SQ
L_Running: No__${TEST_TIME}
fi
###
cat /tmp/shell/slave/slave.log|grep No
if [ $? != 0 ];
 then
#       echo $?
   if [ ${CAT_LOG} -gt 1152 ];
        then
        echo "" > /tmp/shell/slave/slave.log
   fi
fi

初来乍到~请多指教~~~

你可能感兴趣的:(mysql,slave,状态监控)