diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-03-22 17:37:23 +0100 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-03-22 17:44:58 +0100 |
commit | 130bcc3a93d82674eaaf2a62f854983db263a940 (patch) | |
tree | 20f21ee7dc6b065875a471cf7a669cd470eca4f0 /libpod/stats.go | |
parent | 0edb3ddd39ec5ed80cf580148b119d0528875fa9 (diff) | |
download | podman-130bcc3a93d82674eaaf2a62f854983db263a940.tar.gz podman-130bcc3a93d82674eaaf2a62f854983db263a940.tar.bz2 podman-130bcc3a93d82674eaaf2a62f854983db263a940.zip |
podman stats: improve cpu average calc
We can just calculate the cpu percent for the time the container is
running. There is no need to use datapoints.
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'libpod/stats.go')
-rw-r--r-- | libpod/stats.go | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/libpod/stats.go b/libpod/stats.go index 988aa4b5c..25baa378d 100644 --- a/libpod/stats.go +++ b/libpod/stats.go @@ -77,8 +77,8 @@ func (c *Container) GetContainerStats(previousStats *define.ContainerStats) (*de stats.Duration = cgroupStats.CPU.Usage.Total stats.UpTime = time.Duration(stats.Duration) stats.CPU = calculateCPUPercent(cgroupStats, previousCPU, now, previousStats.SystemNano) - stats.AvgCPU = calculateAvgCPU(stats.CPU, previousStats.AvgCPU, previousStats.DataPoints) - stats.DataPoints = previousStats.DataPoints + 1 + // calc the average cpu usage for the time the container is running + stats.AvgCPU = calculateCPUPercent(cgroupStats, 0, now, uint64(c.state.StartedTime.UnixNano())) stats.MemUsage = cgroupStats.Memory.Usage.Usage stats.MemLimit = c.getMemLimit() stats.MemPerc = (float64(stats.MemUsage) / float64(stats.MemLimit)) * 100 @@ -156,9 +156,3 @@ func calculateBlockIO(stats *cgroups.Metrics) (read uint64, write uint64) { } return } - -// calculateAvgCPU calculates the avg CPU percentage given the previous average and the number of data points. -func calculateAvgCPU(statsCPU float64, prevAvg float64, prevData int64) float64 { - avgPer := ((prevAvg * float64(prevData)) + statsCPU) / (float64(prevData) + 1) - return avgPer -} |