Combine 2 metrics to put in Grafana table

19,617 views
Skip to first unread message

Bartosz Witkowski

unread,
May 25, 2018, 7:40:50 AM5/25/18
to Prometheus Users
Hi,

I use bird_exporter to scrape data form BGP daemon called Bird. I have two metrics:
bird_protocol_up{instance="r1",ip_version="4",job="sd_bird_exporter",name="ACX_R1",proto="BGP"} 1
bird_protocol_uptime{instance="r1",ip_version="4",job="sd_bird_exporter",name="ACX_R1",proto="BGP"} 3658607

And I want to build Grafana table with columns: instance, ip_version, name, value_from_bird_protocol_up, value_from_bird_protocol_uptime.
So is it possible to put in one row two values from two metrics? Either using promql query or Grafana settings?

Thanks,
Bartek

vitaly...@gmail.com

unread,
May 30, 2018, 11:25:47 AM5/30/18
to Prometheus Users
Yes, this is possible as described here: https://github.com/grafana/grafana/pull/10050

Grafana will automatically combine results of multiple queries into the same row if all the labels match.

In order for all the labels to match up, you need to exclude the __name__ label since that's different. One way to do that is to just add 0 to the query, which causes the __name__ label to be dropped, eg:

bird_protocol_up{instance="r1",ip_version="4",job="sd_bird_exporter",name="ACX_R1",proto="BGP"}+0
bird_protocol_uptime{instance="r1",ip_version="4",job="sd_bird_exporter",name="ACX_R1",proto="BGP"}+0

Or you can use the sum aggregator:

sum(bird_protocol_up) by (instance, ip_version, name)
sum(bird_protocol_uptime) by (instance, ip_version, name)

There may be better ways of doing this that I'm not aware of.

Bartosz Witkowski

unread,
Jun 1, 2018, 5:00:42 AM6/1/18
to Prometheus Users
It works as expected!
Thanks Vitaly!
Reply all
Reply to author
Forward
0 new messages