監控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
初來乍到~請多指教~~~