Percona Monitoring Plugins for Zabbix
由于zabbix自带的MySQL监控插件功能太过简陋,而且还没有提供可以直接使用的key,对于DBA来说,需要更加详细的监控数据,所以在生产场景中一般不使用自带的监控插件,而使用Percona公司的Percona Monitoring Plugins for Zabbix来监控MySQL。 Percona公司有自己的一套数据库Percona Server,Percona Server在功能上和性能上较MySQL有着显著的提升,该版本提升了在高负载情况下的 InnoDB 的性能、为 DBA 提供一些非常有用的性能诊断工具;另外有更多的参数和命令来控制服务器行为,所以在监控MySQL性能参数方面就更加专业了。 MySQL监控几个重要的性能指标 · Slave_running 从库的运行状态 · Threads_running 数据库超负荷 · Aborted_clients 客户端被异常中断数值 · Questions 每秒钟获得的查询数量 · Handler_* 底层(low-level)数据库负载 · Opened_tables 表缓存没有命中的数量 · Slow_queries 慢查询数量 · show processlist 客户端连接进程数 · innodb status innodb状态: · Pending normal aio reads 该值是innodb io请求查询的大小 · reads/s, avg bytes/read, writes/s, fsyncs/s 这些值是io统计 · Buffer pool hit rate 这个命中率非常依赖于你的应用程序 · inserts/s, updates/s, deletes/s, reads/s 有一些Innodb的底层操作
Percona Monitoring Plugins 安装 系统环境
1
2
3
4
| [iyunv@linux-node1 sbin]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[iyunv@linux-node1 sbin]# ./zabbix_server -V
zabbix_server (Zabbix) 3.0.3
|
1)安装相关组件 1
2
3
4
5
6
7
8
9
10
11
12
| [iyunv@linux-node1 tools]# yum install php php-mysql -y
[iyunv@linux-node1 tools]# wget https://www.percona.com/download ... -1.1.6-1.noarch.rpm #下载percona的模板插件
[iyunv@linux-node1 tools]# rpm -ivh percona-zabbix-templates-1.1.6-1.noarch.rpm
[iyunv@linux-node1 tools]# rpm -ql percona-zabbix-templates #查看插件都安装了哪些文件在系统里面
/var/lib/zabbix/percona
/var/lib/zabbix/percona/scripts #scripts文件夹有一个脚本和一个php文件
/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh #脚本文件里面调用下面的php去连接数据库
/var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
/var/lib/zabbix/percona/templates
/var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf #需要防止在zabbix_agentd.d/文件夹下的mysql监控脚本
/var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.6.xml
#这个是最后要导入到zabbix中去的模板文件
|
2)在agent上配置插件连接mysql数据库 1
2
3
4
5
6
7
8
9
| [iyunv@linux-node1 ~]# cd /var/lib/zabbix/percona/scripts
[iyunv@linux-node1 scripts]# ll
total 64
-rwxr-xr-x 1 root root 1251 Jan 11 2016 get_mysql_stats_wrapper.sh
-rwxr-xr-x 1 root root 59640 Jan 11 2016 ss_get_mysql_stats.php
[iyunv@linux-node1 scripts]# vim ss_get_mysql_stats.php.cnf #创建这个.cnf的文件
<?php
$mysql_user = 'root';
$mysql_pass = 'li123456'; #注意生产环境中密码一定要复杂,由于是明文,所以要注意控制文件权限
|
3)测试percona能不能获取到数据库中性能参数 1
2
3
4
5
6
7
| [iyunv@linux-node1 scripts]# cat /etc/zabbix/zabbix_agentd.d/userparameter_percona_mysql.conf
…
UserParameter=MySQL.Connections,/var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh iz
…
#我们随便在监控脚本中找一个key值参数,记得最终要传给脚本的参数是后面的 iz
[iyunv@linux-node1 scripts]# ./get_mysql_stats_wrapper.sh iz
11 #成功返回数值,当前数据库的连接数是11
|
如果出现获取不到值的情况,测试下面命令 1
2
| [iyunv@linux-node1 scripts]# /usr/bin/php -q ./ss_get_mysql_stats.php --host localhost --items gg
ERROR: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
|
出现上面的错误提示是由于你默认yum安装的PHP连接mysql使用的sock路径是/var/lib/mysql/mysql.sock 解决办法一: 修改MySQL配置文件my.cnf中的socket路径,改成/var/lib/mysql/mysql.sock 解决办法二: 修改php.ini文件中的socket路径 1
2
3
4
5
| mysql.default_socket = /application/mysql-5.5.32/tmp/mysql.sock
mysqli.default_socket = /application/mysql-5.5.32/tmp/mysql.sock
pdo_mysql.default_socket=/application/mysql-5.5.32/tmp/mysql.sock
[iyunv@linux-node1 scripts]# vim get_mysql_stats_wrapper.sh
HOST=localhost #HOST修改为127.0.0.1
|
重启php搞定
4)最后我们在zabbix中添加主机监控模板 1
2
3
4
5
| [iyunv@linux-node1 ~]# cd /var/lib/zabbix/percona/templates/
[iyunv@linux-node1 templates]# ll
total 284
-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 #sz导出模板文件
|
但是可能由于我当时安装的zabbix版本高原因,导入模板会出现很多错误,反而用zabbix2.X升级过来的模板文件却能用,这里也提供一下下载地址,供各位测试: https://pan.baidu.com/s/1nvdbnTZ
模板添加成功后,有很多的监控项已经自动添加进来了
5)等待几分钟
|