On 06.08.21 15:19, Laurent Dumont wrote:
> 
> I have the following metrics (removed some labels)
> 
> potato{short_hostname="qasite1-compute001",site="qasite1",hardware="hardwaretype1"}
>  1
> potato{short_hostname="qasite1-compute001",site="qasite1",hardware="hardwaretype2"}
>  1
> carrot{short_hostname="qasite1-compute001",site="qasite1",type="running_carrots"}
>  0
> carrot{short_hostname="qasite1-compute001",site="qasite1",type="running_carrots"}
>  5
> 
> The goal is to "merge" these two metrics to allow some cross queries where
> 
>    - our common label is short_hostname

Which means you have to specify `on(short_hostname)` after the binary
operator.

This might get you into cases where there is no unique match
possible. In this case, you add `group_left` or `group_right` to mark
the side with the higher cardinality.

If both sides have a cardinality of more than one for that label, then
no match on just that label is possible.

In your example above, `potato` has cardinality 2. The two lines for
`carrot` are actually for the same metric. (They have exactly the same
label set.)

>    - for all short_hostname values, I want to check the value of the
>    "hardware" label and get the value of the "carrot" metric only if the label
>    "hardware" in "potato" is equal to "hardwaretype1"

That's actually easy:

    carrot and on(short_hostname) potato{hardware="hardwaretype1"}

>    - Furthermore, I want to also validate that the resulting metric value
>    of "carrot" is equal to 0 (not a label in this case)

    carrot==0 and on(short_hostname) potato{hardware="hardwaretype1"}
    
-- 
Björn Rabenstein
[PGP-ID] 0x851C3DA17D748D03
[email] [email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/prometheus-users/20210813123924.GD3669%40jahnn.

Reply via email to