如何在容器中获取CPU% [英] How to get CPU % inside a container
问题描述
我想在容器内获取docker stats。我们不能在container中使用docker stats命令。所以,我想使用cat / sys / fs / cgroup。如何获得CPU%。
I want to get docker stats inside a container. We cant use docker stats command inside container . So ,I want to use cat /sys/fs/cgroup. How to get CPU%.
推荐答案
有多种方法可以做到这一点。大多数在容器外部工作的CPU使用率测量方法也将在容器内部工作。
There are a variety of ways of doing this. Most methods of measuring CPU usage which work outside of a container will also work inside of a container.
例如,您可以使用mpstat。此命令将每十秒钟测量一次利用率:
For example, you can use mpstat. This command will measure utilization every ten seconds:
mpstat -u 10
它将每十秒打印一次报告,详细说明CPU空闲的频率,空闲时的操作以及时间戳。如果您希望获得更频繁的报告,可以更改 10参数。
It will print out a report every ten seconds, detailing how often the CPU was idle, what it was doing when it wasn't idle, and a timestamp. If you want a more frequent report, you can change the '10' parameter.
这篇关于如何在容器中获取CPU%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!