[Lxc-users] How to get the CPU usage of a container ?

Louis Opter louis.opter at dotcloud.com
Fri Jun 18 19:35:02 UTC 2010


Hello,

I'm working on a LXC plugin for collectd (A system statistics collection
daemon): http://collectd.org.

My goal is to get statistics on a container almost as if it was a real server.
I have started to focus on RAM and CPU usage.

I have carefully read the cgroups documentation in the kernel sources, as well
as your mailing lists and relevent posts on the LKML.

With the memory.stat getting memory usage was straightforward, I use:
 - cache: to get the amount of ram cached;
 - rss: to get the amount of ram used.

However, I can't figure out how to (correctly) get the cpu usage.

I was searching for something like the cpus lines of /proc/stats.

The right file to get this kind of informations seemed to be cpuacct.stat.

But to make values in this file change *a bit* I have to stress the cpu a lot in
my container. I expected that this value will continously increase because of
backgrounds jobs in my container (postfix, sshd, cron,...).

How is cpuacct.stat calculated ? Can I use it to report CPU usage, like it is
possible with /proc/stats ?

Maybe I'm using the wrong file ?

Best Regards

-- 
Louis Opter




More information about the lxc-users mailing list