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-templatesyum install https://www.percona.com/downloads/percona-monitoring-plugins/1.1.6/percona-zabbix-templates-1.1.6-1.noarch.rpm

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


[[email?protected] zabbix_agentd.d]# cd /var/lib/zabbix/percona/
[[email?protected] percona]# ls
scriptstemplates
[[email?protected] percona]#
[[email?protected] scripts]# cd ../templates/
[[email?protected] 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 root18866 Jan 112016 userparameter_percona_mysql.conf
-rw-r--r--. 1 root root 269258 Jan 112016 zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.6.xml
[[email?protected] templates]# ls -alt ../scripts/
total 72
drwxr-xr-x. 2 root root4096 Sep 14 01:40 .
-rwxr-xr-x. 1 root root1259 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



报错: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
测试监控项:
[[email?protected] 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)
[[email?protected]]#/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模板到监控:





查看相应监控数据图表:




碰到问题:


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)"

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


[[email?protected] 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
[[email?protected] 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

修改权限后测试正常:


[[email?protected] zabbix]# chown zabbix:zabbix /tmp/192.168.174.133-mysql_cacti_stats.txt
[[email?protected] zabbix]# zabbix_get -s 192.168.174.133 -p 10050 -k"MySQL.Threads-connected"
22
[[email?protected] zabbix]# zabbix_get -s 192.168.174.133 -p 10050 -k"MySQL.Key-read-requests"
152
查看日志也正常:
[[email?protected] 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

分享给朋友:
您可能感兴趣的文章:
随机阅读: