Ubuntu下Zabbix結合percona監控mysql數據

按道理來講zabbix就自帶的MySQL插件來監控mysql數據庫,可是你會發現,自帶的mysql監控項是不多的,根本知足不了公司的需求。
因爲它自己自帶的模板太過簡單了,因此須要作更詳細的監控,而percona就提供了這個詳細監控的模版以及腳本,解決了監控不全面的問題。
percona插件是安裝在zabbix-agent端的
php

一、percona插件安裝:

首先須要下載php依賴:node

ubuntu@ubuntu:~$ apt-get install php

一、官網下載percona包

https://www.percona.com/downloads/percona-monitoring-plugins/
2019-03-25 14-02-49屏幕截圖.pngVersion: 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

三、安裝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

二、編輯配置文件

一、添加模板文件路徑

ubuntu@ubuntu:~$ sudo mv /var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf /etc/zabbix_agentd.conf.d/

二、修改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' ','`

linux

mysql -u用戶名 -p密碼,這裏根據本身實際狀況修改sql

三、修改 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';


數據庫

四、重啓zabbix客戶端

[root@node2 templates]# /etc/init.d/zabbix_agentd restart

五、導入mysql的監控模板

模板須要先導入桌面ubuntu

ubuntu@ubuntu:~$ sudo sz /var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.7.xml


                                                                   圖1
vim

六、導入出錯

出現「標籤無效 "/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

七、關聯模板Template Percona MySQL Server

2019-03-25 14-35-28屏幕截圖.png
能夠發現自帶的監控項就一百多了,圖形四十多個。

                                                                 圖3
測試

八、查看監控圖像,出數據如圖四、圖5所示:

 
                                                                 圖4
 

九、碰到問題:

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
相關文章
相關標籤/搜索