[libvirt-users] getting CPU usage of VMs through libvirt

Eric Blake eblake at redhat.com
Thu Jul 3 20:06:32 UTC 2014


On 07/03/2014 01:12 AM, Restituto Marcus Arevalo wrote:
> Greetings everyone,
> 

[can you convince your mailer to wrap long lines?]

> 
>        I just want to ask if it is possible to get the CPU usage of
the VMs in KVM through libvirt? I mean, how does the virt-manager
produce the graph it displays? Is there a way get this graph? But
instead of the graph itself, I just need to get it in percentage(%)
form. I'd like to know how. Thank you and your help will be greatly
appreciated.
> 

The beauty of open source: pop open an editor on the virt-manager source
code and learn for yourself how it is computing the graph.

The trick is to call the query function at a regular interval
(virDomainGetCPUStats in C code, or the appropriate language bindings in
whatever you are doing), then manually subtract the difference in values
between successive calls to compute a percentage yourself.

-- 
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/20140703/b7e38315/attachment.sig>


More information about the libvirt-users mailing list