shell脚本使用钉钉来进行mysql主从监控报警
相信很多朋友都有过mysql主从不同步的报警方案,比如短信,邮件,微信等等,今天我给大家一个用钉钉机器人来进行报警的方案.怎么申请钉钉机器人,我这里就不介绍了,大家自己网上搜下吧.先说下我的环境,因为我的mysql主从是在阿里云vpc内网里,没有公网ip,所以ssh远程连接到另外一台机子,用另外一台机子来发送报警信息.
系统:centos 7(64位)
1.监控脚本:
cat /root/soft_shell/check_slave.sh
02 | mysql_binfile=/usr/ local /mysql/bin/mysql |
05 | mysql_sockfile=/data/mysql/mysql.sock |
06 | slave_ip= "192.168.1.23x" |
07 | status=$($mysql_binfile -u$mysql_user -p$mysql_pass -S $mysql_sockfile -e "show slave status\G" | grep -i "running" ) |
08 | Slave_IO_Running=` echo $status | grep Slave_IO_Running | awk ' {print $2}' ` |
09 | Slave_SQL_Running=` echo $status | grep Slave_SQL_Running | awk '{print $2}' ` |
10 | REMARKFILE= '/tmp/monitor_load.remark' |
11 | DELMARKFILE= '/tmp/monitor_load.delmark' |
18 | if [ -f "$REMARKFILE" ] && [ -s "$REMARKFILE" ]; then |
19 | REMARK=$( cat $REMARKFILE) |
22 | if [ $(( $NOW - $REMARK )) - gt "$EXPIRE" ]; then |
30 | if [ -f "$DELMARKFILE" ] && [ -s "$DELMARKFILE" ]; then |
31 | DELMARK=$( cat $DELMARKFILE) |
34 | if [ $(( $NOW - $DELMARK )) - gt "$ENDTIME" ]; then |
42 | if [ "$REMARK" = "" ] ; then |
43 | if [ "$Slave_IO_Running" != "Yes" -a "$Slave_SQL_Running" != "Yes" ]; then |
44 | ssh -p 18330 root@192.168.1.24x "/root/soft_shell/send_message.sh" |
49 | if [ "$DELMARK" = "" ] ; then |
50 | if [ "$Slave_IO_Running" = "Yes" -a "$Slave_SQL_Running" = "Yes" ]; then |
51 | ssh -p 18330 root@192.168.1.24x "/root/soft_shell/restore_message.sh" |
57 | if [ "$ISSEND" = "1" ]; then |
58 | echo "$(date +%s)" > $REMARKFILE |
61 | if [ "$ASSEND" = "1" ]; then |
62 | echo "$(date +%s)" > $DELMARKFILE |
2.报警脚本
cat /root/soft_shell/send_message.sh
3 | datetime=` date + "%Y-%m-%d/%H:%M:%S" ` |
cat /root/soft_shell/restore_message.sh
3 | datetime=` date + "%Y-%m-%d/%H:%M:%S" ` |
好了,最后去钉钉里查看是否有收到报警短信.
标签: mysql shell 监控 报警 主从 钉钉
评论: