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.
Prometheus provides a functional query language called PromQL (Prometheus Query Language) that lets the user select and aggregate time series data in real time.
Prometheus uses the tilde character ~ to indicate a query contains a wildcard. Inside the label-query the "dot plus" ( . + ) character combination is used where all characters are accepted.
1 Answer. Show activity on this post. Prometheus calls this Vector Matching, you can perform arithmetic binary operations (+, -, *, / etc) across different time series if their labels match.
Figured it out. count(count_over_time(metric[range]))
gives the value I want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With