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)
Answer from user2361830 on Stack Overflow
🌐
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.
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
Joining different labels
I think this will be a common case ... to join such labels could be beneficial. I imagine a syntax along the lines of: container_last_seen and on(pod_name=pod) kube_pod_info · Where the names left and right of = refer to the matched on labels of the left and right metrics respectively. I'd hope it to be easy enough to implement in our parser and think it's generally an rather obvious syntax for the semantics. I know that's not a trivial extension to PromQL, so this is ... More on github.com
🌐 github.com
36
November 18, 2016
Using range with label_join - PromQL - Prometheus Monitoring System
I have a set of metrics that are being sent only when there is an issue. I want to create an expression that will capture the number of issues in the last 15 minutes. For efficiency I would like to use a regex with the metrics names (let’s asume that there will be no performance problems) . More on discuss.prometheus.io
🌐 discuss.prometheus.io
0
October 26, 2022
monitoring - How to rename label within a metric in Prometheus - Stack Overflow
you can use the label_replace function in promQL, but it also add the label, don't replace it More on stackoverflow.com
🌐 stackoverflow.com
People also ask

What is PromQL?
PromQL (Prometheus Query Language) is the query language built into Prometheus for selecting, filtering, and aggregating time series data. You use it to write expressions that power dashboards, alerts, and ad-hoc metric analysis.
🌐
last9.io
last9.io › blog › promql-cheat-sheet
PromQL Cheat Sheet: Queries, Functions, and Labels | Last9
How do I filter by label values in PromQL?
Use curly brace selectors: http_requests_total{job="api", status="500"} for exact matches, {status=~"5.."} for regex matches, and {status!="200"} to exclude a value. Multiple label filters combine with AND logic.
🌐
last9.io
last9.io › blog › promql-cheat-sheet
PromQL Cheat Sheet: Queries, Functions, and Labels | Last9
How do I predict future resource usage in PromQL?
Use predict_linear(metric[window], seconds). For example, predict_linear(node_filesystem_free_bytes[30d], 86400 7) predicts disk space 7 days from now based on the last 30-day trend. Use a long lookback window for more stable predictions.
🌐
last9.io
last9.io › blog › promql-cheat-sheet
PromQL Cheat Sheet: Queries, Functions, and Labels | Last9
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
🌐
GitHub
github.com › prometheus › prometheus › issues › 2204
Joining different labels · Issue #2204 · prometheus/prometheus
November 18, 2016 - The label naming might not be 100% aligned, i.e. in Kubernetes we get container metrics with a pod_name label from cAdvisor and metrics with a pod label from 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 decipher.
Author: prometheus
🌐
Prometheus
discuss.prometheus.io › promql
Using range with label_join - PromQL - Prometheus Monitoring System
October 26, 2022 - I have a set of metrics that are being sent only when there is an issue. I want to create an expression that will capture the number of issues in the last 15 minutes. For efficiency I would like to use a regex with the m…
🌐
Last9
last9.io › blog › promql-cheat-sheet
PromQL Cheat Sheet: Queries, Functions, and Labels | Last9
September 12, 2024 - PromQL’s label join functionality allows you to combine or match time series from different metrics based on shared labels.
Find elsewhere
🌐
Google Groups
groups.google.com › g › prometheus-users › c › qlHK7r1hQVs
Joining two metrics in promtheus and having all labels from both
March 6, 2023 - Thanks, The reason the metrics have the same name as the label is because in order to bring the value in from the SNMP exporter as a lablel, you have to set the type as DisplayString. As from what I have read, doing a 'join' would not allow you yo get the value of the metric in as a label value.
🌐
SigNoz
signoz.io › guides › how to omit labels in promql series results
How to Omit Labels in PromQL Series Results | SigNoz
November 29, 2024 - For more complex scenarios, PromQL ... label. ... The label_join function in PromQL is used to combine multiple label values into a single label, using a specified separator....
Top answer
1 of 5
43

you can use the label_replace function in promQL, but it also add the label, don't replace it

label_replace(
  <vector_expr>, "<desired_label>", "$1", "<existing_label>", "(.+)"
)

label_replace(
node_systemd_unit_state{instance="server-01",job="node-exporters",name="kubelet.service",state="active"},
"unit_name","$1","name", "(.+)"
)

So, to avoid the repetition you can add:

sum(label_replace(
    node_systemd_unit_state{instance="server-01",job="node-exporters",name="kubelet.service",state="active"},
    "unit_name","$1","name", "(.+)"
    )
)by(unit_name)
2 of 5
26

I got tired of all the fragmented documentation and I feel I provided a better answer in this post here: https://medium.com/@texasdave2/replace-and-remove-a-label-in-a-prometheus-query-9500faa302f0

Replace is not a true REPLACE

Your goal is to simply replace the old label name “old_job_id” with a new label name “new_task_id”. Prometheus label_replace will really “add” the new label name. It will preserve the old label name as well… So, that could be a problem, it’s not a true “replace in place”.

So if you want to “add” your new label name and “remove” the old label name, you need to do this:

sum without (old_job_id) (label_replace(metric, "new_task_id", "$1", "old_job_id", "(.*)"))

Here’s how this reads:

  • sum without (old_job_id) will remove the old label name from the query output

  • metric is your metric, like “node_filesystem_avail_bytes”

  • “new_task_id” is where you would put your new label name

  • “$1” is regex for using the string in new label name, don’t change this

  • “old_job_id” is where you’ll put your old label, the one you want to get rid of (.*……. that mess is regex that will replace the whole label name

🌐
GitHub
github.com › prometheus › prometheus › issues › 9850
Allow label_join to be used in aggregation operators · Issue #9850 · prometheus/prometheus
November 23, 2021 - {instance="datacenter0"} 1000 {instance="datacenter1"} 2000 sum by(label_join("instance", "datacenters", ",")) ( irate( tIPFilterParamsEgrHitByteCount{ instance=~"datacenter.*", }[10m] ) ) {datacenters="datacenter0,datacenter1"} 3000 · 👍React with 👍7paulolieuthier, AFriemann, sivukhin, artazar, itzoey and 2 more · No one assigned · component/promqlhelp wantedkind/featurenot-as-easy-as-it-lookspriority/Pmaybe ·
Author: prometheus
🌐
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.
🌐
Ac-programming
ac-programming.com › content › Prom › Functions › label.html
Prometheus Label Functions
These examples demonstrate how each label function can be used in PromQL to manipulate and transform time series data based on their labels: 1. label_replace: label_replace(my_metric{job="job1"}, "new_label", "$1", "source_label", "(.*)") This example replaces the value of the "new_label" with the value of "source_label" for the "my_metric" time series. The regular expression "(.*)" captures the value of "source_label" and assigns it to "new_label". 2. label_join: label_join(my_metric{job="job1"}, "new_label", ",", "label1", "label2") This example joins the values of "label1" and "label2" with a comma (",") as the delimiter and assigns the result to "new_label" for the "my_metric" time series.
🌐
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).
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › functions
Query functions | Prometheus
Please note that sort_by_label only affects the results of instant queries, as range query results always have a fixed output ordering. ... This function has to be enabled via the feature flag --enable-feature=promql-experimental-functions.
🌐
SigNoz
signoz.io › blog › prometheus query tutorial with examples
Prometheus Query Tutorial with examples | SigNoz
August 1, 2022 - PromQL comes with a handy library of built-in functions that help craft useful queries. Utilizing the functions library can take you from a beginner to an adept user quickly. ... label_join(up{job="api-server",src1="a",src2="b",src3="c", srcN="z"}, "New", ",", "src1", "src2", "src3", srcN)
🌐
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 - Vector matching is the primary method for joining metrics in PromQL. It allows you to combine time series based on their label sets.
🌐
Google Groups
groups.google.com › g › prometheus-users › c › po4YEDU5uWw
Promql JOIN many-to-many matching
October 6, 2021 - Now i want all fields from metric1 and the label “kubelet_version” from 2nd metric,let say i want to join kubelet_version to the 1st metric result.
🌐
Grafana
community.grafana.com › prometheus
How can PromQL 'label_join' works in the Variables? - Prometheus - Grafana Labs Community Forums
March 20, 2019 - how can PromQL ‘label_join’ works in the Variables? The version is When i typed the query phrase like this, label_join(ifName{}, 'id_instance, ‘_’, ‘ifIndex’, ‘instance’), it reported the error! Template variables coul…