简体   繁体   English

Docker容器cpu百分比

[英]Docker container cpu percentage

I was trying to extract cpu usage in percentage by individual containers by running command 我试图通过运行命令按单个容器提取CPU使用率百分比

cpu_usage_percent=$(docker stats --format "table {{.Container}}\t{{.CPUPerc}}"  -a --no-stream | grep $container_id_cm | awk '{print $2}')

I want to execute this command in every 1 minute but seems to be this command takes time to give output and also cpu utilization of base system increases. 我想每1分钟执行一次此命令,但似乎此命令需要花费时间才能输出,而且基本系统的CPU利用率也会增加。

Is there any way to extract cpu usage from cgroup by calculating the parameters. 有什么方法可以通过计算参数从cgroup中提取cpu的使用情况。 In cgroup there are lot of parameters which are little bit confusing.Anybody can help would be appreciated. 在cgroup中有很多参数有点令人困惑,任何人都可以提供帮助。

Thanks in Advance 提前致谢

If you are only interested in a single container, you don't have to dump stats for all containers: 如果您只对单个容器感兴趣,则不必为所有容器转储统计信息:

docker stats --format "{{.CPUPerc}}" --no-stream $container_id_cm

Might make the query a bit more performant. 可能会使查询性能更高。

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

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