diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-03-22 17:37:23 +0100 |
---|---|---|
committer | Matthew Heon <mheon@redhat.com> | 2022-03-30 15:36:05 -0400 |
commit | 9510238ff9692a2145be8dc2c712db208cdfd02b (patch) | |
tree | b7abba7d8fee07b455b706f6bf9c36c1777e9382 /libpod | |
parent | 8bc2f6cd8486c893c292da3aa64965d10cd8ffe8 (diff) | |
download | podman-9510238ff9692a2145be8dc2c712db208cdfd02b.tar.gz podman-9510238ff9692a2145be8dc2c712db208cdfd02b.tar.bz2 podman-9510238ff9692a2145be8dc2c712db208cdfd02b.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')
-rw-r--r-- | libpod/define/containerstate.go | 1 | ||||
-rw-r--r-- | libpod/stats.go | 10 |
2 files changed, 2 insertions, 9 deletions
diff --git a/libpod/define/containerstate.go b/libpod/define/containerstate.go index 23ba1f451..9ad3aec08 100644 --- a/libpod/define/containerstate.go +++ b/libpod/define/containerstate.go @@ -138,7 +138,6 @@ type ContainerStats struct { CPU float64 CPUNano uint64 CPUSystemNano uint64 - DataPoints int64 SystemNano uint64 MemUsage uint64 MemLimit uint64 diff --git a/libpod/stats.go b/libpod/stats.go index dbb10a27e..7619ef345 100644 --- a/libpod/stats.go +++ b/libpod/stats.go @@ -66,8 +66,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 @@ -145,9 +145,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 -} |