简体   繁体   English

PromQL 查询以检测新时间序列的创建

[英]PromQL query to detect the creation of new time series

I have a metric with counters type.我有一个计数器类型的指标。 For a given metric and label combination, I need to detect if a new time series is created for the last one day.对于给定的指标和 label 组合,我需要检测是否为最后一天创建了新的时间序列。 If yes, the query should return 1, else return 0 or empty.如果是,查询应返回 1,否则返回 0 或空。

I used the below query.我使用了以下查询。

count by(label_1, label_2) count_over_time(My_metric{label_1="v1",label_2="v2"}[1d]) > 0 

This works partly as it detects the new time series but after a day of creation, it still returns 1.这在一定程度上起作用,因为它检测到新的时间序列,但在创建一天后,它仍然返回 1。

My_metric{label_1="v1",label_2="v2"}

Time series时间序列

count by(label_1, label_2) count_over_time(My_metric{label_1="v1",label_2="v2"}[1d]) > 0 

Time series with the above the above query上面查询的时间序列

This timeseries is created around Jan 1, 10AM.这个时间序列是在 1 月 1 日上午 10 点左右创建的。 From Jan 1, 10AM - Jan 2 10AM, promQL query should return 1 and rest of time, it should return 0 or empty.从 1 月 1 日上午 10 点到 1 月 2 日上午 10 点,promQL 查询应该返回 1 和 rest 的时间,它应该返回 0 或为空。 Could someone help on this?有人可以帮忙吗? Any help on this is greatly appreciated.非常感谢对此的任何帮助。

The following query returns 0 if there were no new time series matching the My_metric{label_1="v1",label_2="v2"} series selector during the last day.如果在最后一天没有与My_metric{label_1="v1",label_2="v2"}系列选择器匹配的新时间系列,则以下查询返回 0。 Otherwise it returns 1:否则返回 1:

count(
  My_metric{label_1="v1",label_2="v2"}
    unless
  (
    My_metric{label_1="v1",label_2="v2"} offset 1d
  )
) >bool 0

The query uses the following PromQL features:该查询使用以下 PromQL 功能:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM