[systemd-devel] systemd-cgtop vs docker-stats

Tiago Alves tiagoalves83 at gmail.com
Fri Nov 27 09:10:37 PST 2015

> See:
> https://github.com/systemd/systemd/blob/master/src/cgtop/cgtop.c#L232
> It simply divides the CPU time spent by the real time spent, that's all.
Any suggestion of how to get those times using bash ?
I am using "/proc/stat" for system cpu and "/sys/fs/cgroup/cpu,
cpuacct/system.slice/docker-${CID}*.scope/cpuacct.usage" for docker
container cpu.

> > b) Is it possible to get CPU% using a bash script reading systemd-cgtop ?
> > I have tried something like: systemd-cgtop -b -n2 , but it is not
> > collecting CPU% info.
> Well, you can only calculate the CPU time spent within a certain
> amount of time, hence writing a script that runs once and does not
> stay around for that time to watch the CPU time counters cannot work.

Yes. I am doing that (sleep 2 in my bash script *get_container_cpu_percentage()
*function ). My doubt is: from where systemd-cgtop gets the CPU info ?

Thank you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20151127/2ac50f35/attachment.html>

More information about the systemd-devel mailing list