Prometheus 监控 MySQL
2019-06-02 本文已影响0人
awker
1、下载 mysql exporter
// 下载地址:https://github.com/prometheus/mysqld_exporter/releases
# ls mysqld_exporter-0.11.0.linux-amd64.tar.gz
mysqld_exporter-0.11.0.linux-amd64.tar.gz
# tar xvf mysqld_exporter-0.11.0.linux-amd64.tar.gz -C /usr/local/
2、配置 mysqld_exporter
2.1 添加账号授权给 mysqld exporter
CREATE USER 'exporter'@'192.168.22.11' IDENTIFIED BY '123456' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'192.168.22.11';
2.2 配置 mysqld_exporter service 文件
# vim /etc/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter
After=network.target
[Service]
Environment=DATA_SOURCE_NAME=exporter:123456@(192.168.22.22:3306)/
Restart=on-failure
ExecStart=/usr/local/mysqld_exporter-0.11.0.linux-amd64/mysqld_exporter
[Install]
WantedBy=multi-user.target
# systemctl daemon-reload
# systemctl start mysqld_exporter
# systemctl status mysqld_exporter
Environment=DATA_SOURCE_NAME=exporter:123456@(192.168.22.22:3306)/ --> 设置 DATA_SOURCE_NAME 变量,包含数据库信息:用户名:密码@(mysql地址:mysql端口)/
3、查看采集到的数据
4、添加 prometheus 监控
# vim prometheus.yml
- file_sd_configs:
- files:
- 'configs/mysql.yml'
job_name: MySQL
metrics_path: /metrics
relabel_configs:
- source_labels: [__address__]
regex: (.*)
target_label: instance
replacement: $1
- source_labels: [__address__]
regex: (.*)
target_label: __address__
replacement: $1:9104
# vim configs/mysql.yml
- labels:
service: mysql_192.168.22.22
targets:
- 192.168.22.11
5、 配置 grafana 展示
从 https://grafana.com/dashboards/6239 下载 json 文件,导入 grafana,根据需求调整即可。