结合我的另一篇zabbix自动发现Mysql并监控的博客使用最佳:
脚本很简单,一看就明白:
[[email protected] 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]
时间: 2024-11-19 23:22:51