ZABBIX 3.X加载percona mysql插件来监控mysql5.6的详细实现过程

安装部署zabbix见上一篇文章《ZABBIX企业级监控安装部署

http://blog.csdn.net/crpp0902/article/details/77978405


部署完zabbix,自带的对于mysql的监控脚本远远不能满足DBA日常监控的需要,percona就有这个详细监控的模版以及脚本,刚好能用于DBA日常的监控。

1、需要安装php脚本运行环境

percona监控zabbix的脚本使用php写的,所以需要准备好php运行环境:

yum install -yphp php-mysql 

2、安装 percona-zabbix-templates

yum install https://www.percona.com/downloads/percona-monitoring-plugins/1.1.6/percona-zabbix-templates-1.1.6-1.noarch.rpm

安装完,我们介绍几个重要文件:

[root@slave1 zabbix_agentd.d]# cd /var/lib/zabbix/percona/
[root@slave1 percona]# ls
scripts  templates
[root@slave1 percona]#
[root@slave1 scripts]# cd ../templates/
[root@slave1 templates]# ls -alt
total 292
drwxr-xr-x. 2 root root   4096 Sep 14 01:33 .
drwxr-xr-x. 4 root root   4096 Sep 13 21:52 ..
-rw-r--r--. 1 root root  18866 Jan 11  2016 userparameter_percona_mysql.conf
-rw-r--r--. 1 root root 269258 Jan 11  2016 zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.6.xml
[root@slave1 templates]# ls -alt ../scripts/
total 72
drwxr-xr-x. 2 root root  4096 Sep 14 01:40 .
-rwxr-xr-x. 1 root root  1259 Sep 14 01:40 get_mysql_stats_wrapper.sh
-rwxr-xr-x. 1 root root 59634 Sep 13 22:23 ss_get_mysql_stats.php

*scripts目录下get_mysql_stats_wrapper.sh脚本是监控获取MySQL状态的,ss_get_mysql_stats.php文件是配置连接数据库用户名密码的。用shell来调用PHP。

* templates目录下conf文件是要放在agent端/etc/zabbix/zabbix_agentd.d/下面的,用于定义监控的items,XML文件是模版文件(这个模板目前还不支持zabbix 3,需要进行修改)

3、导入模板xml文件到zabbix server

ZABBIX 3.X加载percona mysql插件来监控mysql5.6的详细实现过程_第1张图片

报错:Invalid tag"/zabbix_export/date": "YYYY-MM-DDThh:mm:ssZ" is expected.

解决:这个模板还不支持zabbix,需要修改xml模板文件,网上有对应ZABBIX 3的模板导入即可。


4、修改相关脚本:

vim get_mysql_stats_wrapper.sh
修改:
RES=`HOME=~zabbix mysql -e 'SHOW SLAVESTATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print$2}' | tr '\n
为:
RES=`HOME=~/usr/bin/mysql -e 'SHOW SLAVE STATUS\G' | egrep'(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`

修改
HOST=localhost
为:
HOST=192.168.174.133 


vim ss_get_mysql_stats.php    
$mysql_user = 'zabbix';
$mysql_pass = '123456';
$mysql_port = 3306;

cp/var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf/etc/zabbix/zabbix_agentd.d/userparameter_percona_mysql.conf

测试监控项:
[root@slave1 templates]#  /usr/bin/php -q /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php--host localhost --items gg

ERROR: Access denied for user'zabbix'@'localhost' (using password: YES)

 [root@slave1templates]#  /usr/bin/php -q/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php --host 192.168.174.133--items gg

gg:28

5、应用percona模板到监控:

ZABBIX 3.X加载percona mysql插件来监控mysql5.6的详细实现过程_第2张图片

ZABBIX 3.X加载percona mysql插件来监控mysql5.6的详细实现过程_第3张图片

查看相应监控数据图表:

ZABBIX 3.X加载percona mysql插件来监控mysql5.6的详细实现过程_第4张图片

ZABBIX 3.X加载percona mysql插件来监控mysql5.6的详细实现过程_第5张图片

ZABBIX 3.X加载percona mysql插件来监控mysql5.6的详细实现过程_第6张图片ZABBIX 3.X加载percona mysql插件来监控mysql5.6的详细实现过程_第7张图片


碰到问题:

55392:20170914:014811.374 item "SLAVE1:MySQL.State-none" became not supported: Value "rm: cannot remove `/tmp/192.168.174.133-mysql_cacti_stats.txt': Operation not permitted
21" of type "string" is not suitable for value type "Numeric (float)"
 55392:20170914:014813.403 item "SLAVE1:MySQL.State-other" became not supported: Value "rm: cannot remove `/tmp/192.168.174.133-mysql_cacti_stats.txt': Operation not permitted
0" of type "string" is not suitable for value type "Numeric (float)"

执行测试发现发现是文件权限不对:

[root@slave1 zabbix]# zabbix_get -s 192.168.174.133 -p 10050 -k  "MySQL.Threads-connected"
rm: cannot remove `/tmp/192.168.174.133-mysql_cacti_stats.txt': Operation not permitted
22
[root@slave1 zabbix]# ls -alt /tmp/192.168.174.133-mysql_cacti_stats.txt 
-rw-r--r--. 1 root root 1422 Sep 14 01:41 /tmp/192.168.174.133-mysql_cacti_stats.txt

修改权限后测试正常:

[root@slave1 zabbix]# chown zabbix:zabbix /tmp/192.168.174.133-mysql_cacti_stats.txt

[root@slave1 zabbix]# zabbix_get -s 192.168.174.133 -p 10050 -k  "MySQL.Threads-connected"
22
[root@slave1 zabbix]# zabbix_get -s 192.168.174.133 -p 10050 -k  "MySQL.Key-read-requests"
152

查看日志也正常:
[root@slave1 zabbix]# tail -f zabbix_server.log 
 55393:20170914:015126.082 item "SLAVE1:MySQL.innodb-transactions" became not supported: cannot convert value to numeric type
 55394:20170914:015127.098 item "SLAVE1:MySQL.Key-buf-bytes-unflushed" became not supported: Value "rm: cannot remove `/tmp/192.168.174.133-mysql_cacti_stats.txt': Operation not permitted
0" of type "string" is not suitable for value type "Numeric (float)"
 55392:20170914:015128.100 item "SLAVE1:MySQL.Key-buf-bytes-used" became not supported: Value "rm: cannot remove `/tmp/192.168.174.133-mysql_cacti_stats.txt': Operation not permitted
1530880" of type "string" is not suitable for value type "Numeric (float)"
 55392:20170914:015129.120 item "SLAVE1:MySQL.key-buffer-size" became not supported: Value "rm: cannot remove `/tmp/192.168.174.133-mysql_cacti_stats.txt': Operation not permitted
8388608" of type "string" is not suitable for value type "Numeric (float)"
 55395:20170914:015130.166 item "SLAVE1:MySQL.Key-read-requests" became not supported: cannot convert value to numeric type
 55393:20170914:015131.169 item "SLAVE1:MySQL.Key-reads" became not supported: cannot convert value to numeric type
 55393:20170914:015132.182 item "SLAVE1:MySQL.Key-write-requests" became not supported: cannot convert value to numeric type

 55392:20170914:015252.792 item "SLAVE1:MySQL.slave-lag" became supported
 55393:20170914:015253.795 item "SLAVE1:MySQL.Slave-open-temp-tables" became supported
 55393:20170914:015255.830 item "SLAVE1:MySQL.slave-running" became supported
 55395:20170914:015256.873 item "SLAVE1:MySQL.slave-stopped" became supported
 55393:20170914:015304.906 item "SLAVE1:MySQL.State-closing-tables" became supported
 55392:20170914:015305.913 item "SLAVE1:MySQL.State-copying-to-tmp-table" became supported
 55395:20170914:015306.925 item "SLAVE1:MySQL.State-end" became supported
 55392:20170914:015307.934 item "SLAVE1:MySQL.State-freeing-items" became supported




你可能感兴趣的:(mysql,linux)