zabbix监控mysql主从同步可用性

 

[test@test-cratedb-4nqdg11-prd zabbix_agentd.d]$ more mysql.conf 
UserParameter=check_sync_available,sh /etc/zabbix/scripts/check_sync_available.sh

 

[root@dev-env23 scripts]# more check_sync_available.sh
#!/bin/bash
check_time=`date "+%Y-%m-%d,%H:%M:%S"`
mysql -h 192.168.1.197 -urepl -pmysql -P13306 -e 'show slave status\G'>/tmp/slave_197_13306.txt 2>&1

slave_io_running=`cat /tmp/slave_197_13306.txt|grep Slave_IO_Running|sed s/[[:space:]]//g|cut -d ':' -f2`
slave_sql_running=`cat /tmp/slave_197_13306.txt|grep Slave_SQL_Running|grep -v Slave_SQL_Running_State|sed s/[[:space:]]//g|cut -d ':' -f2`
##slave_io_running=bb
##slave_sql_running=aa

if [ "$slave_io_running" == "Yes" ] && [ "$slave_sql_running" == "Yes" ]; then
   echo "ok"
else
   echo "failed"
fi

 

posted @ 2021-05-14 09:11  slnngk  阅读(80)  评论(0编辑  收藏  举报