Filter a Query from Results of Another Query

25 views
Skip to first unread message

Chris Beyers

unread,
Dec 4, 2023, 9:12:57 AM12/4/23
to Prometheus Users
Grab the namespaces we want to collect data on:
sum(kube_namespace_labels{label_machineset="default"}) by (namespace)

Screenshot 2023-12-02 at 5.01.31 PM.png
Inject Into These Results:

kube_resourcequota{resource="limits.cpu",type="hard",namespace={only namespaces from previous query}}

Screenshot 2023-12-02 at 5.05.44 PM.png

How do I go about filtering the resourcequota totals from only namespaces returned in first query?

Much thanks!

Chris

Bryan Boreham

unread,
Dec 4, 2023, 9:15:32 AM12/4/23
to Prometheus Users
The trick is to do a "join", which in PromQL terms can be an arithmetic expression.
Since the value of the first set of series is always 1, you can join by multiplying the two together.

Reply all
Reply to author
Forward
0 new messages