Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the minimum of two metrics in PromQL?

I'm looking for something similar to SQL's LEAST() function.
Since there are binary operators (and a well-defined matching behavior) one would expect there would be min/max as well, but couldn't find such functions.

I'm aware that this is achievable using regex (i.e., min(__name__=~"a|b")) but would like to avoid such hacks if possible.

like image 995
Paul Oyster Avatar asked May 02 '19 11:05

Paul Oyster


People also ask

How can we join two metrics in a Prometheus query?

PromQL supports the ability to join two metrics together: You can append a label set from one metric and append it to another at query time. This can be useful in Prometheus rule evaluations, since it lets you generate a new metric for a series by appending labels from another info metric.

How do I filter Prometheus metrics?

To filter out unwanted metrics from a target, use the ignore_metrics configuration option. To filter out targets instead of the metrics, use the scrape_enabled_label configuration option.

How do you use the rate function in Prometheus?

Prometheus rate function is the process of calculating the average per second rate of value increases. You would use this when you want to view how your server CPU usage has increased over a time range or how many requests come in over a time range and how that number increases.


1 Answers

I'm pretty sure that's the most efficient way of doing it. If you want to avoid regexes, you could write it instead as:

a < b or b

But it may be more expensive to compute this way. (Unless, of course, you used recording rules instead of min(a) and min(b) directly. And maybe even then. You'll just have to benchmark it yourself.)

like image 130
Alin Sînpălean Avatar answered Sep 28 '22 21:09

Alin Sînpălean