I found here this solution: {__name__=~"metricA|metricB|metricC",container_name=~"frontend|backend|db"}.

Answer from roie on Stack Overflow
🌐
Last9
last9.io › blog › query-multiple-metrics-in-prometheus
Easily Query Multiple Metrics in Prometheus | Last9
February 21, 2026 - There are two main types: One-to-one matching: Each time series from the left side matches with exactly one time series from the right side. Many-to-one/one-to-many matching: One side can match with multiple time series from the other side.
Discussions

How to execute a query with two metrics in Prometheus? - Stack Overflow
However I have saw a few answers ... queries. I will consider that VictoriaMetrics might pays off to have another library on top of prometheus. Thank you for letting me know :+1: 2022-04-07T06:19:59.733Z+00:00 ... Save this answer. ... Show activity on this post. It is possible to select multiple metric names with ... More on stackoverflow.com
🌐 stackoverflow.com
Visualizing two metrics on the same graph
does this means that the best way to display metrics is not by using prometheus itself but attaching to grafana and using grafana capabilities ? Yes, the expression browser doesn't have that feature. It's meant more for ad-hoc work. Also i saw robustperception post on how to check if ssh is responding or not ; is there a way to see which process name is listening to a given port ? sudo netstat -nlpt More on reddit.com
🌐 r/PrometheusMonitoring
6
5
January 11, 2017
grafana - Query multiple metrics in one Prometheus HTTP Call - Stack Overflow
I want to make one http call to Prometheus server and get the following: Multiple metrics Calculate rate for all metrics within last 30 seconds I have the following query which works, it requests... More on stackoverflow.com
🌐 stackoverflow.com
Multiple Prometheus queries
Hello I am trying to achieve following situation: I have two prometheus metrics: windows_scheduled_task_last_result windows_scheduled_task_state they are both binary. What I want to have is a query that checks if windows_scheduled_task_last_result for a task is equal to 0 and windows_sched... More on community.grafana.com
🌐 community.grafana.com
1
0
March 21, 2023
🌐
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 - Instead, it uses vector matching ... join, where only matching elements are included in the result. Yes, you can join multiple metrics by chaining operations....
🌐
Google Groups
groups.google.com › g › prometheus-users › c › 59VKF1kHmhU
How to query Multiple Metric with PromQL
I tried, but the operator "or" will return just one value with "or" of multiple values from multiple queries. Vào 16:50:16 UTC+7 Thứ Tư, ngày 11 tháng 9 năm 2019, tgug...@redhat.com đã viết: Have you tried using the "or" operator to combine these two queries? On Wed, 2019-09-11 at 02:36 -0700, Mạnh Nguyễn Tiến wrote: ... > http://Prometheus_IP_Address/api/v1/query?query={__name__=~”node_memory_Buffers_bytes|node_cpu_seconds_total”,instance=”Node_Exporter_IPAddress”}
🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › basics
Querying basics | Prometheus
The value returned will be that of the most recent sample at or before the query's evaluation timestamp (in the case of an instant query) or the current step within the query (in the case of a range query). The @ modifier allows overriding the timestamp relative to which the selection takes place. Time series are only returned if their most recent sample is less than the lookback period ago. This example selects all time series that have the http_requests_total metric name, returning the most recent sample for each:
Top answer
1 of 2
14

First of all, for more complex graphing you should definitely investigate Grafana. The built-in Prometheus graphs are useful eg. for debugging, but definitely more limited. In particular one graph will only display the results of one query.

Now for a hack that I definitely do not recommend:

flink_taskmanager_job_task_operator_numRecordsInPerSecond{operator_name="Map"}
or
label_replace(flink_taskmanager_job_task_operator_numRecordsOutPerSecond{operator_name="Map"}, "distinct", "foo", "job", ".*")

Since, as documented

vector1 or vector2 results in a vector that contains all original elements (label sets + values) of vector1 and additionally all elements of vector2 which do not have matching label sets in vector1.

you can add a new label that is not present in the labels on the first vector to the second vector and thus keep all elements from both.

2 of 2
13

It is possible to select multiple metric names with a single PromQL query by using a regular expression filter on __name__ label:

{__name__=~"flink_taskmanager_job_task_operator_numRecords(In|Out)PerSecond",operator_name="Map"}

See docs about the __name__ label here.

There is another solution when using Prometheus-compatible query engine such as MetricsQL by using union function:

union(
 
 flink_taskmanager_job_task_operator_numRecordsInPerSecond{operator_name="Map"},
 
 flink_taskmanager_job_task_operator_numRecordsOutPerSecond{operator_name="Map"}
)

Note that selecting multiple time series via __name__ regexp can result in vector cannot contain metrics with the same labelset error if the selected series are wrapped in any PromQL function. For example:

max_over_time(
 
 {__name__=~"flink_taskmanager_job_task_operator_numRecords(In|Out)PerSecond",operator_name="Map"}[5m]
)

This is because Prometheus removes metric names from input series when applying PromQL functions. MetricsQL from VictoriaMetrics provides a solution for this issue - keep_metric_names modifier (see these docs for details):

max_over_time(
 
 {__name__=~"flink_taskmanager_job_task_operator_numRecords(In|Out)PerSecond",operator_name="Map"}[5m]
)
keep_metric_names

P.S. I work on VictoriaMetrics and MetricsQL.

🌐
Prometheus
prometheus.io › docs › prometheus › latest › querying › examples
Query examples | Prometheus
If we have two different metrics with the same dimensional labels, we can apply binary operators to them and elements on both sides with the same label set will get matched and propagated to the output.
🌐
Grafana
grafana.com › blog › 2021 › 08 › 04 › 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....
Find elsewhere
🌐
Iximiuz
iximiuz.com › en › posts › prometheus-vector-matching
Prometheus Cheat Sheet - How to Join Multiple Metrics (Vector Matching)
November 30, 2021 - Luckily, Prometheus does support many-to-one and one-to-many vector matching. But it has to be specified explicitly by adding either group_left or group_right modifier to a query.
🌐
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
For instance, if you want to calculate the total request time for each request type, you can multiply the number of requests by their average response time: ... However, you may need to ensure both metrics are appropriately aligned. If they have different labels, you might want to use the ignoring or on keywords. If both metrics share common labels (like method), you can join them based on those labels: ... This query sums up the total requests and the total response times for each HTTP method and then multiplies them based on the shared method label.
🌐
Reddit
reddit.com › r/prometheusmonitoring › visualizing two metrics on the same graph
r/PrometheusMonitoring on Reddit: Visualizing two metrics on the same graph
January 11, 2017 -

Hello, i've been testing prometheus 1.4.1 and i've been wondering if it is possible to put two different metrics (for example memory used and memory free) on the same graph.

I've been looking for a way to do that but so far no luck; does this means that the best way to display metrics is not by using prometheus itself but attaching to grafana and using grafana capabilities ?

Also i saw robustperception post on how to check if ssh is responding or not ; is there a way - using prometheus - to see which process name is listening to a given port (this for sanity check purpose)?

edit: corrected one question

🌐
OneUptime
oneuptime.com › home › blog › how to join two metrics in prometheus query
How to Join Two Metrics in Prometheus Query
December 17, 2025 - Prometheus doesn't have traditional SQL-style JOINs, but it provides powerful vector matching operators that let you combine metrics from different sources.
🌐
Atatus
atatus.com › blog › how-to-join-two-metrics-in-prometheus
How to Join two metrics in Prometheus?
August 12, 2025 - For example, http_requests_total is a metric that tracks the total number of HTTP requests. Querying this in PromQL retrieves all data points related to the total HTTP requests over time. Prometheus labels are key-value pairs associated with metrics that provide extra context and details.
🌐
Google Groups
groups.google.com › g › prometheus-developers › c › exc5RKBLpOg
Prometheus Query Rest API for Multiple metrics
I could find only four type of query( Instant queries, Range queries, Querying metadata, Querying label values ). -- You received this message because you are subscribed to the Google Groups "Prometheus Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-developers+unsub...@googlegroups.com.
🌐
Grafana
community.grafana.com › prometheus
Multiple Prometheus queries - Prometheus - Grafana Labs Community Forums
March 21, 2023 - Hello I am trying to achieve following situation: I have two prometheus metrics: windows_scheduled_task_last_result windows_scheduled_task_state they are both binary. What I want to have is a query that checks if windows_scheduled_task_last_result for a task is equal to 0 and windows_scheduled_task_state{state=“running”} for the same task is equal to 1 then don’t fire alert, otherwise alert should fire.
🌐
Google Groups
groups.google.com › g › prometheus-users › c › PMYdrC5solU
HTTP API request for querying multiple metrics
March 23, 2023 - It is possible to make PromQL queries which use calculations based on multiple metrics. There is "and", "or" and other operators. If you want to get the raw data via the API instead, you might have better luck by using the federate endpoint: https://prometheus.io/docs/prometheus/latest/federation/ ...
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
Top answer
1 of 1
2

First of all, consider converting you metrics to the best practices of Prometheus. I anticipate something like this:

mysystem_request_duration_seconds_sum{type="XXXX"}
mysystem_request_duration_seconds_count{type="XXXX"}
mysystem_request_duration_seconds_sum{type="YYYY"}
mysystem_request_duration_seconds_count{type="YYYY"}

This way you wouldn't need all this hustle with metric names.

In this case your query would look like this:

sum by (container) (
rate(mysystem_request_duration_seconds_sum{type="$myVar"}[5m]) / 
rate(mysystem_request_duration_seconds_count{type="$myVar"}[5m]) )

For your current situation you'll need to employ a couple of tricks:

  1. Since you can't query multiple metrics by name with regex, you'll need to use {__name__=~"${myVar_metrics}_sum"}.
  2. To divide metrics, you need them to have matching labels.
    You can add label to metric based on metrics name using label_replace:
label_replace({__name__=~"${myVar_metrics}_sum"} ,"foo", "$1", "__name__", "(${myVar_metrics})_sum")
  1. Range selector can be applied only to a metric selector. Since label_replace is a function and not a metric selector, you'll need to use subquery syntax. Basically, the difference is addition of semicolon into range selector:
rate(label_replace({__name__=~"${myVar_metrics}_sum"} ,"foo", "$1", "__name__", "(${myVar_metrics})_sum")[5m : ])

Resulting query would look like this:

sum by (container) (
 rate(
  label_replace(
   {__name__=~"${myVar_metrics}_sum"} ,
   "foo", "$1",
   "__name__", "(${myVar_metrics})_sum")
  [5m : ])
/rate(
  label_replace(
   {__name__=~"${myVar_metrics}_count"} ,
   "foo", "$1", 
   "__name__", "(${myVar_metrics})_count")
  [5m : ])
)
🌐
NSRC
nsrc.org › workshops › 2021 › sanog37 › nmm › netmgmt › en › prometheus › ex-promql-basic.htm
ex-promql-basic
This is an unusual query to do, but it demonstrates the point, and it is occasionally useful: for example using regular expression matching you can query multiple metrics at once. Here you can ask prometheus for all the metrics which start with node_filesystem_: