英文:
grafana + prometheus conditional query
问题
I have this query:
sum by (name) (rate(container_cpu_usage_seconds_total{image!="", container_label_org_label_schema_group="$group"}[1m])) / scalar(count(node_cpu_seconds_total{mode="$mode"})) * 100
$group
is a list and values can be 'monitoring', 'web', or 'all'.
When $group
is 'web', I'd like to replace $group
with an empty string. So the container_label_org_label_schema_group
condition should be:
container_label_org_label_schema_group = ''
When $group
is 'all', then I want to match where container_label_org_label_schema_group
is equal to 'monitoring' or an empty string. Effectively something like:
container_label_org_label_schema_group = '"monitoring"|"'"'"
Not sure how to do this with the promQL. It doesn't seem like the use of some AND operators to do pseudo IFs is working here. I'm thinking maybe substitution could be an option. But I do not have success there either.
英文:
I have this query:
sum by (name) (rate(container_cpu_usage_seconds_total{image!="",
container_label_org_label_schema_group="$group"}
[1m])) / scalar(count(node_cpu_seconds_total{mode="$mode"})) * 100
$group
is a list and values can be 'monitoring', 'web', or 'all'.
When $group
is 'web', I'd like to replace $group
with empty string. So the container_label_org_label_schema_group
condition should be:
container_label_org_label_schema_group = ''
When $group
is 'all', then i want to match where container_label_org_label_schema_group
is equal to 'monitoring' or empty string. Effectively something like:
container_label_org_label_schema_group = '"monitoring"|""'
Not sure how to do do this with the promQL. It doesn't seem like the use of some AND operators to do pseudo IFs is working here. I'm thinking maybe substitution could be an option. But I don't not have success there either.
答案1
得分: 1
In Grafana,您可以为您的每个变量值指定标签:它将显示在下拉菜单中。但在替代时,将使用相应的值。
要执行此操作,请以以下格式提供变量的值:标签1:值1,标签2:值2
。
然后只需在查询中使用它,如$example
。
对于您的确切问题,请使用具有以下值的变量:
web:,monitoring:monitoring,all:monitoring|
请注意在第一个冒号和逗号之间有双空格。
英文:
Not really. In grafana you can specify label for every value of you variable: it will be shown in drop down. But when substituted corresponding value will be used instead.
To do it you provide values for variable in format label1 : value1, label2 : value2
.
And then simply use it in query like $example
For your exact problem use variable with the following values:
web : , monitoring : monitoring, all : monitoring|
Please notice double space between first colon and comma.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论