MySQL
MySQL的监控比较简单,因为官方提供了exporter,只需要到数据库内新建一个用户授予几个权限即可。
授权
CREATE USER 'exporter'@'localhost' IDENTIFIED BY 'exporter' WITH MAX_USER_CONNECTIONS 3;
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'localhost';配置exporter
# 下载
cd /tmp
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.0/mysqld_exporter-0.12.0.linux-amd64.tar.gz
tar xvf mysqld_exporter-0.12.0.linux-amd64.tar.gz -C /ops
# 编写systemd service 文件
vi /usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description=mysqld_exporter
After=network.target
[Service]
Type=simple
Environment=DATA_SOURCE_NAME=exporter:exporter@(localhost:3306)/
ExecStart=/ops/mysqld_exporter-0.12.0.linux-amd64/mysqld_exporter --web.listen-address=:9104
Restart=on-failure
[Install]
WantedBy=multi-user.target
# 启动与自启动
systemctl daemon-reload
systemctl start mysqld_exporter
systemctl enable mysqld_exporter默认端口为9104,还需防火墙放行:
配置Prometheus
重启Prometheus生效
Last updated
Was this helpful?