自定义监控

自定义监控

自定义监控MySQL主从状态

完成同步

[root@localhost ~]# mysql -uroot -p123456 -e " show slave status\G"
mysql: [Warning] Using a password on the command line interface can be insecure.
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.159.129
                  Master_User: alg
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql_bin.000001
          Read_Master_Log_Pos: 154
               Relay_Log_File: mysql-relay-bin.000002
                Relay_Log_Pos: 320
        Relay_Master_Log_File: mysql_bin.000001
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

配置监控脚本

//在被监控端,也就是从库,首先修改配置文件
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
UserParameter=check_mysql_status,/bin/bash /scripts/mysql_status.sh
 
//重启服务生效配置
[root@localhost ~]# pkill zabbix_agentd 
[root@localhost ~]# zabbix_agentd 
 
//再编写脚本
[root@localhost ~]# vim /scripts/mysql_status.sh
#!/bin/bash
yes=`mysql -uroot -p123456 -e " show slave status\G" 2> /dev/null |grep "Running:"|grep -c "Yes"`
if [ $yes == 2  ]; then
        echo "0"
else    
        echo "1"
fi 
[root@localhost ~]# chmod +x /scripts/mysql_status.sh 
 
//去服务端检查key是否可用
[root@zabbix ~]# zabbix_get -s 192.168.159.167 -k check_mysql_status
0

添加监控项

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

查看监控数据

在这里插入图片描述

添加触发器

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

手动触发报警

[root@localhost ~]# mysql -uroot -p123456 -e "stop slave;"
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost ~]# 

在这里插入图片描述

自定义监控MySQL延迟

配置监控脚本

//在被监控端,也就是从库,首先修改配置文件
[root@localhost ~]# vim /usr/local/etc/zabbix_agentd.conf
UserParameter=check_mysqlyc,/bin/bash /scripts/mysqlyc.sh
 
//重启服务生效配置
[root@localhost ~]# pkill zabbix_agentd 
[root@localhost ~]# zabbix_agentd 
 
//再编写脚本
[root@localhost ~]# vim /scripts/mysqlyc.sh
 
#!/bin/bash
yc=`mysql -uroot -p123456 -e "show slave status\G" 2> /dev/null |awk '/Seconds_Behind_Master/ {print $2}' `
echo $yc
 
[root@localhost ~]# chmod +x /scripts/mysqlyc.sh 
 
//去服务端检查key是否可用
[root@zabbix ~]# zabbix_get -s 192.168.159.167 -k check_mysqlyc
0

添加监控项

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

查看监控数据

在这里插入图片描述

添加触发器

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

报警触发

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值