zabbix监控mysql

1) 监控mysql主从状态
授权(可以不用)

MariaDB [(none)]> grant all on *.* to check@localhost identified by '123';
version for the right syntax to use near 'check@localhost identified by '123'' at line 1
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)

客户端编辑配置文件

[root@localhost zabbix_agentd.d]# pwd
/etc/zabbix/zabbix_agentd.d
[root@localhost zabbix_agentd.d]# cat check_mysql.conf
UserParameter=mysql_status[*],/etc/zabbix/scripts/check_mysql.sh $1

监控mysql主从状态

[root@localhost scripts]# cat /etc/zabbix/scripts/check_mysql.sh
#!/bin/bash
case $1 in
        slave_status)
        mysql -ucheck -p123 -e "show slave status \G;" | grep "Running" | grep "Yes" | awk '{print $2}' | wc -l
        ;;
esac

重启一下

[root@localhost scripts]# systemctl restart zabbix-agent

serevr 端get 一下值

[root@localhost ~]# zabbix_get -s 192.168.88.17 -k mysql_status[slave_status]
2

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

[root@agent zabbix_agentd.d]# pwd
/etc/zabbix/zabbix_agentd.d
[root@agent zabbix_agentd.d]# ls
userparameter_mysql.conf         userparameter_pv_uv.conf
userparameter_mysql_status.conf
[root@agent zabbix_agentd.d]# cat userparameter_mysql_status.conf
UserParameter=mysql_status[*],/etc/zabbix/scripts/mysql.sh $1

[root@localhost scripts]# cat /etc/zabbix/scripts/mysql.sh
#!/bin/bash
uptime=`mysqladmin status | awk '{print $2}'`
case $1 in
        Bytes_sent)
        mysqladmin extended-status | grep "Bytes_sent" | awk '{print $4}'
        ;;
        Bytes_received)
        mysqladmin extended-status | grep "Bytes_received" | awk '{print $4}'
        ;;
        Com_insert)
        mysqladmin extended-status | grep -w  "Com_insert" | awk '{print $4}'
        ;;
        Com_delete)
        mysqladmin extended-status | grep -w  "Com_delete" | awk '{print $4}'
        ;;
        Com_update)
        mysqladmin extended-status | grep -w  "Com_update" | awk '{print $4}'
        ;;
        Com_select)
        mysqladmin extended-status | grep -w  "Com_select" | awk '{print $4}'
        ;;
        Com_commit)
        mysqladmin extended-status | grep -w  "Com_commit" | awk '{print $4}'
        ;;
        Com_rollback)
        mysqladmin extended-status | grep -w  "Com_rollback" | awk '{print $4}'
        ;;
        qps)
        question=`mysqladmin status | awk '{print $6}'`
        qps=$(($question/$uptime))
        echo $qps
        ;;
        tps)
        commit=`mysqladmin extended-status | grep -w 'Com_commit' | awk '{print $4}'`
        rollback=`mysqladmin extended-status | grep -w 'Com_rollback' | awk '{print $4}'`
        tps=$[($commit+$rollback)/$uptime]
        echo $tps
        ;;
        db_size)
        mysql -D information_schema -e "select sum(DATA_LENGTH) from tables where table_schema='mysql'" | sed -n '2p'
        ;;
        table_size)
        mysql -D information_schema -e "select sum(DATA_LENGTH) from tables where table_schema='mysql' and table_name='user'" | sed -n '2p'
        ;;
esac


server 端get

[root@localhost ~]# zabbix_get -s 192.168.88.17 -k mysql_status[Bytes_sent]
45471333
[root@localhost ~]# zabbix_get -s 192.168.88.17 -k mysql_status[Bytes_received]
90213020
[root@localhost ~]# zabbix_get -s 192.168.88.17 -k mysql_status[Com_insert]
1645
[root@localhost ~]# zabbix_get -s 192.168.88.17 -k mysql_status[Com_delete]
12
[root@localhost ~]# zabbix_get -s 192.168.88.17 -k mysql_status[Com_update]
383
[root@localhost ~]# zabbix_get -s 192.168.88.17 -k mysql_status[Com_select]
1792
[root@localhost ~]# zabbix_get -s 192.168.88.17 -k mysql_status[Com_commit]
1039
[root@localhost ~]# zabbix_get -s 192.168.88.17 -k mysql_status[Com_rollback]
0
[root@localhost ~]# zabbix_get -s 192.168.88.8 -k mysql.status[table_size]
420
[root@localhost ~]# zabbix_get -s 192.168.88.8 -k mysql.status[db_size]
555558
[root@localhost ~]# zabbix_get -s 192.168.88.8 -k mysql.status[qps]
15
[root@localhost ~]# zabbix_get -s 192.168.88.8 -k mysql.status[tps]
2

服务端get 不到值
[root@server ~]# zabbix_get -s 10.211.55.5 -k mysql_status[Bytes_sent]
ZBX_NOTSUPPORTED: Unsupported item key.

客户端重启agent
[root@agent zabbix_agentd.d]# systemctl restart zabbix-agent

出现NULL

去做visudo错误
去web
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

云原生解决方案

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值