You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The API docs about container stats are missing important bits of information.
I had to dig into the source code for the cli stats command (here: https://github.com/docker/cli/blob/19.03/cli/command/container/stats_helpers.go#L166) to discover that memory usage is actually memory_stats.usage - memory_stats.stats.cache, so percentage used is calculated as (memory_stats.usage - memory_stats.stats.cache) / memory_stats.limit * 100.0
and that cpu usage has to be muliplied by the number of cpus - (diff(cpu_stats.cpu_usage.total_usage) / diff(cpu_stats.system_cpu_usage)) * number_cpus * 100.0.
Problem description
The API docs about container stats are missing important bits of information.
I had to dig into the source code for the cli stats command (here: https://github.com/docker/cli/blob/19.03/cli/command/container/stats_helpers.go#L166) to discover that memory usage is actually
memory_stats.usage - memory_stats.stats.cache
, so percentage used is calculated as(memory_stats.usage - memory_stats.stats.cache) / memory_stats.limit * 100.0
and that cpu usage has to be muliplied by the number of cpus -
(diff(cpu_stats.cpu_usage.total_usage) / diff(cpu_stats.system_cpu_usage)) * number_cpus * 100.0
.Problem location
URL: https://docs.docker.com/engine/api/v1.40/#operation/ContainerStats
Suggestions for a fix
An example containing the above calculations would be nice, even nicer if it is accompanied by an explanation of what exactly these values represent.
The text was updated successfully, but these errors were encountered: