如何在表格视图中显示多个(相似的)查询结果

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

How to display multiple (similar) query results in a table view

问题

Context: 在一个运行在Kubernetes集群上的Prometheus和Grafana中。

有没有一种方法可以在一个视图(表格)中显示来自多个相关查询的结果?进一步解释一下,这些查询非常相似,它们只是在度量中可用的一组可能的标签值上进行过滤。每个查询的结果数据在形式上是相同的。

以下是一些具体的信息。

查询:

(kube_pod_status_phase {phase=~"$pod_phase"}!=0)+ on(pod)group_left(node)(0 * kube_pod_info {node=~"$node"})

整个 on/group_left 逻辑允许我将节点名称与来自 kube_pod_status_phase 的数据关联起来,因为该度量中没有可用。重要的是来自 kube_pod_status_phase 的内容。

我想要做的是为每个节点运行查询,以获取并显示每个有效状态(运行中、挂起等)的Pod数量。我认为查询只需应用一个 count 函数。

示例:

节点 运行中 失败 挂起 ...
node-1 10 1 0 ...
node-2 12 2 1 ...
... ... ... ... ...

我在Grafana文档中进行了一些探索,特别是在转换方面,但找不到使这项工作的方法。

UPDATE:

经过一些研究,我设置了多个查询,然后尝试使用合并转换(https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/transform-data/#merge)。我收到一个错误,指示:当应用于单个帧时,合并没有效果。 我不知道这意味着什么,也不知道如何纠正这个问题。

英文:

Context: Prometheus and Grafana running on a Kubernetes cluster.

Is there a way to display results from multiple related queries in one view (a table)? To explain further, the queries are very similar, they just filter on a set of possible label values available in a metric. The result data is identical in form for each query.

Here is some concrete information.

The query:

(kube_pod_status_phase{phase=~"$pod_phase"} != 0) + on(pod) group_left(node) (0 * kube_pod_info{node=~"$node"})

The whole on/group_left logic is allowing me to associate a node name with the data from kube_pod_status_phase, since that is not available in that metric. The important stuff is what's coming from kube_pod_status_phase.

What I'd like to do is run the query for each node to get and display the number of pods that are in each of the valid states (Running, Pending, etc.). I would think the query would just then have a count function applied.

Example:

Node Running Failed Pending ...
node-1 10 1 0 ...
node-2 12 2 1 ...
... ... ... ... ...

I've poked around in the Grafana documentation, especially in the transformations, but can't find a way to make this work.

UPDATE:

After a little research, I set up the multiple queries and then tried using a merge transformation (https://grafana.com/docs/grafana/latest/panels-visualizations/query-transform-data/transform-data/#merge). I get an error indicating: Merge has no effect when applied on a single frame. I do not know what that means or how to correct the problem.

答案1

得分: 1

你需要一个像这样的查询:

sum by (node, phase) (
  kube_pod_status_phase + on(pod) group_left(node) (0 * kube_pod_info{node=~"$node"})
)

它计算每个节点上每个状态的Pod数量。

将查询选项设置如下(可折叠选项面板在查询下方):

  • 格式: 表格,
  • 类型: 瞬时

之后,添加分组到矩阵的转换,使用以下选项:

  • : phase,
  • : node,
  • 单元格值:

结果将为您提供一个表格,类似于问题描述中的表格,行表示您的节点,列表示Pod的阶段,单元格的值等于相应节点上相应状态的Pod数量。

英文:

You need a query like this:

sum by (node, phase) (
  kube_pod_status_phase + on(pod) group_left(node) (0 * kube_pod_info{node=~"$node"})
)

It calculates number of pods in each status per node.

Set query options (collapsible options pane is under the query) to:

  • Format: Table,
  • Type: Instant.

After that, add Transformation Grouping to matrix, with the following options:

  • Column: phase,
  • Row: node,
  • Cell value: Value.

In result you'll get table similar to described in question, with rows presenting your nodes, columns - phases of pods, and cell values equal to number of pods on respective node in respective state.

huangapple
  • 本文由 发表于 2023年6月22日 00:06:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76525218.html
匿名

发表评论

匿名网友

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

确定