prometheus+grafana+mysql_exporter監(jiān)控

一、前言

上篇文章已經(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)控。

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容