Grafana v10.4.7 (8d068faebe), I can not update this version, its managed.
I have a Grafana Alert with multiple math expressions G and K that give integer values in vector form:
G:
{namespace="first"}
=> 0
{namespace="second"}
=> 2
{namespace="third"}
=> 0
{namespace="fourth"}
=> 4
K:
{namespace="first"}
=> 6
{namespace="second"}
=> 1
{namespace="third"}
=> 0
{namespace="fourth"}
=> 2
How do I get the maximum of these two expression results, so that the math expression result would be:
{namespace="first"}
=> 6
{namespace="second"}
=> 2
{namespace="third"}
=> 0
{namespace="fourth"}
=> 4
Of course I want a solution where i can use more expression results, in my case I need the maximum of 7 other math expressions…
max($G, $K)
gives error, not to mention that it is not supported AFAIK.
I have checked all other expression options, non seems todo what I want:
Is this possible? If so how?
goulash:
I have a Grafana Alert with multiple math expressions G and K that give integer values in vector form:
G:
{namespace="first"}
=> 0
{namespace="second"}
=> 2
{namespace="third"}
=> 0
{namespace="fourth"}
=> 4
K:
{namespace="first"}
=> 6
{namespace="second"}
=> 1
{namespace="third"}
=> 0
{namespace="fourth"}
=> 2
How do I get the maximum of these two expression results, so that the math expression result would be:
{namespace="first"}
=> 6
{namespace="second"}
=> 2
{namespace="third"}
=> 0
{namespace="fourth"}
=> 4
Of course I want a solution where i can use more expression results, in my case I need the maximum of 7 other math expressions…
max($G, $K)
gives error, not to mention that it is not supported AFAIK.
I have checked all other expression options, non seems todo what I want:
You’re right — Grafana’s expression engine currently does not support max()
across multiple vector expressions directly like you would in Prometheus. The math expression (like $G > $K ? $G : $K
) only supportsvscalar or element-wise math but not aggregation across multiple expressions directly.
Step-by-step workaround for max across multiple expressions:
Let’s say you have expressions:
Step 1: Pairwise max expressions Start creating math expressions like this:
X1 = $A > $B ? $A : $B
X2 = $C > $D ? $C : $D
X3 = $E > $F ? $E : $F
Step 2: Combine again
X4 = $X1 > $X2 ? $X1 : $X2
X5 = $X3 > $G ? $X3 : $G
Step 3: Final max
XFinal = $X4 > $X5 ? $X4 : $X5
1 Like