Prometheus监控MySQL

这里只是对prometheus监控MySQL的配置过程做个记录,方便以后查阅。

1.下载mysqld_exporter

1
https://github.com/prometheus/mysqld_exporter

2.配置mysqld_exporter

1
2
tar xf downloads/mysqld_exporter-0.11.0.linux-amd64.tar.gz
mv -f mysqld_exporter-0.11.0.linux-amd64 mysqld_exporter

3.配置mysql数据库用于prometheus监控的账户权限

1
2
3
4
mysql> use mysql; 
mysql> GRANT REPLICATION CLIENT,PROCESS ON *.* TO 'prometheus'@'%' identified by '1111111111111111';
mysql> GRANT SELECT ON *.* TO 'prometheus'@'%';
mysql> FLUSH PRIVILEGES;

正在使用的权限

1
mysql> GRANT SELECT,REPLICATION CLIENT,PROCESS ON *.* TO 'prometheus'@'%' identified by '1111111111111111';

4.配置mysql数据库认证文件.my.cnf

1
2
3
4
5
6
cat mysqld_exporter/.my.cnf
[client]
user=prometheus
password=1111111111111111
host=rm-2zemw424285j5yox8.mysql.rds.aliyuncs.com
port=3306

5.启动mysqld_exporter

1
/work/admin/mysqld_exporter/mysqld_exporter --config.my-cnf="/work/admin/mysqld_exporter/.my.cnf"

6.prometheus配置

1
2
3
4
5
6
- job_name: 'ops'
static_configs:
- targets: ['192.168.6.216:9100']
labels: {cluster: 'product',type: 'basic',env: 'ops',job: 'ops',export: 'ops'}
- targets: ['192.168.6.216:9104']
labels: {cluster: 'product',type: 'middle',env: 'bj-server-mysql',job: 'bj-server-mysql',export: 'bj-server-mysql-exporter'}

重启prometheus

如果开启了api管理功能,可以如下方式热加载配置

1
curl -X POST http://127.0.0.1:9090/-/reload

7.grafana出图

推荐使用9342

效果如下

-------------本文结束感谢您的阅读-------------