Function: containerStats() ​
containerStats(
opts):Promise<ContainerStatsResponse>
Get container stats based on resource usage
This endpoint returns a live stream of a container’s resource usage statistics.
The precpu_stats is the CPU statistic of the previous read, and is used to calculate the CPU usage percentage. It is not an exact copy of the cpu_stats field.
If either precpu_stats.online_cpus or cpu_stats.online_cpus is nil then for compatibility with older daemons the length of the corresponding cpu_usage.percpu_usage array should be used.
On a cgroup v2 host, the following fields are not set
blkio_stats: all fields other thanio_service_bytes_recursivecpu_stats:cpu_usage.percpu_usagememory_stats:max_usageandfailcntAlso,memory_stats.statsfields are incompatible with cgroup v1.
To calculate the values shown by the stats command of the docker cli tool the following formulas can be used:
- used_memory =
memory_stats.usage - memory_stats.stats.cache - available_memory =
memory_stats.limit - Memory usage % =
(used_memory / available_memory) * 100.0 - cpu_delta =
cpu_stats.cpu_usage.total_usage - precpu_stats.cpu_usage.total_usage - system_cpu_delta =
cpu_stats.system_cpu_usage - precpu_stats.system_cpu_usage - number_cpus =
length(cpu_stats.cpu_usage.percpu_usage)orcpu_stats.online_cpus - CPU usage % =
(cpu_delta / system_cpu_delta) * number_cpus * 100.0
Parameters ​
| Parameter | Type |
|---|---|
|
Returns ​
Promise<ContainerStatsResponse>