码迷,mamicode.com
首页 > 数据库 > 详细

zabbix4.4 监控mysql

时间:2020-02-01 14:17:37      阅读:656      评论:0      收藏:0      [点我收藏+]

标签:用处   gre   get   index   col   信息   oca   monitor   com   

#template_db_mysql.conf created by Zabbix for "Template DB MySQL" and Zabbix 4.2
#For OS Linux: You need create .my.cnf in zabbix-agent home directory (/var/lib/zabbix by default
#For OS Windows: You need add PATH to mysql and mysqladmin and create my.cnf in %WINDIR%\my.cnf,C:\my.cnf,BASEDIR\my.cnf https://dev.mysql.com/doc/refman/5.7/en/option-files.html
#The file must have three strings:
#[client]
#user=zbx_monitor
#password=<password>
#
UserParameter=mysql.ping[*], mysqladmin -h"$1" -P"$2" ping
UserParameter=mysql.get_status_variables[*], mysql -h"$1" -P"$2" -sNX -e "show global status"
UserParameter=mysql.version[*], mysqladmin -s -h"$1" -P"$2" version
UserParameter=mysql.db.discovery[*], mysql -h"$1" -P"$2" -sN -e "show databases"
#UserParameter=mysql.dbsize[*], mysql -h"$1" -P"$2" -sN -e "SELECT SUM(DATA_LENGTH + INDEX_LENGTH) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=‘$3‘"
UserParameter=mysql.replication.discovery[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.slave_status[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"
UserParameter=mysql.status[*],/server/scripts/mysql.sh $1

这是官方给的文件  放上去感觉没太大用处  除了让默认mysql.status启用 也没有数据流量。

1、在/etc/zabbix/下创建.my.cnf文件:

[mysql]
host=localhost     
user=zabbix
password=zabbix
socket=/var/lib/mysql/mysql.sock
[mysqladmin]
host=localhost
user=zabbix
password=zabbix
socket=/var/lib/mysql/mysql.sock
mysql.sock位置查找方法:
[root@localhost ~]# find / -name mysql.sock
/var/lib/mysql/mysql.sock

2、查看userparameter_mysql.conf文件位置,将其复制到/etc/zabbix/zabbix_agentd.d目录

[root@localhost zabbix_agentd.d]# find / -name userparameter_mysql.conf
/usr/share/doc/zabbix-agent-4.4.5/userparameter_mysql.conf

[root@localhost zabbix_agentd.d]# cp /usr/share/doc/zabbix-agent-4.4.5/userparameter_mysql.conf /etc/zabbix/zabbix_agentd.d/

 修改userparameter_mysql.conf文件内容为:

[root@localhost zabbix_agentd.d]# cat userparameter_mysql.conf 
#UserParameter=mysql.ping[*], mysqladmin -h"$1" -P"$2" ping
#UserParameter=mysql.get_status_variables[*], mysql -h"$1" -P"$2" -sNX -e "show global status"
#UserParameter=mysql.version[*], mysqladmin -s -h"$1" -P"$2" version
#UserParameter=mysql.db.discovery[*], mysql -h"$1" -P"$2" -sN -e "show databases"
#UserParameter=mysql.dbsize[*], mysql -h"$1" -P"$2" -sN -e "SELECT SUM(DATA_LENGTH + INDEX_LENGTH) FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA=‘$3‘"
#UserParameter=mysql.replication.discovery[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"
#UserParameter=mysql.slave_status[*], mysql -h"$1" -P"$2" -sNX -e "show slave status"


UserParameter=mysql.status[*],echo "show global status where Variable_name=‘$1‘;" | HOME=/etc/zabbix /usr/bin/mysql -N | awk ‘{print $$2}‘
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=/usr/local/zabbix/etc mysql -N‘
UserParameter=mysql.ping,HOME=/etc/zabbix /usr/bin/mysqladmin ping
# | grep -c alive
UserParameter=mysql.version,/usr/bin/mysql -V
UserParameter=mysql.vars[*],echo "show variables where Variable_name=‘$1‘;" | HOME=/etc/zabbix /usr/bin/mysql -N | awk ‘{print $$2}‘

3、重新启动相关服务:

systemctl restart mariadb

systemctl restart zabbix-agemt

4、在web端添加监控项

 

键值为:UserParameter=mysql.ping

技术图片

 

 

技术图片

 

 5、模板创建完成以后,应用于主机,并查看该主机最新数据对应模板 数据信息是否正确。

技术图片

 

zabbix4.4 监控mysql

标签:用处   gre   get   index   col   信息   oca   monitor   com   

原文地址:https://www.cnblogs.com/fanlong0212/p/12248160.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!