Search code examples
prometheusgrafanapromql

Is it possible to find max. value from a Histogram


Using grafana-agent to scrape the metrics from my application. I wonder if it's possible to gather max. value within a histogram by using PromQL. I have been publishing execution time metrics in an Histogram from my application, but I would like to also get the max. value like max. execution time within/per minute. I wonder if this is possible by Histogram and PromQL or should I consider a customized solution for that?

Thanks,

  • No min/max value sent via Prometheus Histograms so considering custom solution(s) to publish the max. value of a metric.

Solution

  • You can use the following query for obtaining the estimated maximum value from histogram metric with the name foo over the last hour:

    histogram_quantile(1, increase(foo_bucket[1h]))
    

    Note that the _bucket suffix is added to the foo histogram name in the query.

    This query uses the histogram_quantile function for calculating the estimated maximum value seen during the last hour (see 1h in square brackets in the query above). The estimation error can be quite big if the maximum observed value is located too far from the configured histogram bucket bounds. See this article for details and possible solutions on how to reduce the estimation error.