Need to copy labels from metric1 to metric2

217 views
Skip to first unread message

Kishore Chopne

unread,
Mar 21, 2023, 9:23:49 AM3/21/23
to Prometheus Users
Hi,
     If we have metric1{foo="1} and metric2{foo="1",bar="2"} ? How can I copy the labels from metric2 to metric1?  How can I create recording rules so that the new metrics can be sent to Prometheus.
The idea is to enrich some metrics with more labels.

Thanks.
/Kishore

Brian Candler

unread,
Mar 21, 2023, 1:13:34 PM3/21/23
to Prometheus Users
See:

Assuming there are one or more instances of metric1 with label {foo="1"} and exactly one instance of metric2 with label {foo="1"}, then you can do:
metric1 * on (foo) group_left (bar) metric2

(I think that's right). metric1 is the "many" side and metric2 is the "one" side.  We can copy label bar from the "one" side to the "many" side.

Kishore Chopne

unread,
Mar 22, 2023, 12:44:14 AM3/22/23
to Prometheus Users
Thanks a lot Brian, it worked
Reply all
Reply to author
Forward
0 new messages