按道理來說zabbix就自帶的MySQL插件來監控mysql資料庫,但是你會發現,自帶的mysql監控項是很少的,根本滿足不了公司的需求。由於它本身自帶的模板太過簡單了,所以需要做更詳細的監控,而percona就提供了這個詳細監控的模版以及腳本,解決了監控不全面的問題。percona插件是安裝在za ...
按道理來說zabbix就自帶的MySQL插件來監控mysql資料庫,但是你會發現,自帶的mysql監控項是很少的,根本滿足不了公司的需求。
由於它本身自帶的模板太過簡單了,所以需要做更詳細的監控,而percona就提供了這個詳細監控的模版以及腳本,解決了監控不全面的問題。
percona插件是安裝在zabbix-agent端的
1、percona插件安裝:
首先需要下載php依賴:
ubuntu@ubuntu:~$ apt-get install php
1、官網下載percona包
https://www.percona.com/downloads/percona-monitoring-plugins/
Version: percona的版本
Software:linux server的版本
Download All Packages Together: 一起下載所有包
Download Packages Separately: 單獨下載某個包
這裡我們選擇下載最後一個包-percona-zabbix-templates-1.1.7-1.xenial_all.ded
2、命令下載
ubuntu@ubuntu:~$ wget https://www.percona.com/downloads/percona-monitoring-plugins/1.1.7/binary/debian/xenial/x86_64/percona-zabbix-templates_1.1.7-1.xenial_all.deb
3、安裝percona包
ubuntu@ubuntu:~$ sudo dpkg -i percona-zabbix-templates_1.1.7-1.xenial_all.deb
ubuntu@ubuntu:~$ cd /var/lib/zabbix/percona/templates && ll
total 292
drwxr-xr-x 2 root root 4096 Mar 25 14:19 ./
drwxr-xr-x 4 root root 4096 Mar 15 11:39 ../
-rw-r--r-- 1 root root 18866 Dec 8 2016 userparameter_percona_mysql.conf
-rw-r--r-- 1 root root 269258 Dec 8 2016 zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml
2、編輯配置文件
1、添加模板文件路徑
ubuntu@ubuntu:~$ sudo mv /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix_agentd.conf.d/
2、修改MySQL的執行命令文件,更改mysql的用戶與密碼:
ubuntu@ubuntu:~$ sudo vim /var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
RES=`HOME=~ /usr/bin/mysql -uroot -pzabbix -e 'SHOW SLAVE STATUS\G' | egrep '(Slave_IO_Running|Slave_SQL_Running):' | awk -F: '{print $2}' | tr '\n' ','`
mysql -u用戶名 -p密碼,這裡根據自己實際情況修改
3、修改 ss_get_mysql_stats.php文件
ubuntu@ubuntu:~$ sudo vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'root';
$mysql_pass = 'zabbix';
4、重啟zabbix客戶端
[root@node2 templates]# /etc/init.d/zabbix_agentd restart
5、導入mysql的監控模板
模板需要先導入桌面
ubuntu@ubuntu:~$ sudo sz /var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml
6、導入出錯
出現“標簽無效 "/zabbix_export/date": "YYYY-MM-DDThh:mm:ssZ" 預計”,如圖2所示:
圖2
解決方法:百度了一下說將zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml導入zabbix2.4版本中再導出。之後將新的導出xml導入到3.2中問題解決。
7、關聯模板Template Percona MySQL Server
8、查看監控圖像,出數據如圖4、圖5所示:
9、碰到問題:
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
[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