35

我正在通过 Prometheus.io 监控 docker 容器。我的问题是我只是得到cpu_user_seconds_totalor cpu_system_seconds_total

如何将这个不断增加的值转换为 CPU 百分比?

目前我正在查询:

rate(container_cpu_user_seconds_total[30s])

但我不认为这是完全正确的(与顶部相比)。

如何转换cpu_user_seconds_total为 CPU 百分比?(如上图)

4

3 回答 3

48

Rate 返回每秒的值,因此乘以 100 将得到一个百分比:

rate(container_cpu_user_seconds_total[30s]) * 100

于 2016-01-21T17:36:35.497 回答
31

我还发现这种方法可以使 CPU 使用率准确:

100 - (avg by (instance) (irate(node_cpu_seconds_total{job="node",mode="idle"}[5m])) * 100)

来自:http ://www.robustperception.io/understanding-machine-cpu-usage/

于 2016-08-11T11:09:07.000 回答
3

对于 Windows 用户 - wmi_exporter

100 - (avg by (instance) (irate(wmi_cpu_time_total{mode="idle"}[2m])) * 100)
于 2020-03-24T20:39:49.130 回答