Restituto Marcus Arevalo
2014-Jul-06 17:00 UTC
[libvirt-users] getting CPU usage through virsh command or libvirt API
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. regards, Marco
Michal Privoznik
2014-Jul-07 12:09 UTC
Re: [libvirt-users] getting CPU usage through virsh command or libvirt API
On 06.07.2014 19:00, 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.As I replied in your previous e-mail, libvirt doesn't expose this kind of information. It's the best if client computes the value it needs from the information libvirt provides. Having said that, virt-top[1] may serve as good example, although it's written in OCaml, not C. Michal 1: http://people.redhat.com/~rjones/virt-top/
Eric Blake
2014-Jul-07 21:29 UTC
Re: [libvirt-users] getting CPU usage through virsh command or libvirt API
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