推理、部署与算力1400 字
Prometheus全面监控MySQL服务
·全库 388 / 611
《Prometheus全面监控MySQL服务》共 0.1 万字,通篇围绕 MySQL、Docker、数据库、监控 展开,归在「推理、部署与算力」这一层。
覆盖MySQLDocker数据库监控日志权限
适合要把模型跑起来,还得跑得起的人
目录骨架(3 节)
- 基本配置
- 安装MySQL Exporter
- 🎈Prometheus搭建
简介
在现代应用中,MySQL数据库的性能和稳定性对业务至关重要。有效的监控可以帮助预防问题并优化性能。Prometheus作为一款强大的开源监控系统,结合Grafana的可视化能力,可以提供全面的MySQL监控方案。
设置Prometheus
安装Prometheus
使用Docker安装Prometheus:
docker run -d --name=prometheus -p 9090:9090 prom/prometheus
此命令将Prometheus运行在本地的9090端口。
基本配置
创建一个Prometheus配置文件prometheus.yml:
global:
scrape_interval: 15s
scrape_configs:
- job_name: 'prometheus'
static_configs:
- targets: ['localhost:9090']
上面是官网提供的docker命令安装方案,官方直达链接,也可在Windows的docker中安装运行演示的,下面简单记录一下Windows安装的步骤细节
在指定路径下添加一下普罗米修斯的配置文件

文件的详细信息展示
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ["127.0.0.1:9090"]
- job_name: "mysql"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
# 这里做一个说明就是后续的两个服务本地都是直接通过docker的方式运行在容器中,由于docker容器网络配置的原因,即使在安装部署在同一个网络空间之下,同时给网路空间起不同的名称作为区分也不能实现浏览器的ip访问,因此下面这里使用网络ip的方式进行标记
static_configs:
- targets: ["192.168.28.3:9104"]
执行Windows的docker命令运行服务
这里需要注意一下就是地址配置的问题,需要配置成自己的文件地址
docker run -d -p 9090:9090 --network my-mysql-network -v "D:\Program_Files\prometheus\prometheus.yml:/etc/prometheus/prometheus.yml" prom/prometheus --config.file=/etc/prometheus/prometheus.yml


访问网址得到的页面展示信息

安装MySQL Exporter
MySQL Exporter是什么
MySQL Exporter是一个用于从MySQL数据库中收集指标并暴露给Prometheus的工具。
安装步骤
