prometheus - VictoriaMetrics count temperature distinct values of gauge by bin range - Stack Overflow

admin2025-04-18  3

temperature is a gauge that returns some unique values {10,23,50...} for labels node_id,system_id with values {"1","1"},{"2","1"},{"1","2"},{"2","2"}.

I want to get the count of temperature by bin range.

Something looking like this

| temperature | count    | 
+-------------+----------+
| 10-20       | 10       | 
+-------------+----------+
| 20-30       | 15       |
+-------------+----------+
| 30-40       | 2        |
+-------------+----------+
| 40-50       | 10       | 
+-------------+----------+
.....

I can get individual count using

sum(count_eq_over_time(temperature[1h],11))

looking for a single query to get above results.

Any idea how to tackle this, or where should I start from.

temperature is a gauge that returns some unique values {10,23,50...} for labels node_id,system_id with values {"1","1"},{"2","1"},{"1","2"},{"2","2"}.

I want to get the count of temperature by bin range.

Something looking like this

| temperature | count    | 
+-------------+----------+
| 10-20       | 10       | 
+-------------+----------+
| 20-30       | 15       |
+-------------+----------+
| 30-40       | 2        |
+-------------+----------+
| 40-50       | 10       | 
+-------------+----------+
.....

I can get individual count using

sum(count_eq_over_time(temperature[1h],11))

looking for a single query to get above results.

Any idea how to tackle this, or where should I start from.

Share edited Jan 30 at 12:40 crr asked Jan 30 at 11:06 crrcrr 2636 silver badges16 bronze badges 0
Add a comment  | 

1 Answer 1

Reset to default 2

Try the following expression example to get everything within one query:

WITH (
  metric = temperature[1d],
  range(low, high) = sum(count_le_over_time(metric, high)) - sum(count_le_over_time(metric, low))
)
union(
 label_set(range(10,20), "range", "10-20"),
 label_set(range(20,30), "range", "20-30"),
 label_set(range(30,40), "range", "30-40")
)
转载请注明原文地址:http://www.anycun.com/QandA/1744924248a89555.html