fix: 容器监控适配部分单核系统 (#984)

This commit is contained in:
ssongliu 2023-05-10 14:48:15 +08:00 committed by GitHub
parent dd89933613
commit 8083837333
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -326,7 +326,10 @@ func calculateCPUPercentUnix(stats *types.StatsJSON) float64 {
systemDelta := float64(stats.CPUStats.SystemUsage) - float64(stats.PreCPUStats.SystemUsage)
if systemDelta > 0.0 && cpuDelta > 0.0 {
cpuPercent = (cpuDelta / systemDelta) * float64(len(stats.CPUStats.CPUUsage.PercpuUsage)) * 100.0
cpuPercent = (cpuDelta / systemDelta) * 100.0
if len(stats.CPUStats.CPUUsage.PercpuUsage) != 0 {
cpuPercent = cpuPercent * float64(len(stats.CPUStats.CPUUsage.PercpuUsage))
}
}
return cpuPercent
}