1、首先需要增加授權
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'XXXXXXXX' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';
flush privileges;
2、安裝mysqld_exporter
tar xzvf mysqld_exporter-0.12.1.linux-amd64.tar.gz
mv mysqld_exporter-0.12.1.linux-amd64.tar.gz mysqld_exporter
3、啟動
cat start.sh
export DATA_SOURCE_NAME='root:autodgpmysql@(localhost:3306)/'
./mysqld_exporter --web.listen-address=0.0.0.0:8089 --config.my-cnf /etc/my.cnf
監控指標:
collect.slave_status
Collect from SHOW SLAVE STATUS (Enabled by default)
collect.slave_hosts
Collect from SHOW SLAVE HOSTS
--collect.slave_status \
--collect.slave_hosts \
4、配置prometheus.yml
- job_name: 'mysqld'
static_configs:
- targets: ['localhost:8089’]
設置報警規則
groups:
- name: GaleraAlerts
rules:
- alert: MySQLReplicationNotRunning
expr: mysql_slave_status_slave_io_running == 0 or mysql_slave_status_slave_sql_running
== 0
for: 2m
labels:
severity: critical
annotations:
description: Slave replication (IO or SQL) has been down for more than 2 minutes.
summary: Slave replication is not running
Grafana服務
http://monitor_host:3000訪問Grafana網頁界面(缺省的帳號/密碼為admin/admin)
然后我們到Data Sources頁面添加數據源
Granfana 導入Mysql 監控圖表
監控展示
