管理 pushgateway 最近的抓取时间的普罗米修斯限制

Managing prometheus limitation of pushgateway's recent scrape time

我看到其他 threads/posts(在 github,Whosebug 上)人们要求普罗米修斯能够根据指标过滤指标或将指标标记为 stale/expired ' 时间戳(最后一次推送到 pushgateway 时)。这似乎违背了普罗米修斯的工作方式,这很好。但是,我想知道人们是如何解决这个问题的。

我一直在尝试一些事情,但不幸的是没有成功:

cat <http://localhost:9091/metrics/job/test push_time_seconds{instance="",label1="value1",label2="value2"} 52 EOF

我在 pushgateway 指标中看到以下指标:

push_time_seconds{instance="",job="test"} 1.5754837280426762e+09 some_metric{instance="",job="test",label1="value1",label2="value2"} 5

但是,我不知道如何构建将使用 push_time_seconds 指标更新 some_metric 中的值的 PromQL 查询。就像 push_time_seconds 超过一个小时一样,将 some_metric 的值设置为 0。

有人对此有什么建议吗?

我找到了另一个基于 PromQL 的数据库 "Victoria Metrics"。我能够使用布尔和 "if" 运算符来操纵 push_last_seconds 和我的查询来做我想做的事。

我最终使用了两种方法:

  • script/batch job -> pushgateway <- prometheus -> VictoriaMetrics <- Grafana(通过使用 VictoriaMetrics 作为 Prometheus 类型的数据源)
    • 这将使用我在下面指定的布尔逻辑。
  • script/batch job -> VictoriaMetrics <- Grafana(通过使用 VictoriaMetrics 作为 Prometheus 类型数据源)
    • 这完全不需要使用 pushgateway。

如果有人需要更多信息,请告诉我。

另一个查询(显然 'job' 属性是这里的关键):

avg(SomeMetric{job="some_job"}) if (time() - push_time_seconds{job="some_job"} < 30)

一个例子comparison/boolean:

WITH (x = avg(SomeMetric{job="some_job"}), y = (NaN if 3 < 2) default 2) (y default 3)

结合两者:

WITH (x = avg(SomeMetric{job="some_job"}), y = (NaN if (time() - push_time_seconds{job="some_job"} < 30)) default 2) (y default 3)