当前位置:网站首页>zabbix怎样自定义mysql监控项并触发告警
zabbix怎样自定义mysql监控项并触发告警
2022-07-22 10:03:00 【雅冰石】
比如我想实现,假如有元数据锁Waiting for table metadata lock,则触发告警。
1 编写监控脚本
cd /opt/zabbix/scripts/
vi get_metalock.sh
添加如下内容:
#!/bin/bash
rm -rf /opt/zabbix/scripts/get_metalock.log
mysql -uMonitorUser -p密码 -e "
SELECT * FROM information_schema.processlist WHERE state='Waiting for table metadata lock';
quit" >> /opt/zabbix/scripts/get_metalock.log
v1=`cat /opt/zabbix/scripts/get_metalock.log |wc -l`
if [ $v1 -eq 0 ];then
echo 0
else
echo 1
fi
#给脚本授权
chmod 755 /opt/zabbix/scripts/get_metalock.sh
2 创建配置文件
在/opt/zabbix/etc/zabbix_agentd.conf里定义的Include路径下创建配置文件。
示例:
Include=/opt/zabbix/etc/zabbix_agentd.conf.d/*.conf
则,
cd /opt/zabbix/etc/zabbix_agentd.conf.d/
新建一个以userparameter开头的,名字自定义的配置文件,示例:
vi userparameter_get_metalock.conf
添加如下内容:
UserParameter=get_metalock,sh /opt/zabbix/scripts/get_metalock.sh
#重启zabbix agent
systemctl restart zabbix_agentd
3 添加监控项
在现有mysql模板里创建监控项
配置-模板-监控项-创建监控项
键值和配置文件里定义的保持一致(UserParameter=后面的值)。
4 创建触发器
选择刚建的监控项:
这里设置last结果=1:
最终,自动生成如下结果:
自定义‘严重性’:
边栏推荐
- Data Lake (18): Flink and iceberg integrate SQL API operations
- Preface of daily column
- mysql 将毫秒数转为时间字符串
- 派生类的定义
- “先导杯”来啦!召唤科学计算界的最强大脑,36万奖池等你来拿
- Sentry nodestore_node 表中的数据查看
- Definition of derived classes
- The strongest screen tool sharex v14.0.1
- Constructeurs et destructeurs de classes dérivées
- Pytest interface automated testing framework | pytest parameterization
猜你喜欢
随机推荐
C# winform excel根据当前选中内容,自动插入/编辑批注
SQL Design Teaching Management Library
Explain the adapter technology in NLP from simple to deep
Friend functions and friend classes
PHP curl 请求中设置 proxy 方法
NIOFiles工具类
Force deduction solution summary 676- realize a magic dictionary
7.17 minimum ticket price
CCF 1-2题答题记录(1)
字节码技术在动态代理中的实现探讨
Pytest interface automated testing framework | why do you want to do the secondary development of pytest plug-ins
Leetcode notes
索引为什么选择B+树
每日一题专栏前言
国产立体声音频数模D/A转换器DP4344替代兼容CS4344
由浅入深详解NLP中的Adapter技术
[Standard Specification] what is the concept and definition of low code? Is no code a low code?
Polymorphism
“先导杯”来啦!召唤科学计算界的最强大脑,36万奖池等你来拿
解决Couldn‘t determine repo type for URL