Search code examples
prometheuspromql

Difference between the maximum of a guage metric and instances with a label a series


I have a prometheus guage metric (height) that I have a number of instances of with a regex-able label (pod_name) that I want to take the maximum of and subtract from each instance to get the difference between it and the maximum.

What I thought would work would be something like:

height{pod_name=~"a-name.*"} - max(height{pod_name=~"a-name.*"})

Where the individual parts work, but subtracting fails.

Any ideas on this query? Thank you for your time.


Solution

  • Try the following query:

    height{pod_name=~"a-name.*"} - on() group_left() max(height{pod_name=~"a-name.*"})
    

    See these docs for details on on() and group_left() modifiers.