Filter one query by value of another

101 views
Skip to first unread message

Patrick Macdonald

unread,
Mar 17, 2021, 7:19:15 PM3/17/21
to Prometheus Users
This seems a pretty simple thing to achieve so apologies if it's been answered here a hundred times before. 

If I have two metrics : 
"state"
"swap"

Each metric has records from different hosts, so they both have a "host" label. 

eg 
1. state, label {host="machineA"} value 0
2. state, label {host="machineB"} value 1
3. swap,  label {host="machineA"} value 1234
4. swap,  label {host="machineb"} value 123

I want to filter my graph of "swap" so that any hosts with a "state" value of "0" are removed/ignored. 

What's the trick?
Is the correct nomenclature for this "Filtering series A by series B"? (I'm still trying to get my head around the correct terminology to use).

Thanks in advance for your help.
Patrick

David Leadbeater

unread,
Mar 18, 2021, 4:59:24 AM3/18/21
to Patrick Macdonald, Prometheus Users
The most readable for a case like this is to use unless, something like:

swap unless on(host) state == 0

You can also turn the logic around, using and, e.g.:

swap and on(host) state > 0

David

--
You received this message because you are subscribed to the Google Groups "Prometheus Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to prometheus-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/prometheus-users/44b33eb4-5b55-4fe8-aff8-c90c1215309fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages