or function in alert annotation

19 views
Skip to first unread message

Frank R

unread,
May 21, 2020, 5:33:12 PM5/21/20
to Prometheus Users
Alert templating question.

I have an issue where some targets have a hostname label. When there is no hostname label the instance label should be used. 

Would this work in a prometheus alert annotation:

{{ or $labels.hostname $labels.instance }}

?

Julien Pivotto

unread,
May 21, 2020, 5:37:43 PM5/21/20
to Frank R, Prometheus Users
I am not going to answer your question because I am using another trick
to achieve this.

In the prometheus config:

alerting:
alert_relabel_configs:
- source_labels: [instance, hostname]
regex: "(.+);"
target_label: hostname
replacement: '$1'

That way, prometheus will add a hostname label equal to the instance to
every alert if it is empty.

Regards,


>
> ?
>
> --
> 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 prometheus-use...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/dc4da945-8fd1-41dc-9c10-ced090a1ca2d%40googlegroups.com.


--
Julien Pivotto
@roidelapluie

Frank R

unread,
May 21, 2020, 6:08:40 PM5/21/20
to Frank R, Prometheus Users
Thanks,

Will this work if the target already had an instance and hostname label?

Julien Pivotto

unread,
May 21, 2020, 6:10:35 PM5/21/20
to Frank R, Prometheus Users
On 21 May 18:08, Frank R wrote:
> Thanks,
>
> Will this work if the target already had an instance and hostname label?
>

If there is already a hostname label, the original value is kept.

If there is no hostname label, the value of instance is set as hostname label.
> To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/CAMuVLDOYb1uBdQ2pHTKWCtGOy-nER%2BVsKg8SEgiLHksjhqjKow%40mail.gmail.com.

--
Julien Pivotto
@roidelapluie
Reply all
Reply to author
Forward
0 new messages