It is possible using unless operator:
item_stock unless item_purchases
Results in a vector consisting of the elements of item_stock for which there are no elements in item_purchases with exactly matching label sets. All matching elements in both vectors are dropped.
Note that the metrics in question do not have 'exactly matching label sets' (name is common but count and in_stock are not). In this case you can use on to set the list of labels to match:
item_stock unless on(name) item_purchases
Answer from anemyte on Stack OverflowPromql outer join support
Proposal Outer join (especially left join & right join) are very useful. For example: We have one host level CPU alert (CPU > 70%), and we have another spatial aggregation metrics on pool le... More on github.com
Making joins simpler in PromQL
At yesterday's dev summit, and as part of the discussion around prometheus/snmp_exporter#180 , @brian-brazil also suggested making joins easier to write. This issue is to document possible chan... More on github.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
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
github.com › prometheus › prometheus › issues › 5841
Promql outer join support · Issue #5841 · prometheus/prometheus
August 7, 2019 - Promql outer join support#5841 · Copy link · garrettlish · opened · on Aug 7, 2019 · Issue body actions · Outer join (especially left join & right join) are very useful. For example: We have one host level CPU alert (CPU > 70%), and we have another spatial aggregation metrics on pool level (host count in a pool).
Author: prometheus
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).
GitHub
github.com › prometheus › prometheus › issues › 15146
simpler syntax for joins on labels with different names · Issue #15146 · prometheus/prometheus
October 10, 2024 - 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 with a pod label · A some_custom_pod_info metric with a exported_pod label ... container_fs_reads_total{} * on(pod) group_left label_replace(some_custom_pod_info{}, "pod", "$1", "exported_pod", "(.*)")
Author: prometheus
GitHub
github.com › prometheus › prometheus › issues › 2204
Joining different labels · Issue #2204 · prometheus/prometheus
November 18, 2016 - 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 ...
Author: prometheus
Felixhummel
blag.felixhummel.de › 25 › 08-01-til-prometheus-promql-left-join.html
TIL: Prometheus (PromQL) LEFT JOIN — Felix' Wobsite
August 1, 2025 - SELECT * FROM node_exporter_build_info LEFT OUTER JOIN node_os_info ON a.foo = b.foo AND a.bar = b.bar
Scamcalculate
iai.scamcalculate.pw › promql-join.html
Promql join. SQL | Join (Inner, Left, Right and Full Joins)
Dismiss Join GitHub today GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Sign up. Prometheus Query CLI. Go Branch: master. Find file. Sign in Sign up. Go back. Launching Xcode If nothing happens, download Xcode and try again. Latest commit Fetching latest commit…. Promql CLI Query prometheus from the command line for quick analysis.
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 - Run a single rule per metric that uses a PromQL join to inject the appropriate reference label into the generated series. ... groups: - name: slo_metric expr: count(api_response_latency{labelone="xyz", labeltwo="abc"} > 100) labels: reference_label: xyzabc ... This file would be collected by Grafana Agent. Then the following rule group could be used in Cortex: ... groups: - name: slo_metric expr: count by (reference_label) ((api_response_latency * on (labelone,labeltwo) group_left(reference_label) sli_info > 100)
Google Groups
groups.google.com › g › prometheus-users › c › qlHK7r1hQVs
Joining two metrics in promtheus and having all labels from both
March 6, 2023 - https://www.robustperception.io/left-joins-in-promql