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

Lennart Poettering lennart at poettering.net
Fri Nov 27 08:23:45 PST 2015

On Thu, 26.11.15 02:28, Tiago Alves (tiagoalves83 at gmail.com) wrote:

> Hi,
> I am implementing a zabbix monitoring service for docker (some
> implementations that I found are not working the way I need).
> I am using a bash script for collecting container CPU % direct from cgroup
> cpuacct. The bash script (at the end of this message) is very simple (I
> copied the idea from docker-stats -
> https://github.com/docker/docker/blob/master/api/client/stats.go#L81)
> However, it seems that docker-stats is not so accurate as systemd-cgtop so
> my question are:
> a) How systemd-cgtop calculate a system.slice (in my case, an docker
> container) CPU % ? Can someone point me the cgroups/systemd/linux files
> used?
> I am looking at
> https://github.com/systemd/systemd/blob/master/src/cgtop/cgtop.c#L126 but I
> am not a C expert.



It simply divides the CPU time spent by the real time spent, that's all.

> 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.


Lennart Poettering, Red Hat

More information about the systemd-devel mailing list