【问题标题】:Prometheus alerts based on non-periodic metrics from batch jobsPrometheus 基于批处理作业的非周期性指标的警报
【发布时间】:2020-08-26 07:17:31
【问题描述】:

我有一个 CronJob,它每 20 分钟运行一次,只收集构建持续时间超过特定值的 Jenkins 多分支作业上的活动构建,并将这些指标以构建持续时间作为值发布到 Prometheus Pushgateway。因此,如果构建完成,则不会推送此指标。我使用以下 Prometheus 配置设置了警报。

- alert: BuildDurationExceeded
    expr: jenkins_build_duration > 7200
    annotations:
      title: 'Build duration is too long at {{ $labels.instance }}'
      description: 'Build time of job {{ $labels.job }} on {{ $labels.instance }} exceeded 2h.'
    labels:
      severity: 'high'

以下是 Prometheus 中存在的一个指标值

jenkins_build_duration{branch="repo/branch_name",build_number="5",instance="https://jenkins-instance.com/",jenkins_url="https://jenkins-instance.com/job/repo/job/branch_name/5/",job="jenkins_metrics_job",job_name="repo"}    10000

使用此配置,一旦创建警报,它就会永久保留并且不会被删除。如果给定作业的指标不是周期性的,我该如何处理这种用例,并在指标不再可用时删除警报?

【问题讨论】:

    标签: prometheus prometheus-alertmanager prometheus-pushgateway


    【解决方案1】:

    我们通过使用Prometheus python client library API delete_from_gateway 明确删除不再相关的指标来解决此问题。

    【讨论】:

      猜你喜欢
      • 2018-10-20
      • 1970-01-01
      • 2021-12-11
      • 1970-01-01
      • 2021-12-16
      • 2019-01-29
      • 2018-05-22
      • 1970-01-01
      • 2022-09-28
      相关资源
      最近更新 更多