Docker容器统计数据在使用时超过100%docker stats怎么可能?最大 CPU 不应该 <= 100 吗?
类似的输出:
$ docker stats
CONTAINER ID NAME CPU %
b95a83497c91 awesome_brattain 152.28%
67b2525d8ad1 foobar 0.00%
e5c383697914 test-1951.1.kay7x1lh1twk9c0oig50sd5tr 0.00%
4bda148efbc0 random.1.vnc8on831idyr42slu578u3cr 0.00%
Run Code Online (Sandbox Code Playgroud)
我的用例是,我试图找到容器可以从当前裸机主机的 CPU 中获得的最大使用量。
如果报告结果是可用核心的计数。如果我有 4 线程 CPU,最大值是否会达到 400%?还是 200% 因为我只有 2 个核心?
Uku*_*kit 10
这是因为您可以拥有多个 CPU 核心,这种情况很可能发生。100% CPU 表示一个核心完全被占用。
编辑:虽然我没有找到很好的参考,但我深入研究了源代码:
func calculateCPUPercentUnix(previousCPU, previousSystem uint64, v *types.StatsJSON) float64 {
var (
cpuPercent = 0.0
// calculate the change for the cpu usage of the container in between readings
cpuDelta = float64(v.CPUStats.CPUUsage.TotalUsage) - float64(previousCPU)
// calculate the change for the entire system between readings
systemDelta = float64(v.CPUStats.SystemUsage) - float64(previousSystem)
onlineCPUs = float64(v.CPUStats.OnlineCPUs)
)
if onlineCPUs == 0.0 {
onlineCPUs = float64(len(v.CPUStats.CPUUsage.PercpuUsage))
}
if systemDelta > 0.0 && cpuDelta > 0.0 {
cpuPercent = (cpuDelta / systemDelta) * onlineCPUs * 100.0
}
return cpuPercent
}
Run Code Online (Sandbox Code Playgroud)
这是您在示例中使用的 CLI 统计工具使用的代码。
| 归档时间: |
|
| 查看次数: |
7722 次 |
| 最近记录: |