简体   繁体   中英

Docker container cpu percentage

I was trying to extract cpu usage in percentage by individual containers by running command

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.

Is there any way to extract cpu usage from cgroup by calculating the parameters. In cgroup there are lot of parameters which are little bit confusing.Anybody can help would be appreciated.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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