zabbix如何监控MySQL


一、概述

mysql指标

实例状态

连接数

流量

增删改查

缓冲池大小与利用率​

二、mysql设置(192.168.10.130)

​为了方便直接使用lnmp的mariadb

​之前安装zabbix环境已经设置了一个用户

​create database zabbix character set utf8;

grant all on  zabbix.* to  zabbix@”localhost” identified by “zabbix”;​

直接拿来使用

创建免密配置文件

vi /usr/local/etc/.my.cnf

[mysql]

user=zabbix

password=zabbix

host=127.0.0.1

[mysqladmin]

user=zabbix

password=zabbix

host=127.0.0.1

进行测试

​HOME=/usr/local/etc mysqladmin ping | grep -c alive

echo “show variables where Variable_name=’max_connections’;” | HOME=/usr/local/etc mysql -N | awk ‘{print $2}’

三、zabbix配置(192.168.10.130)

zabbix_agentd本身带着mysql的模板,源码包位置:

/root/zabbix-3.4.3/conf/zabbix_agentd/userparameter_mysql.conf

vi /usr/local/etc/zabbix_agentd.conf.d/mysql.conf

连接数

UserParameter=mysql.max_connections,echo “show variables where Variable_name=’max_connections’;” |HOME=/usr/local/etc mysql -N | awk ‘{print $2}’

UserParameter=mysql.current_connections,echo “show global status where Variable_name=’Threads_connected’;” |HOME=/usr/local/etc  mysql -N | awk ‘{print $2}’

缓冲池

UserParameter=mysql.buffer_pool_size,echo “show variables where Variable_name=’innodb_buffer_pool_size’;” |HOME=/usr/local/etc mysql -N |awk ‘{printf “%.2f”,$2/1024/1024/1024}’

UserParameter=mysql.buffer_pool_usage_percent,echo “show global status where Variable_name=’Innodb_buffer_pool_pages_free’ or Variable_name=’Innodb_buffer_pool_pages_total’;” |HOME=/usr/local/etc mysql -N | awk ‘{a[NR]=$2}END{printf “%.1f”,100-((a[1]/a[2])*100)}’

增删改查

UserParameter=mysql.status[*],echo “show global status where Variable_name=’$1′;” |HOME=/usr/local/etc mysql -N | awk ‘{print $$2}’

实例状态

UserParameter=mysql.ping,HOME=/usr/local/etc mysqladmin ping | grep -c alive

UserParameter=mysql.version,HOME=/usr/local/etc mysql -V

启动zabbix_agentd

zabbix_agentd

四、web页面配置

也可以把没有的那几个监控项添加进去