I have a simple PromQL query that performs a count:
sum(up{container_name="my-container",environment_name="$env"})
This is part of a Grafana Dashboard and allows for ${env} to be selected from a drop down menu.
I would like to perform different queries depending on the environment.
How do I construct something like this in PromQL:
if ${env} == 'dev' or ${env} == 'integration':
if sum(up{container_name="my-container",environment_name="$env"}) == 1:
sum(up{container_name="my-container",environment_name="$env"}) + 1
else:
sum(up{container_name="my-container",environment_name="$env"})
else:
sum(up{container_name="my-container",environment_name="$env"})
The purpose is to falsely inflate the count to trigger a healthy threshold in a RAG status panel in environments that are running single containers.
You can query like this:
(
sum(up{container_name="my-container", environment_name=~"dev|integration", environment_name="$env"}) + 1
AND
(sum(up{container_name="my-container", environment_name=~"dev|integration", environment_name="$env"} == 1)
)
OR
sum(up{container_name="my-container", environment_name=~"dev|integration", environment_name="$env"}) != 1
OR
sum(up{container_name="my-container", environment_name="prod", environment_name="$env"})
OR
on() vector(0)
this will return the amount of instances increased by one when the amount of instances is 1 (thats what the and
does) and the user selected the dev or integration environment.
The or
would al three metrics at once, but due to the query and the users selection, there can be only one metric that is returned.