文章目录
- 一、Prometheus监控MySQL
- 二、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
4、配置systemd管理
cat > /usr/lib/systemd/system/mysqld_exporter.service << EOF
[Unit]
Description=mysqld_exporter Service
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/mysqld_exporter/mysqld_exporter --config.my-cnf=/usr/local/mysqld_exporter/.my.cnf
ExecReload=/bin/kill -HUP \$MAINPID
Restart=on-failure
RestartSec=30s
[Install]
WantedBy=multi-user.target
EOF
启动并加入开机自启动
systemctl enable mysqld_exporter --now
systemctl status mysqld_exporter
默认端口为9104
netstat -anput |grep 9104
5、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