首页 技术 正文
技术 2022年11月8日
0 收藏 579 点赞 1,969 浏览 6871 个字

模板如下

<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界面创建监控项

ZABBIX监控mysql主从状态

web界面创建触发值

ZABBIX监控mysql主从状态

依次创建监控项跟触发值

键值:

ZABBIX监控mysql主从状态

触发器:

ZABBIX监控mysql主从状态

图:为0则是正常的,Seconds_Behind_Master是延迟多少秒。超过600也就是10分钟会报警

ZABBIX监控mysql主从状态

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,493
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295