mysqld_exporter
mysqld_exporter是Prometheus对MySQL的监控插件
下载地址
这里要选择自己合适的版本
下载并解压
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz
ARM版本
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-arm64.tar.gz
tar -zxvf mysqld_exporter-0.12.1.linux-arm64.tar.gz
创建mysqld_exporter配置文件
cd mysqld_exporter-0.12.1.linux-arm64/
vim .my.cnf
[client]
host=localhost
port=3306
user=mysqld_exporter
password=Fwigff+A0T0
创建Prometheus中的mysqld_exporter配置文件
vim mysql.yml
- labels:
service: mysql
targets:
- localhost
创建mysqld_exporter数据库用户并配置数据库权限
create user 'mysqld_exporter'@'%' identified by 'Fwigff+A0T0' with MAX_USER_CONNECTIONS 3 ;
grant process,replication client,select on *.* to 'mysqld_exporter'@'%';
FLUSH PRIVILEGES;
配置启动文件
vim /etc/systemd/system/mysqld_exporter.service
[Unit]
Description=Prometheus Monitoring System
Documentation=Prometheus Monitoring System
[Service]
ExecStart=/opt/monitor/service/mysqld_exporter-0.12.1.linux-arm64/mysqld_exporter
--config.my-cnf=/opt/monitor/service/mysqld_exporter-0.12.1.linux-arm64/.my.cnf
[Install]
WantedBy=multi-user.target
刷新文件
systemctl daemon-reload
启动命令
systemctl start mysqld_exporter #启动
systemctl stop mysqld_exporter #停止
systemctl restart mysqld_exporter #重启
systemctl status mysqld_exporter #查看状态
配置Prometheus配置文件
vim prometheus.yml
- file_sd_configs:
- files:
- mysql.yml
job_name: MySQL
scrape_interval: 5s
metrics_path: /metrics
relabel_configs:
- source_labels: [__address__]
regex: (.*)
target_label: instance
replacement: $1
- source_labels: [__address__]
regex: (.*)
target_label: __address__
replacement: $1:9104
重启Prometheus
配置Grafana
输入7362