Get Docker Container CPU Usage as Percentage

前端 未结 3 1677
伪装坚强ぢ
伪装坚强ぢ 2020-12-14 17:10

Docker provides an interactive stats command, docker stats [cid] which gives up to date information on the CPU usage, like so:

CONTAINER      CPU         


        
3条回答
  •  别那么骄傲
    2020-12-14 17:43

    So I need this also, and the following gives me the correct CPU usage, factoring in number of cores.

    var cpuDelta = metric.cpu_stats.cpu_usage.total_usage -  metric.precpu_stats.cpu_usage.total_usage;
    var systemDelta = metric.cpu_stats.system_cpu_usage - metric.precpu_stats.system_cpu_usage;
    var RESULT_CPU_USAGE = cpuDelta / systemDelta * metric.cpu_stats.cpu_usage.percpu_usage.length * 100;
    
    console.log(RESULT_CPU_USAGE);
    

提交回复
热议问题