[libvirt-users] No way to obtain guest's cpu and mem usage?

Hi everybody, I'm using the PHP API to make a web interface interact with the virtual machines installed on some hypervisor. Everything is fine, but I would like to find a way to get the guest's cpu and mem usage, so that it should be possible to make some rrd graphs. I didn't find out anything and also it seems looking around that there is no way to obtain those data. What is strange for me is that programs like virt-top are showing exactly what I'm looking for. Can anyone help me to find out a way to retrieve those statistics? Another related question: do you think I can obtain the same data by using this: ps aux | egrep "[/]usr/libexec/qemu-kvm.*libvirt.*" | awk '{print $3"/"$4}' on the hypervisor? These are related to the kvm process, and the kvm process IS the virtual machine... Or not? Thanks to everybody, -- RaSca Mia Mamma Usa Linux: Niente è impossibile da capire, se lo spieghi bene! rasca@miamammausalinux.org http://www.miamammausalinux.org

On Thu, Apr 12, 2012 at 09:21:18AM +0200, RaSca wrote:
Hi everybody, I'm using the PHP API to make a web interface interact with the virtual machines installed on some hypervisor. Everything is fine, but I would like to find a way to get the guest's cpu and mem usage, so that it should be possible to make some rrd graphs. I didn't find out anything and also it seems looking around that there is no way to obtain those data.
What is strange for me is that programs like virt-top are showing exactly what I'm looking for. Can anyone help me to find out a way to retrieve those statistics?
virt-top mostly uses the virDomainGetInfo() API to get this data. Regards, Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Il giorno Gio 12 Apr 2012 10:30:04 CEST, Daniel P. Berrange ha scritto:
On Thu, Apr 12, 2012 at 09:21:18AM +0200, RaSca wrote: [...] virt-top mostly uses the virDomainGetInfo() API to get this data. Regards, Daniel
Thanks Daniel, since there's no such function in the php api, can you please help me to find out a solution? Is modifying the libvirt-php sources the only solution? Thanks again, -- RaSca Mia Mamma Usa Linux: Niente è impossibile da capire, se lo spieghi bene! rasca@miamammausalinux.org http://www.miamammausalinux.org

On Thu, Apr 12, 2012 at 10:33:41AM +0200, RaSca wrote:
Il giorno Gio 12 Apr 2012 10:30:04 CEST, Daniel P. Berrange ha scritto:
On Thu, Apr 12, 2012 at 09:21:18AM +0200, RaSca wrote: [...] virt-top mostly uses the virDomainGetInfo() API to get this data. Regards, Daniel
Thanks Daniel, since there's no such function in the php api, can you please help me to find out a solution? Is modifying the libvirt-php sources the only solution?
Yes, I'd suggest adding it to libvirt-php. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Il giorno Gio 12 Apr 2012 10:39:42 CEST, Daniel P. Berrange ha scritto: [...]
Yes, I'd suggest adding it to libvirt-php. Daniel
But wait Daniel, as far as I see, the only info I can obtain from virDomainGetInfo are: unsigned char state : the running state, one of virDomainState unsigned long maxMem : the maximum memory in KBytes allowed unsigned long memory : the memory in KBytes used by the domain unsigned short nrVirtCpu : the number of virtual CPUs for the domain unsigned long long cpuTime : the CPU time used in nanoseconds which are *exact* the same data I can reach from the php function libvirt_domain_get_info. But these are NOT live stats, these does not contain the actual cpu and memory usage. So, what you mean when you say that virt-top takes all from virDomainGetInfo? -- RaSca Mia Mamma Usa Linux: Niente è impossibile da capire, se lo spieghi bene! rasca@miamammausalinux.org http://www.miamammausalinux.org

On Thu, Apr 12, 2012 at 10:48:05AM +0200, RaSca wrote:
Il giorno Gio 12 Apr 2012 10:39:42 CEST, Daniel P. Berrange ha scritto: [...]
Yes, I'd suggest adding it to libvirt-php. Daniel
But wait Daniel, as far as I see, the only info I can obtain from virDomainGetInfo are:
unsigned char state : the running state, one of virDomainState unsigned long maxMem : the maximum memory in KBytes allowed unsigned long memory : the memory in KBytes used by the domain unsigned short nrVirtCpu : the number of virtual CPUs for the domain unsigned long long cpuTime : the CPU time used in nanoseconds
which are *exact* the same data I can reach from the php function libvirt_domain_get_info. But these are NOT live stats, these does not contain the actual cpu and memory usage.
Err, yes they are the live stats. 'memory' shows the current memory consumed by the VM, while 'cpuTime' shows the absolute CPU time consumed since boot. To get % CPU time, take two readings 'n' seconds apart and calculate the delta between them Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|

Il giorno Gio 12 Apr 2012 11:11:29 CEST, Daniel P. Berrange ha scritto: [...]
Err, yes they are the live stats. 'memory' shows the current memory consumed by the VM, while 'cpuTime' shows the absolute CPU time consumed since boot. To get % CPU time, take two readings 'n' seconds apart and calculate the delta between them Daniel
NOW it's clear! Thank you very much Daniel! -- RaSca Mia Mamma Usa Linux: Niente è impossibile da capire, se lo spieghi bene! rasca@miamammausalinux.org http://www.miamammausalinux.org

On 12.04.2012 09:21, RaSca wrote:
Hi everybody, I'm using the PHP API to make a web interface interact with the virtual machines installed on some hypervisor. Everything is fine, but I would like to find a way to get the guest's cpu and mem usage, so that it should be possible to make some rrd graphs. I didn't find out anything and also it seems looking around that there is no way to obtain those data.
What is strange for me is that programs like virt-top are showing exactly what I'm looking for. Can anyone help me to find out a way to retrieve those statistics?
Another related question: do you think I can obtain the same data by using this:
ps aux | egrep "[/]usr/libexec/qemu-kvm.*libvirt.*" | awk '{print $3"/"$4}'
This takes into account memory used by hypervisor itself. Either you need to extend libvirt-php; or you can do: $stats = exec("virsh dommemstat $dom"); However, I lean towards libvirt-php extension. Michal

Il giorno Gio 12 Apr 2012 11:08:09 CEST, Michal Privoznik ha scritto: [...]
This takes into account memory used by hypervisor itself. Either you need to extend libvirt-php; or you can do: $stats = exec("virsh dommemstat $dom"); However, I lean towards libvirt-php extension. Michal
Hi Michal and thank you, libvirt-php has already got a libvirt_domain_memory_stats function, but it returns always an array in with just the 6th element has a value, and it is always the same value as the total memory of the guest. What then about the cpu? Is the CPU time useful to do statistics? How can I interpret this value? Thanks again, -- RaSca Mia Mamma Usa Linux: Niente è impossibile da capire, se lo spieghi bene! rasca@miamammausalinux.org http://www.miamammausalinux.org
participants (3)
-
Daniel P. Berrange
-
Michal Privoznik
-
RaSca