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.
I created the following query:
(windows_scheduled_task_state{job=“windows-servers”, state=“running”}==1) and (windows_scheduled_task_last_result{job=“windows-servers”}==0)
And altough I have metric that fits to both criteria I get emptry result.
- What Grafana version and what operating system are you using?
Grafana version 9.3.6, Prometheus 2.42.0
It is not a question about Grafana, but about PromQL (so this is not a best forum). Check D
doc (e.g. Operators | Prometheus):
vector1 and vector2
results in a vector consisting of the elements of vector1
for which there are elements in vector2
with exactly matching label sets. Other elements are dropped. The metric name and values are carried over from the left-hand side vector.
So I would say that and
is not what you need. Check some recommendations how to implement boolean algebra in PromQL: Booleans, logic and math – Robust Perception | Prometheus Monitoring Experts
Thank you for pointing me to right direction! Solved it like this:
count(windows_scheduled_task_last_result{job=“windows-servers”}==0 or windows_scheduled_task_state{ job=“windows-servers”, state=“running”}==1) by (task,instance,hostname)