结合我的另一篇zabbix自动发现Mysql并监控的博客使用最佳:
脚本很简单,一看就明白:
[root@localhost files]# cat libexec/slave.sh #!/bin/bash ##slave.sh ##YES ---- 1 ##NO ---- 0 export MYSQL_PWD=xxxxxx xstats () { STATS=$(/usr/local/mysql/bin/mysql -h127.0.0.1 -uUser_name -P$1 -e "show slave status\G" | grep "\<$2\>" |awk ‘{print $2}‘) if [ "${STATS}" = "Yes" ]; then echo 1 else echo 0 fi } if [ "$2" != "Seconds_Behind_Master" ];then xstats $1 $2 else result=$(/usr/local/mysql/bin/mysql -h127.0.0.1 -umonitor -P$1 -e "show slave status\G" | grep "Seconds_Behind_Master" |awk ‘{print $NF}‘) echo $result fi
这样定义键值:
UserParameter=mysql_slave_status[*],/usr/local/zabbix/libexec/slave.sh $1 $2
模板里这样写:
mysql_slave_status[{#MYSQLPORT},Seconds_Behind_Master] mysql_slave_status[{#MYSQLPORT},Slave_IO_Running] mysql_slave_status[{#MYSQLPORT},Slave_SQL_Running]
本文出自 “铜锣湾” 博客,请务必保留此出处http://wuhf2015.blog.51cto.com/8213008/1783782
原文地址:http://wuhf2015.blog.51cto.com/8213008/1783782