监控mysql尹正杰_zabbix基于命令行方式监控MySQL

zabbix基于命令行方式监控MySQL

作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

一.zabbix agent自定义监控脚本

1>.自定义脚本

[root@node203.yinzhengjie.org.cn ~]# cat /etc/zabbix/zabbix_agentd.d/mysql_monitoring.sh#!/bin/bash

#

#********************************************************************#Author: yinzhengjie

#QQ:1053419035#Date:2019-11-23#FileName: shell/menu.sh#URL: http://www.cnblogs.com/yinzhengjie

#Description: The test script

#Copyright notice: original works, no reprint!Otherwise, legal liability will be investigated.

#********************************************************************

functionseconds_Behind_Master(){

NUM=`mysql -uroot -hlocalhost -e "show slave status\G;" | grep "Seconds_Behind_Master:" | awk -F: '{print $2}'`echo$NUM

}functionmaster_slave_check(){

NUM1=`mysql -uroot -hlocalhost -e "show slave status\G;" | grep "Slave_IO_Running" | awk -F: '{print $2}' | sed 's/^[ \t]*//g'`

#echo$NUM1

NUM2=`mysql -uroot -hlocalhost -e "show slave status\G;" | grep "Slave_SQL_Running:" | awk -F: '{print $2}' | sed 's/^[ \t]*//g'`

#echo$NUM2if test $NUM1 == "Yes" && test $NUM2 == "Yes";then

echo 50

else

echo 100

fi}functionmain(){case $1 inseconds_Behind_Master)

seconds_Behind_Master

;;

master_slave_check)

master_slave_check

;;esac}

main $1[root@node203.yinzhengjie.org.cn~]#

2>.测试脚本可用性

9f4c1616dfa96b235eeefbb5ab38f27e.png

3>.为脚本授权

[root@node203.yinzhengjie.org.cn ~]# ll /etc/zabbix/zabbix_agentd.d/mysql_monitoring.sh

-rw-r--r-- 1 root root 1279 Feb 29 18:31 /etc/zabbix/zabbix_agentd.d/mysql_monitoring.sh[root@node203.yinzhengjie.org.cn~]#[root@node203.yinzhengjie.org.cn~]# chmod +x /etc/zabbix/zabbix_agentd.d/mysql_monitoring.sh[root@node203.yinzhengjie.org.cn~]#

[root@node203.yinzhengjie.org.cn~]# ll /etc/zabbix/zabbix_agentd.d/mysql_monitoring.sh

-rwxr-xr-x 1 root root 1279 Feb 29 18:31 /etc/zabbix/zabbix_agentd.d/mysql_monitoring.sh[root@node203.yinzhengjie.org.cn~]#

[root@node203.yinzhengjie.org.cn~]#

4>.定义agent端的子配置文件

[root@node203.yinzhengjie.org.cn ~]# grep ^Include /etc/zabbix/zabbix_agentd.confInclude=/etc/zabbix/zabbix_agentd.d/*.conf

[root@node203.yinzhengjie.org.cn ~]#

[root@node203.yinzhengjie.org.cn ~]# cat /etc/zabbix/zabbix_agentd.d/mysql_monitoring.conf

UserParameter=mysql_master_slave[*],/etc/zabbix/zabbix_agentd.d/mysql_monitoring.sh $1

[root@node203.yinzhengjie.org.cn ~]#

[root@node203.yinzhengjie.org.cn ~]#

5>.重启zabbix agent服务使得配置生效

[root@node203.yinzhengjie.org.cn ~]# systemctl restart zabbix-agent.service

f7c18b1969ea68f0a22c19b0ec5f2a6a.png

二.在zabbix WebUI测试

1>.先在zabbix server端进行测试是否可以获取数据

[root@zabbix203.yinzhengjie.org.cn ~]# /yinzhengjie/softwares/zabbix/bin/zabbix_get -s 172.200.1.203 -p 10050 -k "mysql_master_slave[master_slave_check]"

50[root@zabbix203.yinzhengjie.org.cn~]#

[root@zabbix203.yinzhengjie.org.cn~]# /yinzhengjie/softwares/zabbix/bin/zabbix_get -s 172.200.1.203 -p 10050 -k "mysql_master_slave[seconds_Behind_Master]"

0[root@zabbix203.yinzhengjie.org.cn~]#

[root@zabbix203.yinzhengjie.org.cn~]#

2>.创建一个模板

140edbf99464de14304c0a08f456e017.png

3>.自定义监控项

bcbb59b860e8eb283fc45e06e6e779ea.png

4>.自定义模板的图形

0e78bca3d5af6658043015517488de2e.png

5>.自定义MySQL的触发器

d11a3ca791a00c2bf84fccc544ce35f1.png

6>.为MySQL主机链接咱们自定义的模板

2b0fa43f63c87b005e6eebbca96e5003.png

7>.模板链接成功

5fa9c5cb87b7ba84f45a8e548e67d5b0.png

8>.手动停止MySQL数据库从库同步数据

mysql> stop slave;

bde1715ec995a653008c2e900a8325ce.png

9>.查看自定义的MySQL图形

007fa793799264ccf223bd4950ab017f.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值