1.mysqld的metric指标采集插件下载
官网地址
https://github.com/prometheus/mysqld_exporter/releases/
mysqld_exporter取得及解压
# wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.12.1/mysqld_exporter-0.12.1.linux-amd64.tar.gz
# tar zxf mysqld_exporter-0.12.1.linux-amd64.tar.gz
2.mysql中创建一个Prometheus收集数据的账号
mysql> create user 'promethues'@'localhost' IDENTIFIED BY 'promethues1';
Query OK, 0 rows affected (0.00 sec)
mysql> grant select,replication client,process on *.* to 'promethues'@'localhost';
Query OK, 0 rows affected (0.00 sec)
※这里的的localhost不是指mysqld服务的ip,是指mysqld_exporter的ip,因为promethues服务来找mysqld获取数据时,是先找到mysqld_exporter,然后mysqld_exporter再去mysqld获取数据。所以要保证mysqld_exporter的ip可以连接mysqld服务。
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
3.在mysqld_exporter组件中配置mysql信息
# cp -p mysqld_exporter/.my.cnf mysqld_exporter/.my.cnf.org
# vi mysqld_exporter/.my.cnf
[client]
user=promethues
password=promethues1
4.启动mysqld_exporter组件,配置promethues.yml,并指定mysql账号信息文件
# ./mysqld_exporter --help
# nohup ./mysqld_exporter --web.listen-address=":9104" --config.my-cnf=".my.cnf" &> /dev/null &
## 添加以下配置:vim prometheus.yml
- job_name: 'mysqld'
static_configs:
- targets: ['localhost:9104']
5.在Grafana添加mysqld模板
Grafana查找MySQL相关的模板,参考签署JOSN文件导入,即可生成仪表盘