Prometheus-mysql-监控

Prometheus-mysql-监控

mysql创建用户并授权

1
2
3
4
drop user 'exporter'@'localhost';
create user 'exporter'@'localhost' identified by '123456';
GRANT REPLICATION CLIENT,PROCESS,SELECT ON *.* TO 'exporter'@'localhost' ;
flush privileges;

mysql-exporter配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# client.cnf
cat << EOF >/opt/mysqld_exporter/.client.cnf
[client]
user=exporter
password=123456
EOF

# systemctl配置
cat << EOF >/usr/lib/systemd/system/mysqld_exporter.service
[Unit]
Description= Prometheus MySQL Exporter
Wants=network-online.target
After=network-online.target

[Service]
User=root
Group=root
Type=simple
Restart=always
ExecStart=/opt/mysqld_exporter/mysqld_exporter \
--config.my-cnf /opt/mysqld_exporter/.client.cnf \
--web.listen-address=0.0.0.0:51235

[Install]
WantedBy=multi-user.target
EOF

prometheus配置

1
2
3
4
5
# 增加配置并重启prometheus
prometheus 配置
- job_name: mysql
static_configs:
- targets: ['172.31.40.125:51235', '172.31.36.28:51235']

grafana配置

grafana.com/grafana/dashboards/

alert-manager告警配置

待补充