如何在prometheus中获取cpu和nodes/pods的内存使用情况?

How to get cpu and memory usage of nodes/pods in prometheus?

作为初学者,我尝试了 k9s 和 kubernetes 'kubectl top nodes',对于 cpu 和内存使用和值是 matched.Meanwhile 我尝试了 prometheus UI,对于 dev-node01,使用“avg(container_cpu_user_seconds_total{node="dev-node01"})”和“avg(container_cpu_usage_seconds_total{node="dev-node01"})”。我无法获得匹配 values.Any 帮助将不胜感激,因为我是 beginner.please 任何帮助将不胜感激。

如果指标 'container_cpu_user_seconds_total' 显示输出,那么它应该可以工作。我使用了您上面提到的相同查询,它对我有用。在 Prometheus 中检查图形和控制台选项卡。

请试试这个

avg(container_cpu_user_seconds_total{node="NODE_NAME"})

container_cpu_usage_seconds_total 是一个 counter,因此您需要了解这意味着什么以及如何查询计数器。

在这种情况下,您可能需要使用 rate 函数,documented here

rate(v range-vector) calculates the per-second average rate of increase of the time series in the range vector... rate should only be used with counters... Note that when combining rate() with an aggregation operator, always take a rate() first, then aggregate.

每个 pod CPU 用法的示例查询为:

sum(rate(container_cpu_usage_seconds_total{}[1h])) by (pod_name, namespace)

此外,您可能想查看 Kubecost 以了解 k8s 分配指标和 API。