ZABBIX4.0 添加mysql监控

环境简介:

zabbix 服务器IP:192.168.101.1

mysql 服务器IP:192.168.101.2 (agent端)

前提条件:是192.168.102已经安装zabbix_agent

1.创建监控所需mysql账户(agent端):
grant usage on *.* to [email protected] identified by '123456';
flush privileges;

 
2.agent端:创建.my.cnf并检查zabbix账号是否能正常连接数据库
/etc/zabbix/下创建一个包含MySQL用户名和密码的配置文件“.my.cnf”

[client]
user=zabbix
host=127.0.0.1
password=123456

有了这个文件后,检查zabbix账号是否能正常连接数据库:
HOME=/etc/zabbix/ mysqladmin ping | grep -c alive

ZABBIX4.0 添加mysql监控_第1张图片

我这里是把已经改好的模板直接放到/etc/zabbix/zabbix_agentd.conf.d/ 目录下 ,注意HOME=路径的配置 配置完后续重启zabbix-agent:
kill -9 XXX
/usr/sbin/zabbix_agentd

3.zabbix服务端验证zabbix代理服务端是否正常返回数据

同时,在Server端也可以使用使用zabbix_get命令来测试从Server端获取指定的Client端的数据,如下:

[root@Zabbixserver alertscripts]# zabbix_get -s172.18.200.61 -p 10050 -k mysql.ping

ZABBIX4.0 添加mysql监控_第2张图片

如果返回数据,证明zabbix服务端可获取客户端信息!

4.页面对主机添加监控模板

ZABBIX4.0 添加mysql监控_第3张图片

ZABBIX4.0 添加mysql监控_第4张图片

ZABBIX4.0 添加mysql监控_第5张图片

至此,可看到监控数据!添加mysql监控成功!

监控脚本:

# For all the following commands HOME should be set to the directory that has .my.cnf file with password information.

# Flexible parameter to grab global variables. On the frontend side, use keys like mysql.status[Com_insert].
# Key syntax is mysql.status[variable].
UserParameter=mysql.status[*],echo "show global status where Variable_name='$1';" | HOME=/etc/zabbix mysql -N | awk '{print $$2}'

# Flexible parameter to determine database or table size. On the frontend side, use keys like mysql.size[zabbix,history,data].
# Key syntax is mysql.size[,,].
# Database may be a database name or "all". Default is "all".
# Table may be a table name or "all". Default is "all".
# Type may be "data", "index", "free" or "both". Both is a sum of data and index. Default is "both".
# Database is mandatory if a table is specified. Type may be specified always.
# Returns value in bytes.
# 'sum' on data_length or index_length alone needed when we are getting this information for whole database instead of a single table
UserParameter=mysql.size[*],bash -c 'echo "select sum($(case "$3" in both|"") echo "data_length+index_length";; data|index) echo "$3_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "$1" = "all" || ! "$1" ]] || echo " where table_schema=\"$1\"")$([[ "$2" = "all" || ! "$2" ]] || echo "and table_name=\"$2\"");" | HOME=/etc/zabbix mysql -N'

UserParameter=mysql.ping,HOME=/etc/zabbix mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V

 

 

 

 

 

 

 

你可能感兴趣的:(zabbix)