prometheuspromqlvictoriametrics

Is it possible to calculate Ranks of metrics?


Am I missing something or is there no function in promql to calculate either one of the following:

A roundabout way might be to:

  1. Count how many observations are smaller than the observation at each timestamp.
  2. Divide result from 1. by total number of observations.

However that still seems beyond my skill so I am looking for some direction on which way I should pursue.


Solution

  • Probably you need share_le_over_time function from VictoriaMetrics (I work on this Prometheus-like system). For example, the following query returns the share of raw samples during the last hour per each series with name m, which don't exceed 42:

    share_le_over_time(m[1h], 42)
    

    The returned share is in the range 0 .. 1, where 0 means 0%, while 1 means 100%.

    Additionally, you may look at histogram_share function - it returns the share of samples from histogram buckets, which don't exceed the given threshold. I.e. it is an inverse of histogram_quantile function.