I've implemented by using label_replace for renaming label.

Answer from kolchanov on Stack Overflow
🌐
GitHub
github.com › prometheus › prometheus › issues › 2204
Joining different labels · Issue #2204 · prometheus/prometheus
November 18, 2016 - The label naming might not be 100% ... kube-state-metrics. The values are the same pod identifying names. However, we have to use label_replace() to be able to join them properly, which is always somewhat awkward and hard to ...
Author: prometheus
Discussions

monitoring - How can I 'join' two metrics in a Prometheus query? - Stack Overflow
Good PromQL primer if this is as impenetrable to you as it was to me a few hours ago :joy: 2020-01-18T05:18:00.287Z+00:00 ... Save this answer. ... Show activity on this post. It is a good practice in Prometheus ecosystem to expose additional labels, which can be joined to multiple metrics, ... More on stackoverflow.com
🌐 stackoverflow.com
simpler syntax for joins on labels with different names
Background When doing joins, I usually encounter cases where I want to join through a label that has different names on each side. For example, suppose I have: A container_fs_reads_total metric wit... More on github.com
🌐 github.com
8
October 10, 2024
prometheus - PromQL join with identical label value but different label name - Stack Overflow
I am struggling with the label_replace function since I am pretty sure it's what I need. The answer here also suggests it: Promql join on different label names More on stackoverflow.com
🌐 stackoverflow.com
prometheus - PromQL join two metrics with identic label names but different label values - Stack Overflow
Additionally the result vector must have unique set of label keys. That's why we are renaming the label in the right-hand side vector and joining it as a label with different name. More on stackoverflow.com
🌐 stackoverflow.com
Top answer
1 of 3
76

You can use the argument list of group_left to include extra labels from the right operand (parentheses and indents for clarity):

(
  max(consul_health_service_status{status="critical"}) 
  by (service_name,status,node) == 1
)
   + on(service_name,node) group_left(env)
(
   0 * consul_service_tags
)

The important part here is the operation + on(service_name,node) group_left(env):

  • the + is "abused" as a join operator (fine since 0 * consul_service_tags always has the value 0)
  • group_left(env) is the modifier that includes the extra label env from the right (consul_service_tags)
2 of 3
15

It is a good practice in Prometheus ecosystem to expose additional labels, which can be joined to multiple metrics, via a separate info-like metric as explained in this article. For example, consul_service_tags metric exposes a set of tags, which can be joined to metrics via (service_name, node) labels.

The join is usually performed via on() and group_left() modifiers applied to * operation. The * doesn't modify values for time series on the left side because info-like metrics usually have constant 1 values. The on() modifier is used for limiting the labels used for finding matching time series on the left and the right side of *. The group_left() modifier is used for adding additional labels from time series on the right side of *. See these docs for details.

For example, the following PromQL query adds env label from consul_service_tags metric to consul_health_service_status metric with the same set of (service_name, node) labels:

consul_health_service_status
  * on(service_name, node) group_left(env)
consul_service_tags

Additional label filters can be added to consul_health_service_status if needed. For example, the following query returns only time series with status="critical" label:

consul_health_service_status{status="critical"}
  * on(service_name, node) group_left(env)
consul_service_tags
🌐
Iximiuz
iximiuz.com › en › posts › prometheus-vector-matching
Prometheus Cheat Sheet - How to Join Multiple Metrics (Vector Matching)
November 30, 2021 - How to join metrics on matching labels? Vector matching: one-to-one, one-to-many and many-to-one, many-to-many. What on/ignoring clause is for? group_left and group_right explained. Logical/set operations explained.
🌐
Google Groups
groups.google.com › g › prometheus-users › c › qlHK7r1hQVs
Joining two metrics in promtheus and having all labels from both
March 6, 2023 - In theory both of the metrics that I’m using to would work just without any manipulation, for example ltmPoolMbrStatusAvailState will return everything I care about and all the labels I need to use to match it’s just once I manipulate the values that it stops showing me everything. ... ‘ltmPoolMbrStatusAvailState or on (instance,ltmPoolMbrStatusNodeName,ltmPoolMbrStatusPoolName,ltmPoolMbrStatusPort) metricfromrecordingrule * 0’ · Then the recording rule would be for the initial join:
🌐
Robust Perception
robustperception.io › left-joins-in-promql
Left joins in PromQL – Robust Perception | Prometheus Monitoring Experts
December 30, 2019 - PromQL by default effectively does an inner join and requires that labels (except the metric name) on both sides of the expression to be exactly the same and match one-to-one. There's no way in PromQL to increase your cardinality (other than absent(), which can only go from 0 to 1).
Find elsewhere
🌐
GitHub
github.com › prometheus › prometheus › issues › 15146
simpler syntax for joins on labels with different names · Issue #15146 · prometheus/prometheus
October 10, 2024 - Extend the join syntax to support joins through labels with different names. Syntax could be <binop> on (a as b). Credits to @colega for this suggestion. Reactions are currently unavailable · Sign up for free to join this conversation on GitHub.
Author: prometheus
🌐
Stack Overflow
stackoverflow.com › questions › 79231136 › promql-join-with-identical-label-value-but-different-label-name
prometheus - PromQL join with identical label value but different label name - Stack Overflow
I am struggling with the label_replace function since I am pretty sure it's what I need. The answer here also suggests it: Promql join on different label names
🌐
Google Groups
groups.google.com › g › prometheus-users › c › po4YEDU5uWw
Promql JOIN many-to-many matching
October 6, 2021 - If all the nodes in a given cluster have identical kubelet versions, then you'll just get 1 metric per cluster. At that point you can do a N:1 join: kube_deployment_labels * on (instance) group_left(kubelet_version) (count by (instance, kubelet_version) (kube_node_info))
Top answer
1 of 2
2

The main roadblock you are probably hitting is the fact that the in both metrics you have the status label which is different AND the one you want to replicate. Prometheus won't be able resolve it while the label names collide.

The first thing you want to do is generate a new timeseries with a different label name for the second status. You can do this by using label_replace. For example:

label_replace(metric2{...}, "metric2_status", "$1", "status", "(.*)")

This will keep the status label but will also add a metric2_status with the value of the status label.

Now you can proceed to use on() and group_left(). These need to be used with an arithmetic or group function. If you are using this to add more labels to metric1, remember to use an arithmetic that will not alter the metric value.

For example - assuming metric2 has always a value of 1 - this is what you could use:

metric1{label_1="a", ...} * 
    on (label_a, label_b) 
    group_left(metric2_status)
label_replace(metric2{...}, "metric2_status", "$1", "status", "(.*)")

the resulting metric should have metric1's labels plus the metric2_status label.

2 of 2
0

When using group modifiers such as

ignoring()
on()
group_left()
group_right()

the label(s) used in on() modifier must be unique at least in one vector.

Consider metric1, metric2 vectors and common label_a=... label used in on(). These cases may occur

If metric1 has unique label_a=... and metric2 has unique label_a=... we have one-to-one match.

If metric1 has duplicate label_a=... and metric2 has unique label_a=... we have many-to-one match.

If metric1 has unique label_a=... and metric2 has duplicate label_a=... we have one-to-many match.

If metric1 has duplicate label_a=... and metric2 has duplicate label_a=... we have many-to-many match and vectors are not joinable.

Additionally the result vector must have unique set of label keys. That's why we are renaming the label in the right-hand side vector and joining it as a label with different name.

Working query is

( metric1{...} == 1 ) *
    on(label_a)
    group_left(metric2_status)
label_replace((metric2{...} == 1), "metric2_status", "$1", "status", "(.*)")

( metric1{...} == 1 )

Filter metric1 so that the left-hand side of the query contains only data with unique label_a=....

on(label_a)

join two metrics on label_a=....

group_left(metric2_status)

add metric2_status label from right-hand metric2.

label_replace((metric2{...} == 1), "metric2_status", "$1", "status", "(.*)")

create new label metric2_status in metrics2 from the status label.

🌐
SigNoz
signoz.io › guides › how can i 'join' two metrics in a prometheus query? - joining metrics in promql
How can I 'join' two metrics in a Prometheus query? - Joining Metrics in PromQL | SigNoz
July 24, 2024 - This approach allows for a holistic view of your system's health and performance. Vector matching is the primary method for joining metrics in PromQL. It allows you to combine time series based on their label sets.
🌐
Checkmk
forum.checkmk.com › general
PromQL for joining labels - General - Checkmk Forum
August 14, 2023 - Hi, We have a scenario where were we need to explore using Prometheus. To get the right value for our metric we need to join two different metrics. The data is available as Prometheus labels and comes from two different…
🌐
OneUptime
oneuptime.com › home › blog › how to join two metrics in prometheus query
How to Join Two Metrics in Prometheus Query
December 17, 2025 - # Add missing label for join label_replace( node_cpu_utilization, "cluster", "production", "job", ".*" ) * on(cluster) group_left(region) cluster_info
🌐
Google Groups
groups.google.com › g › prometheus-users › c › LgGTcR-jQvs
Join by field (outer join) with different names
October 12, 2020 - Joining the two queries results would permit to get some more informations into the same table. ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... 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.
🌐
Atatus
atatus.com › blog › how-to-join-two-metrics-in-prometheus
How to Join two metrics in Prometheus?
August 12, 2025 - This is achieved using PromQL (Prometheus Query Language) to create queries that merge related metrics based on their labels, allowing for a more comprehensive view of the data. The need for joining metrics in Prometheus arises from the limitations of analysing metrics individually.
🌐
Coralogix
coralogix.com › home › promql tutorial: 5 tricks to become a prometheus god
PromQL Tutorial: Basic Concepts & Examples - Coralogix
June 3, 2025 - PromQL’s two label manipulation commands are label_join and label_replace. label_join allows you to take values from separate labels and group them into one new label.