按道理來講zabbix就自帶的MySQL插件來監控mysql數據庫,可是你會發現,自帶的mysql監控項是不多的,根本知足不了公司的需求。
因爲它自己自帶的模板太過簡單了,因此須要作更詳細的監控,而percona就提供了這個詳細監控的模版以及腳本,解決了監控不全面的問題。
percona插件是安裝在zabbix-agent端的
php
首先須要下載php依賴:node
ubuntu@ubuntu:~$ apt-get install php
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
mysql
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
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
ubuntu@ubuntu:~$ sudo mv /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix_agentd.conf.d/
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' ','`
linux
mysql -u用戶名 -p密碼,這裏根據本身實際狀況修改sql
ubuntu@ubuntu:~$ sudo vim /var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'root';
$mysql_pass = 'zabbix';
數據庫
[root@node2 templates]# /etc/init.d/zabbix_agentd restart
模板須要先導入桌面ubuntu
ubuntu@ubuntu:~$ sudo sz /var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml
出現「標籤無效 "/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中問題解決。
app
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