main:重构指标系统并切换为 Redis 方案

变更内容:
- 重构指标系统实现,支持基于 Redis 的多实例指标管理。
- 替换原有的 Pushgateway 和 Redis Exporter 方案。
- 更新 Prometheus 配置,适配新的指标抓取方式。
- 添加 Redis 指标相关配置和告警规则文件。
- 更新 Dockerfile 和 docker-compose 文件,移除多余服务,精简配置。
- 编写 `metrics_unified.py` 模块及单元测试。
- 修复部分代码中的冗余和格式问题。
This commit is contained in:
2026-02-02 13:30:28 +08:00
parent 5921f71756
commit 3254fdc3f0
11 changed files with 1047 additions and 94 deletions

View File

@@ -8,27 +8,13 @@ global:
# 抓取配置
scrape_configs:
# 方案1从 Pushgateway 抓取指标(推荐
- job_name: 'pushgateway'
honor_labels: true
static_configs:
- targets: ['pushgateway:9091']
metric_relabel_configs:
# 保留 instance 标签
- source_labels: [instance]
target_label: instance
action: replace
# 方案2从 Redis Exporter 抓取指标
- job_name: 'redis-exporter'
static_configs:
- targets: ['redis-exporter:8001']
# 直接从应用实例抓取(如果有多个实例,需要配置服务发现)
- job_name: 'app'
# 从应用实例抓取指标Redis 统一指标方案
# 应用通过 /metrics 端点从 Redis 读取并导出 Prometheus 格式指标
- job_name: 'functional-scaffold'
static_configs:
- targets: ['app:8000']
metrics_path: '/metrics'
scrape_interval: 10s
# Prometheus 自身监控
- job_name: 'prometheus'
@@ -37,7 +23,7 @@ scrape_configs:
# 告警规则文件
rule_files:
- '/etc/prometheus/rules/*.yml'
- '/etc/prometheus/rules/*.yaml'
# Alertmanager 配置(可选)
# alerting: