模板如下
3.4 2018-11-30T08:28:28Z 自定义 Mysql-slave-info Mysql-slave-info 自定义 Mysql-Slave 读取错误数 0 slave_status[Last_Errno] 30s 7d 365d 0 3 0 0 0 0 0 Mysql-Slave 慢多少秒 0 slave_status[Seconds_Behind_Master] 30s 7d 365d 0 0 0 0 0 0 0 Mysql-Slave 跳过错误数 0 slave_status[Skip_Counter] 30s 7d 365d 0 3 0 0 0 0 0 Mysql-Slave IO线程状态 0 slave_status[Slave_IO_Running] 30s 7d 365d 0 3 0 0 0 0 0 Mysql-Slave sql线程状态 0 slave_status[Slave_SQL_Running] 30s 7d 365d 0 3 0 0 0 0 0 {Mysql-slave-info:slave_status[Slave_IO_Running].last()}=1 0 Mysql-Slave IO线程中断 0 0 3 0 0 {Mysql-slave-info:slave_status[Slave_SQL_Running].last()}=1 0 Mysql-Slave Sql线程中断 0 0 3 0 0 {Mysql-slave-info:slave_status[Seconds_Behind_Master].last()}>600 0 Mysql-Slave 慢超过600秒 0 0 3 0 0 {Mysql-slave-info:slave_status[Skip_Counter].last()}=1 0 Mysql-Slave 读取错误数超过0个 0 0 3 0 0 {Mysql-slave-info:slave_status[Skip_Counter].last()}=1 0 Mysql-Slave 跳过错误数超过0个 0 0 3 0 0
如果mysql是源码安装,而且是环境变量的mysql命令,需要将脚本里mysql写成绝对路径
#vim mysql-slave.sh
#!/bin/bash#监控mysql从状态脚本commnd() { /usr/local/mysql/bin/mysql -uroot -p'123456' -e "show slave status\G;" 2>/dev/null | grep -w $1 | awk -F': ' '{print $2}'}if [[ $1 == "Slave_IO_Running" ]];then a=`commnd Slave_IO_Running`#判断是否为Yes,如果是Yes,输出0,否则输出1,触发报警 [[ "$a" == "Yes" ]] && echo 0 || echo 1elif [[ $1 == "Slave_SQL_Running" ]];then a=`commnd Slave_SQL_Running` [[ "$a" == "Yes" ]] && echo 0 || echo 1elif [[ $1 == "Seconds_Behind_Master" ]];then a=`commnd Seconds_Behind_Master` b=`cat /tmp/sbm.tmp` if [[ $a -ge 600 ]] && [[ $b -ge 600 ]];then echo $a else echo 0 fi echo "$a" > /tmp/sbm.tmpelif [[ $1 == "Last_Errno" ]];then a=`commnd Last_Errno` [[ $a -eq 0 ]] && echo 0 || echo 1elif [[ $1 == "Skip_Counter" ]];then a=`commnd Skip_Counter` [[ $a -eq 0 ]] && echo 0 || echo 1else echo "Slave_IO_Running | Slave_SQL_Running | Seconds_Behind_Master | Last_Errno | Skip_Counter"fi
#vim zabbix.agent.conf
UserParameter=slave_status[*],/etc/zabbix/script/mysql-slave.sh $1
验证
# zabbix_get -s 10.0.0.52(监控的主机) -k'slave_status[Slave_IO_Running]'
web界面创建监控项
web界面创建触发值
依次创建监控项跟触发值
键值:
触发器:
图:为0则是正常的,Seconds_Behind_Master是延迟多少秒。超过600也就是10分钟会报警