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. If yes, the query should return 1, else return 0 or empty.
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.
My_metric{label_1="v1",label_2="v2"}
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. From Jan 1, 10AM - Jan 2 10AM, promQL query should return 1 and rest of time, it should return 0 or empty. 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. Otherwise it returns 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:
offset
modifier unless
binary operator bool
modifier for >
operator
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.