【Prometheus】集成MySQL
安装mysql_exporter
tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz
- 设置软链接
ln -s mysqld_exporter-0.12.1.linux-amd64 mysqld_exporter
- MySQL创建mysqld_exporter用户
mysql -uroot -p
mysql>CREATE USER 'mysqld_exporter'@'%' IDENTIFIED BY 'SuccessHR_2021' WITH MAX_USER_CONNECTIONS 3;
mysql>GRANT PROCESS, REPLICATION CLIENT, SELECT ON *.* TO 'mysqld_exporter'@'%';
mysql>flush privileges;
- 创建.my.cnf文件
vim .my.cnf
[client]
user=mysqld_exporter
password=SuccessHR_2021
- 启动mysql_exporter
export DATA_SOURCE_NAME='mysqld_exporter:SuccessHR_2021@(172.16.30.181:3306)/'
nohup ./mysqld_exporter --config.my-cnf="/usr/local/mysqld_exporter/.my.cnf" &
Prometheus配置
- prometheus.yml配置
- job_name: 'mysql_exporter'
static_configs:
- targets:
- 172.16.30.184:9104
- 重启prometheus
systemctl restart prometheus
- 查看prometheus运行状态
systemctl status prometheus
- 查看mysql_exporter是否运行正常:http://121.41.206.73:9090/targets
Grafana配置
- 添加Prometheus数据源
- 添加dashboard,并选择之前配置好的Prometheus数据源
dashboard地址:https://grafana.com/grafana/dashboards/7362
评论区