Prometheus Pushgateway
Prometheus 的拉取模型(pull model)要求被监控目标必须持续运行并暴露 HTTP /metrics 端点。但有些场景不适合这种模式: 批处理作业(Batch Job):运行几秒或几分钟就退出,Prometheus 来不及抓取 CronJob:定时执行,完成后进程消失 短暂任务:数据管道、一次性脚本 Pushgateway 就是为这类场景设计的中间缓冲层。 工作原理 Batch Job → POST metrics → Pushgateway ← scrape ← Prometheus → Grafana 批处理作业完成后,主动将指标 推送(push) 到 Pushgateway Pushgateway 将指标持久保存在内存中 Prometheus 按照正常 pull 机制定期抓取 Pushgateway 的 /metrics 端点 Grafana 查询 Prometheus 展示数据 安装(Kubernetes) apiVersion: apps/v1 kind: Deployment metadata: name: pushgateway spec: replicas: 1 template: spec: containers: - name: pushgateway image: prom/pushgateway:v1.11.0 ports: - containerPort: 9091 默认端口 9091,Web UI 可以查看当前存储的所有指标。 ...