prometheusgrafanavictoriametrics

VictoriaMetrics count temperature distinct values of gauge by bin range


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.


Solution

  • 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")
    )