Prometheus+Grafana可视化监控【MySQL状态】
Prometheus+Grafana部署请参考上篇文章: Prometheus+Grafana部署:
一、Prometheus监控MySQL
1、创建MySQL监控用户
mysql> create user "prometheus"@"%" identified by 'NTQ34tg*@19VF';
mysql> grant select,replication client,process ON *.* to "prometheus"@"%";
mysql> flush privileges;
2、安装mysqld_exporter
wget https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz
tar zxf mysqld_exporter-0.14.0.linux-amd64.tar.gz
mv mysqld_exporter-0.14.0.linux-amd64 /usr/local/mysqld_exporter
3、配置mysql连接信息
cd /usr/local/mysqld_exporter
vim .my.cnf
[client]
user=prometheus
password=NTQ34tg*@19VF
启动
nohup ./mysqld_exporter --config.my-cnf=.my.cnf &
默认端口为9104
netstat -anput |grep 9104
4、prometheus服务器配置,编辑prometheus.yml文件
- job_name: "MySQL_百度saas"
static_configs:
- targets: ["xxxx.xxxx.xxx.xxx:9104"] # IP地址+端口
注意缩进和上面节点保持对齐,如下:
systemctl restart prometheus.service
5、验证
prometheus页面验证
二、Grafana添加MySQL监控模板
这里使用MySQL的模板ID:7362