maxprometheuspromql

PromQL query to get the maximum of two metrics


In a Prometheus timeseries database, there are two sets of data (for M1 and M2) collected with following schema

Write a PromQL query that creates a new time-series N, that tracks the max(M1, M2) for each time period the query is run.

For example: table

I tried using max(), but it takes only 1 argument.


Solution

  • PromQL allows selecting time series with multiple different names via regexp filter on __name__ pseudo-label. See these docs. For example, the following query selects all the series with names m1 and m2:

    {__name__=~"m1|m2"}
    

    So, the following query would select the max values over all the series with names m1 and m2 per each requested timestamp:

    max({__name__=~"m1|m2"})
    

    See the following additional info: