下载需要的版本
https://github.com/prometheus/mysqld_exporter/releases/tag/v0.13.0
登录mysql 创建给 监控的账户
mysql> GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'exporter'@'%' IDENTIFIED BY 'Test123456!' WITH MAX_USER_CONNECTIONS 3;
Query OK, 0 rows affected, 1 warning (0.10 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> exit
创建监控文件
tar zxvf mysqld_exporter-0.13.0.linux-amd64.tar.gz
mv mysqld_exporter-0.13.0.linux-amd64 /usr/local/mysql_exporter
cd /usr/local/mysql_exporter/
创建一个.my.cnf的文件,文件内容如下
[client]
user=exporter
password=Test123456!
启动监控,默认端口9104
nohup ./mysqld_exporter --config.my-cnf=".my.cnf" &
修改prometheus.yml文件
- job_name: 'db_server'
static_configs:
- targets: ['192.168.1.108:9104']
导入模板 7362