[libvirt-users] getting CPU usage through virsh command or libvirt API

Eric Blake eblake at redhat.com
Mon Jul 7 21:29:01 UTC 2014


On 07/06/2014 11:00 AM, Restituto Marcus Arevalo wrote:
> Hi,    
> 
> 
>     Is it possible to get the CPU usage of a guest through a virsh command? I have tried almost all the commands (vcpuinfo, cpu-stats, etc.) that gets the details of a guest cpu, but it only returns the cpu time. Is there any command that returns the cpu usage (just like the graph that virt-manager displays) of a guest? Or do I have to create a program using libvirt API? Thanks in advance.

virsh is just a thin wrapper around the libvirt API, but has some severe
overheads due to shell scripting being expensive on spawning so many
processes and having to reconnect on every new virsh invocation. Batch
mode helps some, but I don't know that you can set up batch mode to do
periodic polling.  If you care at all about efficiency, you'll want to
write your own program rather than using virsh.

If you want to see how virt-manager calculates CPU usage, use the
source: https://git.fedorahosted.org/git/virt-manager.git
Alas, I'm not familiar enough with python in general or with
virt-manager in particular to point you to a specific file within that
repository.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 604 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20140707/7e17c51b/attachment.sig>


More information about the libvirt-users mailing list