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
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
🌐
OneUptime
oneuptime.com › home › blog › how to join two metrics in prometheus query
How to Join Two Metrics in Prometheus Query
December 17, 2025 - Learn how to join two metrics in Prometheus using vector matching with on(), group_left(), and group_right(). This guide covers one-to-one, many-to-one, and many-to-many joins with practical examples.
Discussions

Joining two metrics - PromQL - Prometheus Monitoring System
Hello Team, I have been trying to join two metrics, But whenever I add an operator, I get no data. Could someone help me figure it out? topk(5, stddev(container_memory_usage{k8s_cluster_name=“lab”}) by (k8s_container_name)) * on(k8s_node_name) group_left(support_level) k8s_cluster_metadata{} More on discuss.prometheus.io
🌐 discuss.prometheus.io
0
December 19, 2023
Prometheus - How to “join” two metrics and calculate the difference?
How would I join metrics by their similar labels and calculate the difference? Example I have metric for tracking the inventory from two systems. I have the numbers push to the same metric but use labels to identify whe… More on community.grafana.com
🌐 community.grafana.com
3
0
May 11, 2020
How to combine two metrics into one in Prometheus
Use a recording rule to summarize them when scraping them instead of summing them at query time. The recording rule will yield a new metric for this use. More on reddit.com
🌐 r/PrometheusMonitoring
1
2
September 18, 2023
Merge/join two metrics in Prometheus/PromQL - Stack Overflow
Apply transformation Labels to fields (Select value filed name a value that uniquely identifies the metric name e.g. name) ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Help me join Stack Overflow for Agents here. More on stackoverflow.com
🌐 stackoverflow.com
🌐
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 - Joining two metrics in a Prometheus query allows you to correlate data from different sources, providing deeper insights into your system's behavior. This process involves using PromQL (Prometheus Query Language) to combine metrics based on ...
🌐
Yannick Pereira-Reis
ypereirareis.github.io › blog › 2020 › 02 › 21 › how-to-join-prometheus-metrics-by-label-with-promql
How to join Prometheus metrics by label with PromQL – Yannick Pereira-Reis
There is a label in common between the two metrics “node_meta” and “node_disk_bytes_read”: instance. ... How to query prometheus to have sum of “disk bytes read” by instance/node/server name ?
🌐
Prometheus
discuss.prometheus.io › promql
Joining two metrics - PromQL - Prometheus Monitoring System
December 19, 2023 - Hello Team, I have been trying to join two metrics, But whenever I add an operator, I get no data. Could someone help me figure it out? topk(5, stddev(container_memory_usage{k8s_cluster_name=“lab”}) by (k8s_container_…
🌐
Better Stack
betterstack.com › community › questions › how-to-join-two-metric-in-one-prometheus-query
How Can I 'Join' Two Metrics in a Prometheus Query? | Better Stack Community
Joining two metrics in Prometheus is commonly achieved through the use of the * operator or the group function, allowing you to perform operations between metrics based on their labels.
🌐
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.
🌐
Atatus
atatus.com › blog › how-to-join-two-metrics-in-prometheus
How to Join two metrics in Prometheus?
August 12, 2025 - Once metrics are joined in Prometheus ... meaningful insights. Here's a simple explanation of how these operations can help: Addition (+): This operation helps in combining the values of two metrics....
Find elsewhere
🌐
Grafana
community.grafana.com › prometheus
Prometheus - How to “join” two metrics and calculate the difference? - Prometheus - Grafana Labs Community Forums
May 11, 2020 - How would I join metrics by their similar labels and calculate the difference? Example I have metric for tracking the inventory from two systems. I have the numbers push to the same metric but use labels to identify where the metric came from. inventory_quantities{sku="ABC", system="warehouse1"} value = 5 inventory_quantities{sku="ABC", system="warehouse2"} value = 15 I want to join on the SKU and calculate the difference between the two.
🌐
Grafana
grafana.com › blog › how-to-use-promql-joins-for-more-effective-queries-of-prometheus-metrics-at-scale
How to use PromQL joins for more effective queries of Prometheus metrics at scale | Grafana Labs
August 5, 2021 - For some example scripts that can ... the ability to join two metrics together: You can append a label set from one metric and append it to another at query time....
🌐
Google Groups
groups.google.com › g › prometheus-users › c › qlHK7r1hQVs
Joining two metrics in promtheus and having all labels from both
March 6, 2023 - To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/4c22a279-a51c-47db-993e-9107e54e883en@googlegroups.com. ... Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message ... But yes, you'll have to treat it as a many-to-one in order to pick up the extra labels. If you know for sure that metrics A and B are always matched 1:1, then it doesn't matter whether you use group_left or group_right.
🌐
Reddit
reddit.com › r/prometheusmonitoring › how to combine two metrics into one in prometheus
r/PrometheusMonitoring on Reddit: How to combine two metrics into one in Prometheus
September 18, 2023 -

I am new to Prometheus metrics and I still struggle to see the right way to do things.

I recently discovered that the job I created had one target that was reading two instances metrics. That means that I had two sequences merged into one and the counter was going up and down.

After a question at Stackoverflow I changed the job to

- job_name: 'example'
    scrape_interval: 30s
    params:
      -instance: ['372c43937e6acd56073246ffdf0e95597480cdba24688cc331d77a8c3c07e1a9','be007691832f4002a86cf0148768a3b039304e9b1fa7ae91a032b0beddc152b2']
    static_configs:
      - targets: ['example.com']
    metrics_path: /metrics
    scheme: https

That way I get two sequences of metrics within the same job name.

Is there anything that can group these two sequences into one?

I know that I can query the Prometheus with a sum and combine them in every query, but I would like to simplify this and query them as a single sequence.

🌐
Super User
superuser.com › questions › 1768794 › prometheus-join-on-metric-value-rather-than-label
Prometheus join on metric value, rather than label? - Super User
February 15, 2023 - You can do such a join using == and group_left. For example provided in question something like this. ifIndex == on(instance) group_left(ipAddressAddr) ipAddressIfIndex · This query will take all pair of metrics ifIndex and ipAddressIfIndex ...
🌐
Medium
medium.com › @atatus › how-to-join-two-metrics-in-prometheus-f36a6cde2f6b
How to Join two metrics in Prometheus? | by Atatus | Medium
October 25, 2024 - By using group_left, the query aligns the two datasets based on the shared method label, while retaining the code information from the left-side dataset. This approach ensures that each combination of method and code is appropriately matched with its corresponding total request count based on the method, allowing for an accurate comparison. ... Once metrics are joined in Prometheus using label matching techniques (like on, ignoring, group_left, or group_right), you can apply various mathematical operations to analyze the data and derive meaningful insights.
🌐
GitHub
github.com › prometheus › prometheus › issues › 2393
Join two metrics as label to some other metric [HELP/DIRECTIONS needed] · Issue #2393 · prometheus/prometheus
February 3, 2017 - Hi, I would like to make a join operation between two metrics and expect the metric values to be in single response. Consider this situation : ifOutOctets - which gives number of packets transmitte...
Author: prometheus
🌐
Last9
last9.io › blog › query-multiple-metrics-in-prometheus
Easily Query Multiple Metrics in Prometheus | Last9
February 21, 2026 - In monitoring setups, working with a single metric rarely tells the complete story. The real power of Prometheus lies in its ability to query multiple metrics simultaneously, creating connections between different data points that reveal the true state of your systems.
🌐
Boldena
boldena.com › article › 79981
How can I 'join' two metrics in a Prometheus query? | BolDena
In your Prometheus query, you can use label_replace and group_left to combine the metrics based on the common labels service_name and node. ... # Use `label_replace` to filter and align labels health_status = label_replace(consul:health_ser...
🌐
Grafana
community.grafana.com › prometheus
Combine/join two different prometheus metrics into one table - Prometheus - Grafana Labs Community Forums
October 25, 2022 - I’m using grafana+prometheus+telegraf for monitoring certain web servers. I’m collecting metrics for certificate information: x509_cert_expiry and dns status: dns_query_rcode_value exposed by telegraf for a single web se…