diff options
author | Paul Holzinger <pholzing@redhat.com> | 2022-03-22 17:10:43 +0100 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2022-03-22 17:43:49 +0100 |
commit | 0edb3ddd39ec5ed80cf580148b119d0528875fa9 (patch) | |
tree | de2279d53b74ed77fe292e1c8afe07fa658f3f00 /pkg/api/handlers | |
parent | 02aae4a65856305f657bc3684ad1ac2a47fbc30e (diff) | |
download | podman-0edb3ddd39ec5ed80cf580148b119d0528875fa9.tar.gz podman-0edb3ddd39ec5ed80cf580148b119d0528875fa9.tar.bz2 podman-0edb3ddd39ec5ed80cf580148b119d0528875fa9.zip |
podman stats: calc CPU percentage correctly
When you run podman stats, the first interval always shows the wrong cpu
usage. To calculate cpu percentage we get the cpu time from the cgroup
and compare this against the system time between two stats. Since the
first time we do not have a previous stats an empty struct is used
instead. Thus we do not use the actual running time of the container but
the current unix timestamp (time since Jan 1 1970).
To fix this we make sure that the previous stats time is set to the
container start time, when it is empty.
[NO NEW TESTS NEEDED] No idea how I could create a test which would have
a predictable cpu usage.
See the linked bugzilla for a reproducer.
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2066145
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'pkg/api/handlers')
-rw-r--r-- | pkg/api/handlers/compat/containers_stats.go | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/pkg/api/handlers/compat/containers_stats.go b/pkg/api/handlers/compat/containers_stats.go index 99f14d02f..77b16b03e 100644 --- a/pkg/api/handlers/compat/containers_stats.go +++ b/pkg/api/handlers/compat/containers_stats.go @@ -56,7 +56,7 @@ func StatsContainer(w http.ResponseWriter, r *http.Request) { return } - stats, err := ctnr.GetContainerStats(&define.ContainerStats{}) + stats, err := ctnr.GetContainerStats(nil) if err != nil { utils.InternalServerError(w, errors.Wrapf(err, "failed to obtain Container %s stats", name)) return |