简体   繁体   English

Docker容器CPU使用率

[英]Docker Container CPU Usage

I am using the docker remote API to retrieve stats of my running containers. 我正在使用docker远程API来检索正在运行的容器的统计信息。 For CPU usage I get for example this: 对于CPU使用情况,我得到例如:

"cpu_stats": {
    "cpu_usage": {
      "total_usage": 13039191340,
      "percpu_usage": [
        13039191340
      ],
      "usage_in_kernelmode": 420000000,
      "usage_in_usermode": 10480000000
    },
    "system_cpu_usage": 8.8930204e+14,
    "throttling_data": {
      "periods": 0,
      "throttled_periods": 0,
      "throttled_time": 0
    }
  }

How can I calculate the CPU usage in percent? 如何以百分比计算CPU使用率? When I divide "usage_in_kernelmode" with "total_usage" I get a similar result as the docker stats command, but is this the right way to do it? 当我将“usage_in_kernelmode”除以“total_usage”时,我得到了与docker docker stats命令类似的结果,但这是正确的方法吗?

Thank you :) 谢谢 :)

Ultimately, it comes down to what CPU usage you want to measure. 最终,它归结为您想要衡量的CPU使用率。

The usage states are in cycles. 使用状态是循环的。 User cycles are those spent in executing applications, including system applications (like daemons) executing in user space. 用户周期是用于执行应用程序的周期,包括在用户空间中执行的系统应用程序(如守护程序)。 Kernel cycles are those spent in executing fundamental OS or driver functions. 内核周期是执行基本 OS或驱动程序功能所花费的。 Non-fundamental OS functions execute in user space. 非基本OS功能在用户空间中执行。 The unaccounted for cycles are probably idle cycles, those spent doing nothing useful. 未计入的周期可能是空闲周期,那些花费无用的周期。

So total CPU percent usage is (kernel+user)/(idle+kernel+user)*100. 因此,总CPU使用百分比是(内核+用户)/(空闲+内核+用户)* 100。 User CPU usage is (user))/(idle+kernel+user)*100. 用户CPU使用率为(用户))/(空闲+内核+用户)* 100。 And you can guess the equation for system % usage. 您可以猜测系统%使用率的等式。

system_cpu_usage puzzles me. system_cpu_usage让我很困惑。 If it, instead of total_usage, refers to total cycles, then replace (idle+kernel+user) with that. 如果它(而不是total_usage)指的是总周期,则用它替换(idle + kernel + user)。 What puzzles me is if system_cpu_usage is total usage, then what the heck is total_usage? 让我感到困惑的是,如果system_cpu_usage是总使用量,那么究竟是什么?total_usage?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM