最新原文:https://www.cnblogs.com/uncleyong/p/13192456.html
架构
在需要监控的mysql上安装 node_exporter和 mysqld_exporter
架构示意图:https://processon.com/diagraming/6028831e079129342249700e
下载
https://github.com/prometheus/mysqld_exporter/releases
安装、配置、验证
解压
tar -zxvf mysqld_exporter-0.12.1.linux-amd64.tar.gz -C /usr/local/
修改配置文件
vim .my.cnf
添加获取mysql监控数据的账号,如果不写端口,默认为3306
(根据自己安装的mysql实际情况填写)
[client] user=root password=mysql123 port=3206
也可以另外创建用户并授权
GRANT REPLICATION CLIENT, PROCESS ON *.* TO 'mysql_exporter'@'localhost' identified by '123456'; GRANT SELECT ON performance_schema.* TO 'mysql_exporter'@'localhost'; flush privileges;
启动服务
./mysqld_exporter --config.my-cnf=".my.cnf"
验证:http://IP:9104/metrics
搜索:max_connections
在prometheus.yml中加入job
- job_name: 'mysql' static_configs: - targets: ['localhost:9104']
重启prometheus:nohup /usr/local/prometheus-2.19.1.linux-amd64/prometheus --config.file=/usr/local/prometheus-2.19.1.linux-amd64/prometheus.yml &
http://ip:9090/targets
mysql的状态变成up了
grafana导入模板
https://grafana.com/grafana/dashboards/7362
导入
效果(报告含义不清楚的可以咨询作者)