英文:
Prometheus query not working for Grafana Variable
问题
I am trying to create a variable in Grafana using below query to return me a number based on cpu usage percentage. This works fine for panels but it throws an error when I try to create a variable out of it.
(向量(1)和 on() (sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate)/0.04)<50)
或 on() (vector(2) 和 on() (sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate)/0.04)<80)
或 on() vector(3)
英文:
I am trying to create a variable in Grafana using below query to return me a number based on cpu usage percentage. This works fine for panels but it throws an error when I try to create a variable out of it.
(vector(1) and on() (sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate)/0.04)<50)
or on() (vector(2) and on() (sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate)/0.04)<80)
or on() vector(3)
答案1
得分: 1
以下是您要翻译的内容:
你在这里有一些问题:
- 查询过于复杂,无法直接解析。如果使用函数
query_result
,Grafana 将更好地理解它的预期操作。 - 你的查询包含换行符,出于某种原因,Grafana 对它们感到不满意。
我使用类似的查询重现了您的错误,一旦删除了换行符,它就开始正常工作了。
我的查询:
query_result((vector(1) and on() (sum(node_cpu_seconds_total)/0.04)<1000000000) or (vector(2) and on() (sum(node_cpu_seconds_total)/0.04)<8000000000) or vector(3))
在 play.grafana.com 进行了测试。
英文:
You have a couple of problems here:
- query is too complicated to be parsed as is. Grafana will have better understanding what is it expected to do, if function
query_result
is used. - you query contains new-lines, and Grafana is not happy with them for whatever reason.
I reproduced your error with similar query, and it began to work correctly, once new-lines were removed.
My query:
query_result((vector(1) and on() (sum(node_cpu_seconds_total)/0.04)<1000000000) or (vector(2) and on() (sum(node_cpu_seconds_total)/0.04)<8000000000) or vector(3))
Tested at play.grafana.com
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论