Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge/join two metrics in Prometheus/PromQL

I have two different (but related metrics).

metric_1(id="abc",id2="def")
metric_2(id="abc",id2="def")

My goal ultimately is to have the following in Grafana. I plan to use the "instant" value and Grafana's table visualization widget to display this data.

id      id2     metric1 metric2
abc     def     1       2

What query/joining/relabeling should I use to achieve this?

Thank you in advance! :)

like image 887
rcjsuen Avatar asked Jul 14 '18 15:07

rcjsuen


4 Answers

{__name__=~"metric_1|metric_2"}

https://stackoverflow.com/a/47415934/661150 https://prometheus.io/docs/prometheus/latest/querying/basics/

like image 150
fche Avatar answered Nov 08 '22 00:11

fche


As a workaround, you can append + 0 to the query so that Prometheus strips out its __name__ label so Grafana will merge them together. I found this workaround on GitHub.

Is there a better solution?

like image 2
rcjsuen Avatar answered Nov 08 '22 01:11

rcjsuen


You can achieve that in Grafana

  • make two queries, be sure to select format table
  • merge them with transform => merge
  • relable and hide unwanted fields with organize fields
like image 2
Martin Mkay Avatar answered Nov 08 '22 01:11

Martin Mkay


A bit of changes which merges all the steps before. The solution can be achieved in Grafana

  1. Make 2 queries and select visualization format as table
  2. Apply transformation Labels to fields (Select value filed name a value that uniquely identifies the metric name e.g. name)
  3. Merge them together transform ==> merge
  4. Reorganize/rename the field names
like image 1
Shashank Nigam Avatar answered Nov 07 '22 23:11

Shashank Nigam