模板如下

<zabbix_export>
<version>3.4</version>
<date>2018-11-30T08:28:28Z</date>
<groups>
<group>
<name>自定义</name>
</group>
</groups>
<templates>
<template>
<template>Mysql-slave-info</template>
<name>Mysql-slave-info</name>
<description/>
<groups>
<group>
<name>自定义</name>
</group>
</groups>
<applications/>
<items>
<item>
<name>Mysql-Slave 读取错误数</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>slave_status[Last_Errno]</key>
<delay>30s</delay>
<history>7d</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications/>
<valuemap/>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<master_item/>
</item>
<item>
<name>Mysql-Slave 慢多少秒</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>slave_status[Seconds_Behind_Master]</key>
<delay>30s</delay>
<history>7d</history>
<trends>365d</trends>
<status>0</status>
<value_type>0</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications/>
<valuemap/>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<master_item/>
</item>
<item>
<name>Mysql-Slave 跳过错误数</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>slave_status[Skip_Counter]</key>
<delay>30s</delay>
<history>7d</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications/>
<valuemap/>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<master_item/>
</item>
<item>
<name>Mysql-Slave IO线程状态</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>slave_status[Slave_IO_Running]</key>
<delay>30s</delay>
<history>7d</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications/>
<valuemap/>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<master_item/>
</item>
<item>
<name>Mysql-Slave sql线程状态</name>
<type>0</type>
<snmp_community/>
<snmp_oid/>
<key>slave_status[Slave_SQL_Running]</key>
<delay>30s</delay>
<history>7d</history>
<trends>365d</trends>
<status>0</status>
<value_type>3</value_type>
<allowed_hosts/>
<units/>
<snmpv3_contextname/>
<snmpv3_securityname/>
<snmpv3_securitylevel>0</snmpv3_securitylevel>
<snmpv3_authprotocol>0</snmpv3_authprotocol>
<snmpv3_authpassphrase/>
<snmpv3_privprotocol>0</snmpv3_privprotocol>
<snmpv3_privpassphrase/>
<params/>
<ipmi_sensor/>
<authtype>0</authtype>
<username/>
<password/>
<publickey/>
<privatekey/>
<port/>
<description/>
<inventory_link>0</inventory_link>
<applications/>
<valuemap/>
<logtimefmt/>
<preprocessing/>
<jmx_endpoint/>
<master_item/>
</item>
</items>
<discovery_rules/>
<httptests/>
<macros/>
<templates/>
<screens/>
</template>
</templates>
<triggers>
<trigger>
<expression>
{Mysql-slave-info:slave_status[Slave_IO_Running].last()}=1
</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name>Mysql-Slave IO线程中断</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>3</priority>
<description/>
<type>0</type>
<manual_close>0</manual_close>
<dependencies/>
<tags/>
</trigger>
<trigger>
<expression>
{Mysql-slave-info:slave_status[Slave_SQL_Running].last()}=1
</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name>Mysql-Slave Sql线程中断</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>3</priority>
<description/>
<type>0</type>
<manual_close>0</manual_close>
<dependencies/>
<tags/>
</trigger>
<trigger>
<expression>
{Mysql-slave-info:slave_status[Seconds_Behind_Master].last()}>600
</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name>Mysql-Slave 慢超过600秒</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>3</priority>
<description/>
<type>0</type>
<manual_close>0</manual_close>
<dependencies/>
<tags/>
</trigger>
<trigger>
<expression>
{Mysql-slave-info:slave_status[Skip_Counter].last()}=1
</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name>Mysql-Slave 读取错误数超过0个</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>3</priority>
<description/>
<type>0</type>
<manual_close>0</manual_close>
<dependencies/>
<tags/>
</trigger>
<trigger>
<expression>
{Mysql-slave-info:slave_status[Skip_Counter].last()}=1
</expression>
<recovery_mode>0</recovery_mode>
<recovery_expression/>
<name>Mysql-Slave 跳过错误数超过0个</name>
<correlation_mode>0</correlation_mode>
<correlation_tag/>
<url/>
<status>0</status>
<priority>3</priority>
<description/>
<type>0</type>
<manual_close>0</manual_close>
<dependencies/>
<tags/>
</trigger>
</triggers>
</zabbix_export>

如果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 1
elif [[ $1 == "Slave_SQL_Running" ]];then
a=`commnd Slave_SQL_Running`
[[ "$a" == "Yes" ]] && echo 0 || echo 1
elif [[ $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.tmp
elif [[ $1 == "Last_Errno" ]];then
a=`commnd Last_Errno`
[[ $a -eq 0 ]] && echo 0 || echo 1
elif [[ $1 == "Skip_Counter" ]];then
a=`commnd Skip_Counter`
[[ $a -eq 0 ]] && echo 0 || echo 1
else
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分钟会报警

最新文章

  1. *HDU1969 二分
  2. php 读取文件
  3. bug--常见的bug总结:
  4. 搭建调用 WebService 的 ASP.NET 网站 (VS2010, C#)
  5. 《Visual C++并行编程实战》译者序
  6. 从nib文件里加载collectionViewCell
  7. django-cms 代码研究(四)CMS_TEMPLATE标签
  8. Who&#39;s in the Middle 分类: POJ 2015-06-12 19:45 11人阅读 评论(0) 收藏
  9. hdu1023:卡特兰数
  10. js获取Session的值
  11. photoshop 修改pdf文件并保存为pdf
  12. effective java——32用EnumSet代替位域
  13. mysql避免数据库误操作小技巧(转)
  14. Object.defineProperty(o,p,descriptor ) 理解应用
  15. Go语言规格说明书 之 通道类型(Channel types)
  16. MySQL触发器详解
  17. angularJS 事件广播与接收
  18. Mahout源码目录说明&amp;&amp;算法集
  19. tools-eclipse-002-常用插件
  20. Tkinter Menu(菜单)

热门文章

  1. exec族函数详解及循环创建子进程
  2. 如何定制Linux外围文件系统?
  3. Python机器学习笔记 异常点检测算法——Isolation Forest
  4. 痞子衡嵌入式:常用的数据差错控制技术(2)- 奇偶校验(Parity Check)
  5. C#实现以太仿DApp合约编译、部署
  6. Chrome F12调试工具常用技巧
  7. 基于C#&amp;.net2.0的windows服务创建与安装
  8. MySQL5.7开多实例指导
  9. H5页面的高度宽度100%
  10. nth-child(n)和nth-of-type(n)的区别