zabbix3.2学习笔记(九):mysql5.6+监控

Zabbix 3.2自带监控mysql数据库的模板,只是没有监控主从状态的监控项,我们可以将自带的模板克隆一份存为Template App MySQL_slave,然后配置agent客户端,随后在web端给主机增加监控项和触发器。
1)首先在zabbix客户端的mysql里添加账号,即只是本机使用zabbix账号连接本地的mysql
mysql> grant all privileges on *.* to zabbix@'localhost' identified by "Passw0rd”;
mysql> flush privileges;
2)在zabbix_agent目录/etc/zabbix/zabbix_agentd.d下创建.my.cnf 连接文件
vi .my.cnf
[mysql]
host=localhost
user=zabbix
password=Passw0rd
socket=/var/lib/mysql/mysql.sock
[mysqladmin]
host=localhost
user=zabbix
password=Passw0rd
socket=/var/lib/mysql/mysql.sock
3,修改自带监控插件的配置文件
cd /etc/zabbix/zabbix_agentd.d/
cat userparameter_mysql.conf
# 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=/var/lib/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>,<table>,<type>].
# 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=/var/lib/zabbix mysql -N'
UserParameter=mysql.ping,HOME=/var/lib/zabbix mysqladmin ping | grep -c alive
UserParameter=mysql.version,mysql -V
#添加以下监控项:
#slave状态是否正常
UserParameter=slavestatus,echo "show slave status\G" | HOME=/var/lib/zabbix mysql -N | grep -c "Yes"
#seconds behind master
UserParameter=sbehindmaster,echo "show slave status" | HOME=/var/lib/zabbix mysql -N | awk '{print $25}'
#当前线程数
UserParameter=threads,HOME=/var/lib/zabbix mysqladmin status | cut -f3 -d":" | cut -f1 -d"Q" | tr -d ' '
就像第一句英文说的将所有HOME=/var/lib/zabbix改为/etc/zabbix/zabbix_agentd.d
4,重启zabbix-agent,在zabbix web端 检测中--最新数据--选择对应主机,若看到最新数据即成功了。
这样就避免了
UserParameter=mysql.threads,mysqladmin -uroot -ppassword status | cut -f3 -d":" | cut -f1 -d"Q" | tr  -d ' '
这种监控项直接读取数据时提示:
Warning: Using a password on the command line interface can be insecure
而取不到值。

转载于:https://my.oschina.net/u/2404183/blog/1524559

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值