Docker Community Forums

Share and learn in the Docker community.

Calculate CPU usage in percentage with latest API

docker

#1

Hello,

how can I calculate the CPU usage in percentage for a container.
This is an excerpt from the API for a specific conatiner (Url: /containers/{id}/stats):

    "cpu_stats": {
    "cpu_usage": {
    "percpu_usage": [
    8646879,
    24472255,
    36438778,
    30657443
    ],
    "usage_in_usermode": 50000000,
    "total_usage": 100215355,
    "usage_in_kernelmode": 30000000
    },
    "system_cpu_usage": 739306590000000,
    "online_cpus": 4,
    "throttling_data": {
    "periods": 0,
    "throttled_periods": 0,
    "throttled_time": 0
    }
    },
    "precpu_stats": {
    "cpu_usage": {
    "percpu_usage": [
    8646879,
    24350896,
    36438778,
    30657443
    ],
    "usage_in_usermode": 50000000,
    "total_usage": 100093996,
    "usage_in_kernelmode": 30000000
    },
    "system_cpu_usage": 9492140000000,
    "online_cpus": 4