0

一次运行两个查询时遇到错误。

查询1:

sum by(container_label_io_kubernetes_pod_name) (rate (container_cpu_usage_seconds_total{container_label_io_kubernetes_container_name=~"demo-api"}[1m]))

输出/输出:

{container_label_io_kubernetes_pod_name="demo-api-demo-api-7c8d7c75d-sfrsg"}    0.15590349995998623
{container_label_io_kubernetes_pod_name="demo-api-demo-api-7c8d7c75d-nnxqz"}    0.22167272938000676
{container_label_io_kubernetes_pod_name="demo-api-demo-api-7c8d7c75d-zbcdk"}    0.14510123627695987

欧瑞2:

avg(kube_pod_container_resource_requests_cpu_cores{container="demo-api"})

输出/输出:

Element     Value
{}  1

最终查询(q1/q2):

(sum by(container_label_io_kubernetes_pod_name) (rate (container_cpu_usage_seconds_total{container_label_io_kubernetes_container_name=~"demo-api"}[1m])))
/(avg(kube_pod_container_resource_requests_cpu_cores{container="demo-api"}))

未找到数据点。

4

1 回答 1

1

此处的Prometheus 文档描述了矢量匹配的工作原理。为了您的操作成功,您需要container_label_io_kubernetes_pod_name在除法期间忽略标签:

(sum by(container_label_io_kubernetes_pod_name) (rate (container_cpu_usage_seconds_total{container_label_io_kubernetes_container_name=~"demo-api"}[1m])))
/
ignoring(container_label_io_kubernetes_pod_name) group_left 
avg(kube_pod_container_resource_requests_cpu_cores{container="demo-api"})
于 2019-05-13T23:39:57.377 回答