模板 MySQL 未在 Zabbix 中获得结果

Template MySQL didn't get result in Zabbix

我打算使用 Temple MySQL 监控 MySQL 个详细实例。不幸的是我无法得到结果。我在配置中还缺少什么。查看zabbix-agent log那些是一段日志不是整个日志。

XECUTE_STR() command:'/usr/lib/zabbix/externalscripts/mysql_check.pl' len:0 cmd_result:''
 28786:20160121:141008.072 Sending back []
 28786:20160121:141008.072 listener #2 [waiting for connection]
 28788:20160121:141008.648 In send_buffer() host:'127.0.0.1' port:10051 values:0/100
 28788:20160121:141008.648 End of send_buffer():SUCCEED
 28788:20160121:141008.648 active checks #1 [idle 1 sec]
 28784:20160121:141008.795 collector [processing data]
 28784:20160121:141008.796 In update_cpustats()
 28784:20160121:141008.796 End of update_cpustats()
 28784:20160121:141008.796 collector [idle 1 sec]
 28785:20160121:141009.075 listener #1 [processing request]
 28785:20160121:141009.075 Requested [mysql[root,Qwestions,lld]]

日志没用。我们只看到脚本 returns 没有结果,也看不出原因。

  1. 尝试使用您在 mysql_check.pl 文件中提供的凭据从控制台连接到 MySQL。确保用户有足够的权限(最后是 SUPER)。

mysql -hhostname -uuser -ppassword

  1. 运行 来自用户zabbix的脚本及检查结果:

perl ./mysql_check.pl

1.为 MySQL 添加特殊用户:

示例:

GRANT USAGE ON *.* TO 'zabbix'@'%' IDENTIFIED BY 'superpassword';
FLUSH PRIVILEGES;

2。将用户参数添加到 zabbix-agent 配置中

编辑/etc/zabbix/zabbix_agentd.conf

UserParameter=mysql.version,mysql -V
UserParameter=mysql.status[*],echo "show global status where Variable_name='';" | HOME=/etc/zabbix mysql -N | awk '{print $}'
UserParameter=mysql.ping,HOME=/etc/zabbix mysqladmin ping | grep -c alive
# '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[*],echo "select sum($(case "" in both|"") echo "data_length+index_length";; data|index) echo "_length";; free) echo "data_free";; esac)) from information_schema.tables$([[ "" = "all" || ! "" ]] || echo " where table_schema=''")$([[ "" = "all" || ! "" ]] || echo "and table_name=''");" | HOME=/etc/zabbix mysql -N

如果你想扩展监控项,只需添加另一个 UserParameter 和适当的 SQL-query

3。为 MySQL 添加授权文件:

创建 .my.cnf 文件到 /etc/zabbix/

[client]
user = zabbix
password = superpassword

4.重新启动代理(和 zabbix-proxy,如果你使用它)