[virt-tools-list] Help request (obtaining %cpu for a guest domain)

Richard W.M. Jones rjones at redhat.com
Sun Mar 16 16:26:54 UTC 2014

On Sat, Mar 15, 2014 at 11:37:22PM +0100, Pasquale Dir wrote:
> I am a student and I am using python libvirt api, like the ones which were
> used in order to build virt-manager.
> I am wondering how to obtain the %cpu usage and I thought asking to you, as
> you did it for your program which is written in python.
> getCpuStats() function on a domain object gives me
> cpu_time,user_time,system_time...I don't know how to combine them in order
> to obtain the % usage.
> For the guest system I take the delta between two successive measurations
> and make a division, putting idle time just on the denominator...but here?
> Maybe the cpu_time is actually an idle time for the guest?

IIRC it's nanoseconds used by the vCPU (and note there may be multiple
vCPUs per guest).  In any case, have a look at the source for


Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-p2v converts physical machines to virtual machines.  Boot with a
live CD or over the network (PXE) and turn machines into KVM guests.

More information about the virt-tools-list mailing list