zabbix3.2学习笔记(九):mysql5.6+监控
博客专区 > hiwill 的博客 > 博客详情
zabbix3.2学习笔记(九):mysql5.6+监控
hiwill 发表于5个月前
zabbix3.2学习笔记(九):mysql5.6+监控
  • 发表于 5个月前
  • 阅读 29
  • 收藏 0
  • 点赞 0
  • 评论 0

标题:腾讯云 新注册用户域名抢购1元起>>>   

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
而取不到值。

共有 人打赏支持
粉丝 9
博文 109
码字总数 64459
×
hiwill
如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: