一、概述
線上有2台阿裡雲RDS,一台測試,一台生産。監控是預設每5分鐘采集一次,如果要調整為更快,需要收費!
二、mysqld_exporter安裝
下載下傳頁面
https://github.com/prometheus/mysqld_exporter/releases
下載下傳最新版本
https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
這裡直接登入到prometheus伺服器
# 解壓
tar zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /data
mv mysqld_exporter-0.12.1.linux-amd64 /data/mysqld_exporter
# 建立目錄
mkdir -p /data/mysqld_exporter/conf
複制
編輯配置檔案
cd /data/mysqld_exporter/conf
vi test.cnf
複制
内容如下:
[client]
user=admin
password=admin123
port=3306
host=rdsxx.mysql.rds.aliyuncs.com
複制
注意:這裡推薦使用高權限賬号。
啟動程序
cd /data/mysqld_exporter
nohup ./mysqld_exporter --config.my-cnf="conf/test.cnf" --web.listen-address=":9104" &
複制
生産RDS,也是類似步驟。建立一個 prod.cnf,填寫對應的資訊。
啟動程序
cd /data/mysqld_exporter
nohup ./mysqld_exporter --config.my-cnf="conf/prod.cnf" --web.listen-address=":9105" &
複制
觀察是否有報錯資訊,如果沒有報錯資訊,就可以封裝service服務了
通路metrics
curl http://localhost:9104/metrics curl http://localhost:9105/metrics
複制
如果資料輸出正常,則表示成功。
三、promethus增加job
vim /data/prometheus/prometheus.yml
複制
最後一行添加
- job_name: 'mysqld_exporter'
static_configs:
- targets: ['localhost:9104']
labels:
instance: 測試
- targets: ['localhost:9105']
labels:
instance: 生産
複制
最後,重新開機prometheus
確定mysqd_exporter狀态為UP

六、Grafana導入Dashboards
下載下傳json檔案
https://files.cnblogs.com/files/xiao987334176/MySQL%E7%9B%91%E6%8E%A7-rds.zip
解壓之後,裡面就是一個json檔案
點選import
上傳json檔案,設定Name,選擇prometheus,點選import
等待一段時間,資料多了之後,效果如下:
每個圖表,都有解釋。
其中要特别注意,連接配接使用率,高于80%,就表示RDS有異常了。
本文參考連結:
https://www.cnblogs.com/xiao987334176/p/11181033.html