一、前言
上篇文章已經(jīng)概述了prometheus喝grafana的使用,沒了解的小伙伴們可以,在我的文章中查看下。這里不再贅述這兩個(gè)中間件的使用,直奔主題。
二、mysql_exporter是干什么的
mysql_exporter主要監(jiān)控Mysql數(shù)據(jù)庫的穩(wěn)定性、吞吐量、連接情況、緩沖池使用情況、查詢性能等各項(xiàng)指標(biāo),是我們壓測(cè)時(shí)常常需要監(jiān)控的一些指標(biāo)。
三、mysql_exporter安裝配置
最新版本下載鏈接:https://prometheus.io/download/
四、解壓
將壓縮包上傳到mysql服務(wù)器下的/server目錄下,然后解壓。
tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz
mv mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter
五、添加系統(tǒng)服務(wù)
vim /usr/lib/systemd/system/mysqld_exporter.service
添加如下內(nèi)容:
[Unit]
Description=https://prometheus.io
[Service]
ExecStart=/server/mysqld_exporter/mysqld_exporter --config.my-cnf=/server/mysqld_exporter/.my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
六、添加并授權(quán)mysql用戶
create user 'exporter'@'%' identified by '123456';
grant all on *.* to exporter@'%';
flush proivileges;
七、添加.my.cnf
vim /server/mysqld_exporter/.my.cnf
添加如下內(nèi)容:
[client]
host=10.28.60.219
user=exporter
password=123456
port=3306
說明:host為要監(jiān)控的mysql主機(jī),user和password為數(shù)據(jù)庫的用戶名密碼,port為數(shù)據(jù)庫的端口。
八、運(yùn)行mysql_exporter
systemctl daemon-reload
systemctl restart mysqld_exporter.service
systemctl enable mysqld_exporter.service
systemctl status mysqld_exporter.service
驗(yàn)證:
netstat -anp | grep 9104
默認(rèn)端口為9104
九、開啟防火墻
如果prometheus服務(wù)器telnet mysql服務(wù)器9104端口不通,則需要如下操作(關(guān)閉防火墻是不允許的,只能開放對(duì)應(yīng)端口)。
systemctl status firewalld
firewall-cmd --zone=public --add-port=9100/tcp --permanent
systemctl restart firewalld.service
firewall-cmd --reload
十、prometheus添加mysql監(jiān)控
vim prometheus.yml
添加如下:
- job_name: 'mysql監(jiān)控'
static_configs:
- targets: ['10.28.60.191:9104']
添加完成后,重啟prometheus.
pkill -9 prometheus
nohup ./prometheus --config.file="/server/prometheus/prometheus.yml" &
十一、添加grafana儀表
打開grafana后臺(tái),點(diǎn)擊'+'導(dǎo)入mysql_exporter的儀表id,選擇prometheus數(shù)據(jù)源。




至此,完美實(shí)現(xiàn)了prometheus+grafana+mysql_exporter監(jiān)控。