Join by field (outer join) with different names

1,379 views
Skip to first unread message

Gilbert Moisio

unread,
Oct 12, 2020, 7:49:53 AM10/12/20
to Prometheus Users
Hi all, using Grafana on a Prometheus data source and snmp_exporter, I'm searching a way to join two tables that have a common information but the name of the field is not the same in the tables.
Is there a way to do this?
Thanks
Reg

Brian Candler

unread,
Oct 12, 2020, 8:43:33 AM10/12/20
to Prometheus Users
Can you give a specific example?

The solution in general is to make the labels align, e.g. see here for the instance label.  There is also label_replace() if you can modify the labels using regexp matches.  At worst, you would create a third, static timeseries with appropriate labels to join the other two timeseries onto, similar to the approach here and here.

Gilbert Moisio

unread,
Oct 12, 2020, 8:50:46 AM10/12/20
to Prometheus Users
The example:

- From IF-MIB, getting ifHighSpeed gives an ifIndex in the returned informations
- From LLDP-MIB getting lldpLocPortDesc gives lldpLocPortNum that is the same value as ifIndex

Joining the two queries results would permit to get some more informations into the same table.
Thanks

Brian Candler

unread,
Oct 12, 2020, 9:48:31 AM10/12/20
to Prometheus Users
Try:

label_replace(lldpLocPortDesc, "ifIndex", "$1", "lldpLocPortNum", "(.+)")

If that works, then you should be able to build a query on top of this which uses (instance, ifIndex) as the join labels.

Gilbert Moisio

unread,
Oct 12, 2020, 12:13:43 PM10/12/20
to Prometheus Users
Ok, it looks like it's working as expected...
Thanks

Kshitija Patil

unread,
Sep 7, 2021, 1:28:39 AM9/7/21
to Prometheus Users
i wanted to join to queries cpu_usage and memory_bytes for one namespace how can i do that ?

Brian Candler

unread,
Sep 7, 2021, 4:30:42 AM9/7/21
to Prometheus Users
You can combine metrics using arithmetic, e.g.

    memory_bytes / cpu_usage

assuming that (a) dividing those two metrics gives a meaningful result (which is your responsibility), and (b) the two metrics have exactly the same label sets (so the corresponding timeseries can be matched 1:1).

If they don't have identical label sets then using on(), ignoring() for 1:1 matches, and group_left or group_right for 1-to-many matches are possible.  They are documented here:
There are also various blogs and tutorials - those on www.robustperception.io are especially worth digesting.
Reply all
Reply to author
Forward
0 new messages