Merge/join two metrics in Prometheus/PromQL

13,059

Solution 1

{__name__=~"metric_1|metric_2"}

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

Solution 2

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?

Share:
13,059

Related videos on Youtube

rcjsuen
Author by

rcjsuen

Updated on June 04, 2022

Comments

  • rcjsuen
    rcjsuen almost 2 years

    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! :)