Prometheus query to count unique labels over a timeframe

冷暖自知 提交于 2021-02-08 19:53:10

问题


I need to count the number of unique labelsets for a prometheus metric over a given timeframe. For example, "How many unique labelsets have a value of 1 at some point during the past 7 days."

I've investigated using count and count_over_time but count only operates on instant vectors meaning I can get the number of unique labelsets for an instance in time, but not in aggregate over a timeframe. count_over_time returns the number of values which isn't useful since I need to know the number of labelsets and not how many values each has.

Basically I want something like count((metric_name >= 1)[7d]). This is a very easy problem to solve outside of PromQL by just making the range query metric_name >= 1 over 7 days and then counting the number of series in the result field of the response, but I want to perform this query in PromQL if possible.


回答1:


Figured it out. count(count_over_time(metric[range])) gives the value I want.



来源:https://stackoverflow.com/questions/57434543/prometheus-query-to-count-unique-labels-over-a-timeframe

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!