Docker容器CPU使用率 [英] Docker Container CPU Usage

查看:921
本文介绍了Docker容器CPU使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用docker远程API检索我正在运行的容器的统计信息。对于CPU使用率,例如:

I am using the docker remote API to retrieve stats of my running containers. For CPU usage I get for example this:

"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
    }
  }

如何计算百分?当我将 usage_in_kernelmode除以 total_usage时,得到的结果与 docker stats 命令相似,但这是正确的方法吗?

How can I calculate the CPU usage in percent? 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?

谢谢:)

推荐答案

最终,它取决于您要使用的CPU使用率

Ultimately, it comes down to what CPU usage you want to measure.

使用状态以周期为单位。用户周期是那些花费在执行应用程序上的周期,包括在用户空间中执行的系统应用程序(如守护程序)。内核周期是用于执行基本操作系统或驱动程序功能的周期。非基本OS功能在用户空间中执行。无法解释的周期可能是空闲周期,那些花费了很多时间而没有做的事情。

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. Non-fundamental OS functions execute in user space. The unaccounted for cycles are probably idle cycles, those spent doing nothing useful.

因此,CPU的总使用率为(内核+用户)/(空闲+内核+用户)* 100用户CPU使用率是(user))/(idle + kernel + user)* 100。您可以猜测出系统%使用率的等式。

So total CPU percent usage is (kernel+user)/(idle+kernel+user)*100. User CPU usage is (user))/(idle+kernel+user)*100. And you can guess the equation for system % usage.

system_cpu_usage使我感到困惑。如果是,而不是total_usage,则引用总周期,然后将其替换为(idle + kernel + user)。令我困惑的是,如果system_cpu_usage是总使用量,那么到底是什么total_usage?

system_cpu_usage puzzles me. If it, instead of total_usage, refers to total cycles, then replace (idle+kernel+user) with that. What puzzles me is if system_cpu_usage is total usage, then what the heck is total_usage?

这篇关于Docker容器CPU使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆