在Prometheus架构中,exporter是负责收集数据并将信息汇报给Prometheus Server的组件,mysqld_exporter是常用的数据库监控工具。
一、mysqld_exporter的安装
1、mysql库创建相应用户并赋权:
create user 'exporter'@'%' identified by 'MONty_00';
GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%' WITH MAX_USER_CONNECTIONS 3;
flush privileges;
2、配置.my.cnf
.my.cnf默认放置在启动用户的家目录,启动时无需指定;也可以随意放置在任意目录,在启动时通过 --config.my-cnf={conf_dir}/.my.cnf
指定配置文件。
.my.cnf内容
[client]
host=127.0.0.1
port=3306
user=exporter
password=123456
3、启动mysqld_exporter
mysqld_exporter默认监听9104端口,启动命令如下:
./mysqld_exporter --config.my-cnf=/opt/mysqld_exporter-0.10.0.linux-amd64/.my.cnf
4、使用环境变量运行(不推荐)
使用环境变量运行时无需指定配置文件。