# Prometheus Exporter 采集验证报告 **验证时间**: 2026-01-03 03:45 **验证对象**: Gitea Actions Exporter -> Prometheus 数据采集 --- ## ✅ 验证结果总结 | 检查项 | 状态 | 详情 | |--------|------|------| | **Prometheus Pod** | ✅ Running | prometheus-67f47fc6fb-7pkbf (运行 10 分钟) | | **Exporter Pod** | ✅ Running | gitea-actions-exporter-7ffccb4f95-cvck4 | | **网络连通性** | ✅ 正常 | Prometheus 可访问 Exporter | | **Exporter 指标** | ✅ 正常 | 指标正常暴露 | | **ServiceMonitor** | ✅ 已创建 | namespace: observability, labels: release=monitoring | | **Additional Scrape Configs** | ✅ Secret 已创建 | 配置正确 | | **Prometheus CRD 配置** | ✅ 已配置 | additionalScrapeConfigs 已设置 | | **Prometheus 采集** | ❌ **未生效** | Target 列表中未找到 gitea-actions-exporter | --- ## 🔍 详细验证过程 ### 1. Prometheus Pod 状态 ✅ ```bash NAME READY STATUS AGE prometheus-67f47fc6fb-7pkbf 1/1 Running 10m ``` - Pod 已重启并运行正常 - 无错误日志 ### 2. 网络连通性测试 ✅ **从 Prometheus Pod 访问 Exporter**: ```bash $ kubectl exec -n monitoring prometheus-67f47fc6fb-7pkbf -- \ wget -qO- http://gitea-actions-exporter.gitea-runner.svc.cluster.local:9999/metrics # 成功返回指标: gitea_actions_pending_jobs{instance="http://192.168.1.83:33000"} 0.0 gitea_actions_running_jobs{instance="http://192.168.1.83:33000"} 0.0 gitea_actions_total_jobs{instance="http://192.168.1.83:33000"} 0.0 ... ``` ✅ **结论**: Prometheus 可以正常访问 Exporter,网络无问题 ### 3. Prometheus Targets 检查 ❌ ```bash $ curl 'http://localhost:9090/api/v1/targets' | grep gitea Total targets: 26 Gitea targets: 0 ❌ ``` ❌ **问题**: Prometheus 的 target 列表中没有 gitea-actions-exporter ### 4. Prometheus 查询测试 ❌ ```bash $ curl 'http://localhost:9090/api/v1/query?query=gitea_actions_pending_jobs' { "status": "success", "data": { "resultType": "vector", "result": [] ❌ } } ``` ❌ **问题**: Prometheus 没有采集到任何 Gitea Actions 指标 ### 5. Additional Scrape Configs 检查 ✅ **Secret 内容**: ```yaml - job_name: 'gitea-actions-exporter' static_configs: - targets: ['gitea-actions-exporter.gitea-runner.svc.cluster.local:9999'] scrape_interval: 30s scrape_timeout: 10s metrics_path: /metrics ``` ✅ **配置正确** **Prometheus CRD 配置**: ```yaml spec: additionalScrapeConfigs: key: prometheus-additional.yaml name: additional-scrape-configs ``` ✅ **已正确配置** --- ## ⚠️ 根本原因分析 ### 问题:Prometheus Operator 未应用 Additional Scrape Configs **可能原因**: 1. **Prometheus Operator 版本问题** - 某些版本的 Prometheus Operator 对 `additionalScrapeConfigs` 的处理有 bug - 可能需要重启 Prometheus Operator 2. **Secret 未正确挂载到 Pod** - Pod 描述中未找到 `additional-scrape-configs` volume - 可能是 Operator 未正确处理 Secret 3. **配置重载未触发** - Prometheus Operator 可能没有检测到配置变更 - 需要手动触发重载 --- ## 🛠️ 解决方案 ### 方案 1: 重启 Prometheus Operator(推荐)⭐⭐⭐⭐⭐ Prometheus Operator 负责将配置应用到 Prometheus Pod,重启它可能解决问题。 ```bash # 1. 查找 Prometheus Operator kubectl get pods -n observability -l app.kubernetes.io/name=prometheus-operator # 2. 重启 Operator kubectl delete pod -n observability # 3. 等待 Operator 重新创建 Prometheus 配置 # (约 1-2 分钟) # 4. 验证 kubectl port-forward -n monitoring svc/prometheus 9090:9090 curl 'http://localhost:9090/api/v1/targets' | grep gitea ``` ### 方案 2: 使用 PodMonitor(替代方案)⭐⭐⭐⭐ PodMonitor 直接监控 Pod,不依赖 Service: ```yaml apiVersion: monitoring.coreos.com/v1 kind: PodMonitor metadata: name: gitea-actions-exporter namespace: observability labels: release: monitoring spec: namespaceSelector: matchNames: - gitea-runner selector: matchLabels: app: gitea-actions-exporter podMetricsEndpoints: - port: metrics interval: 30s path: /metrics ``` 应用: ```bash kubectl apply -f gitea-actions-exporter/podmonitor.yaml ``` ### 方案 3: 手动添加到 Prometheus ConfigMap(最后手段)⭐⭐⭐ 如果 Operator 方式不工作,直接编辑 Prometheus ConfigMap: ```bash # 1. 编辑 ConfigMap kubectl edit configmap prometheus-prometheus-kube-prometheus-prometheus-rulefiles-0 -n monitoring # 2. 在 scrape_configs 部分添加: scrape_configs: - job_name: 'gitea-actions-exporter' static_configs: - targets: ['gitea-actions-exporter.gitea-runner:9999'] # 3. 重启 Prometheus kubectl delete pod -n monitoring prometheus-67f47fc6fb-7pkbf ``` --- ## 📊 当前工作方案:简化版 Dashboard **好消息**: 即使 Prometheus 未采集 Exporter 指标,简化版 Dashboard 仍然可用! ### ✅ 当前可用功能(使用 kube-state-metrics) - Gitea Runner 副本数监控 - Pod 状态监控 - HPA 配置监控 - Pod 重启次数 - 资源请求配置 **Dashboard URL**: http://localhost:30300/d/af901k0wj05q8c/gitea-runner-autoscaling-simplified --- ## 🎯 推荐立即执行 ### 步骤 1: 查找并重启 Prometheus Operator ```bash # 查找 Operator(可能在不同命名空间) kubectl get pods -A | grep prometheus-operator # 示例输出: # observability prometheus-operator-xxx 1/1 Running ... # 重启它 kubectl delete pod -n ``` ### 步骤 2: 等待 2 分钟后验证 ```bash kubectl port-forward -n monitoring svc/prometheus 9090:9090 # 检查 targets curl -s 'http://localhost:9090/api/v1/targets' | \ python3 -c "import sys,json; d=json.load(sys.stdin); \ print([t['labels']['job'] for t in d['data']['activeTargets'] if 'gitea' in t['labels']['job']])" ``` ### 步骤 3: 如果成功,测试指标查询 ```bash curl -s 'http://localhost:9090/api/v1/query?query=gitea_actions_pending_jobs' | \ python3 -m json.tool ``` ### 步骤 4: 更新 Dashboard 添加队列监控 如果指标采集成功,可以添加以下面板到 Dashboard: ```json { "title": "Gitea Actions 队列状态", "targets": [ { "expr": "gitea_actions_pending_jobs{instance=\"http://192.168.1.83:33000\"}", "legendFormat": "等待任务" }, { "expr": "gitea_actions_running_jobs{instance=\"http://192.168.1.83:33000\"}", "legendFormat": "运行中任务" } ] } ``` --- ## 🔄 临时解决方案:手动查询 Exporter 在 Prometheus 采集生效之前,可以直接查询 Exporter: ```bash # 端口转发到 Exporter kubectl port-forward -n gitea-runner svc/gitea-actions-exporter 9999:9999 # 直接访问指标 curl http://localhost:9999/metrics | grep gitea_actions # 或在浏览器中访问 open http://localhost:9999/metrics ``` --- ## 📝 总结 ### 已验证 ✅ 1. ✅ Exporter Pod 运行正常 2. ✅ Exporter 正常暴露指标 3. ✅ Prometheus 可以访问 Exporter(网络通) 4. ✅ ServiceMonitor 配置正确 5. ✅ Additional Scrape Configs Secret 已创建 6. ✅ Prometheus CRD 配置正确 ### 问题 ❌ 1. ❌ Prometheus 未将 Exporter 添加到 target 列表 2. ❌ Prometheus 未采集到任何 Gitea Actions 指标 ### 根本原因 ⚠️ **Prometheus Operator 未正确应用 `additionalScrapeConfigs`** ### 推荐解决方案 🔧 **重启 Prometheus Operator**(最简单有效) ### 当前可用 ✅ **简化版 Dashboard 正常工作**(使用 kube-state-metrics 指标) --- **下一步**: 执行方案 1(重启 Prometheus Operator)并验证结果 **预计修复时间**: 2-3 分钟 **临时方案**: 使用简化版 Dashboard + 手动查询 Exporter