如何使用cadvisor的数据来计算Prometheus中的cpu使用和负载

时间:2018-01-04 04:23:29

标签: docker prometheus cadvisor

当我使用cadvisor获取有关docker容器中cpu的信息时,我得到如下信息: enter image description here

我的问题是如何通过cadvisor返回的信息来计算cpu的使用和加载,这与Prometheus相同?Prometheus如何计算cpu的使用情况?

2 个答案:

答案 0 :(得分:0)

Prometheus用于rate()的算法由于处理对齐和计数器重置等问题而有点错综复杂,如Counting with Prometheus中所述。

短版本是从最后一个值中减去第一个值,然后除以它们结束的时间。使用普罗米修斯可能最容易,而不是自己这样做。

答案 1 :(得分:0)

以下查询应返回消耗时间最多的前10个容器:

topk(10, sum(irate(container_cpu_usage_seconds_total{container_label_com_docker_swarm_node_id=~".+", id=~"/docker/.*"}[$interval])) by (name)) * 100