Prometheus(也叫普羅米修斯)官網:https://prometheus.io/docs/introduction/overview/
Grafana官網:https://grafana.com/enterprise
特征
普羅米修斯的主要特點是:
組件
Prometheus生態(tài)系統(tǒng)由多個組件組成,其中許多組件是可選的:
大多數(shù)Prometheus組件都是用Go編寫的,因此很容易構建和部署為靜態(tài)二進制文件。
今天本文重點給大家介紹使用Grafana+Prometheus監(jiān)控mysql性能的方法詳細介紹。
#cmd /usr/local
今天講一下如何監(jiān)控服務器中的mysql數(shù)據(jù)庫的性能
一、數(shù)據(jù)庫操作
1.mysql啟動
#service mysqld start #啟動數(shù)據(jù)庫 #service mysqld stop #關閉數(shù)據(jù)庫 #service mysqld restart #重啟數(shù)據(jù)庫
2、進入 mysql
mysql -u root -p
3、新增監(jiān)控 mysql 賬號
#use mysql #GRANT ALL PRIVILEGES ON *.* TO '帳號'@'localhost' identified by '密碼';br>#flush privileges; #刷新
二、Prometheus 搭建
這里會給大家提供一個干凈的普羅米修斯數(shù)據(jù)庫的壓縮包,大家解壓就好
將壓縮包放到服務器中
#cmd /usr/local
解壓
#tar -zxvf prometheus-xxxxx
現(xiàn)在修改一下普羅米修斯的配置文件,在他的安裝目錄中有一個prometheus.yml文件,添加
- job_name: 'linux' static_configs: - targets: ['localhost:9100'] - job_name: 'mysql' static_configs: - targets: ['localhost:9104']
這里大家注意一個地方,要嚴格按照普羅米修斯的格式,不要隨意添加空格和縮進,不然會出錯
增加這一步的意義是給普羅米修斯開放兩個端口,用于Grafana監(jiān)控
設置文件權限:#chmod 777 prometheus.yml 從配置文件中啟動
#./prometheus --config.file=prometheus.yml
設置linux系統(tǒng)端口
firewall-cmd --list-ports ##列出開放的端口 firewall-cmd --add-port=9090/tcp --permanent ##永久添加 9090 端口 firewall-cmd --add-port=9100/tcp --permanent ##永久添加 9100 端口 firewall-cmd --add-port=9104/tcp --permanent ##永久添加 9104 端口 firewall-cmd --list-ports ##列出開放的端口 systemctl stop firewalld ##關閉防火墻 systemctl start firewalld ##開啟防火墻 systemctl status firewalld ##查看防火墻狀態(tài) systemctl restart firewalld ##重啟防火墻 systemctl disable firewalld ##開機關閉防火墻,即永久關閉
windows 訪問:http://192.168.xx.xx:9090 statue-targets 查看端口狀態(tài)為up為成功
三、mysqld_exporter 搭建
這里也會提供一個壓縮包給大家
1、上傳 mysqld_exporter 至 local 下 2、解壓 tar -zxvf mysqld_exporter-xxxxxx 3、在/usr/local/mysql_exporter 下創(chuàng)建一個.my.cnf 配置文件,寫上創(chuàng)建的用戶名和密碼
[client] user=xxxx password=xxxx
4、啟動服務
在/usr/local/mysql_exporter 下啟動./mysqld_exporter --config.my-cnf=my.cnf
5、安裝lsof
#yum install lsof
6、查看 9104 端口占用情況
lsof -i:9104
7、
關閉進程 #kill -9 進程號
8、重啟 Prometheus
四、Node_exporter 監(jiān)控 linux
這里會給大家提供一個壓縮包
1、上傳至/usr/local/ 2、解壓 tar -zxvf node_exporter-xxxxx 3、在/usr/local/node_exporter 目錄下,啟動 ./node_exporter 4、通過瀏覽器訪問 http://服務器 ip:9100/metrics 可以看到監(jiān)控的數(shù)據(jù)
此時查看任務項均處于UP狀態(tài)這樣我們的監(jiān)控平臺就搭建起來了,至于Gafana如何與普羅米修斯數(shù)據(jù)庫連接不做解釋,需要的請看上幾篇文章
附linux效果圖
最后給大家附上本文所需壓縮包,以及Grafana基于普羅米修斯數(shù)據(jù)庫的監(jiān)控模板
鏈接: https://pan.baidu.com/s/124sJ0cv3zghK02n4W-rSZw 提取碼: w987
鏈接: https://pan.baidu.com/s/1l3pvorWAv3_VfwhL6G9PHg 提取碼: m7nw
總結
到此這篇關于使用Grafana+Prometheus監(jiān)控mysql性能的文章就介紹到這了,更多相關mysql性能監(jiān)控內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!