监控mysql html
Slave_IO_Running: mysql
Slave_SQL_Running:sql
状态,为NO 邮件报警shell
最近刚发现一个发邮件的工具,简单好用 sendEmail,免安装的 我的感受很是好用vim
参考:http://blog.chinaunix.net/uid-10697776-id-3185073.html bash
vim slave.shide
思路:工具
过滤Slave_IO_Running && Slave_SQL_Running的值。为No邮件报警,同时写入日志slave.log。。固然就得按期清空日志(我作的是每次查看日志的行数超过1152行,清空日志。同时判断日志中是否有Noui
字段,有则不执行清空操做,方便记录故障时间)spa
变量: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 xxx@163.com -t yyy@163.com -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 xxx@163.com -t xxx@163.com -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
初来乍到~请多指教~~~