Prometheus查询在Grafana变量中无法正常工作。

huangapple go评论58阅读模式
英文:

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)&lt;50)
or on() (vector(2) and on() (sum(node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate)/0.04)&lt;80)
or on() vector(3)

Prometheus查询在Grafana变量中无法正常工作。

答案1

得分: 1

以下是您要翻译的内容:

你在这里有一些问题:

  1. 查询过于复杂,无法直接解析。如果使用函数 query_result,Grafana 将更好地理解它的预期操作。
  2. 你的查询包含换行符,出于某种原因,Grafana 对它们感到不满意。

我使用类似的查询重现了您的错误,一旦删除了换行符,它就开始正常工作了。

我的查询:

query_result((vector(1) and on() (sum(node_cpu_seconds_total)/0.04)&lt;1000000000) or (vector(2) and on() (sum(node_cpu_seconds_total)/0.04)&lt;8000000000) or vector(3))

在 play.grafana.com 进行了测试。

英文:

You have a couple of problems here:

  1. 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.
  2. 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)&lt;1000000000) or (vector(2) and on() (sum(node_cpu_seconds_total)/0.04)&lt;8000000000) or vector(3))

Tested at play.grafana.com

huangapple
  • 本文由 发表于 2023年5月11日 02:46:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76221698.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定