[Libvir] Question on acquiring cpuTime in struct _virDomainInfo

Jan Michael jan.michael at cern.ch
Thu May 10 15:41:33 UTC 2007

Hi everyone,

using libvirt I'm trying to calculate cpu utilization of a node in  
percent. But sometimes values beyond 100.0% are being calculated.  
This is because a domain spend more time on a cpu than time is  
elapsed in the meantime.

A short explanation of the way how cpu utilization is computed in my  

	1. - open two connections with
		conn_cur/conn_old = virConnectOpenReadOnly(NULL);
	2. - get current time
		gettimeofday(&time_old, NULL);
	   - get domain by id with
		dom_old = virDomainLookupByID(conn_old, id)
	   - get domain information
		virDomainGetInfo(dom_old, &info_old);
	3. - sleep a second
	4. - doing same stuff like in 2. but with _cur

	5. - compute cpu utilization by dividing used cputime by elapsed time
		and multiply with 100

Am I right if I suppose that cpuTime for _virDomainInfo structure  
will be directly acquired from the hypervisor in virDomainGetInfo 
(dom_old, &info_old) or is it already present with getting the domain  
itself? Is there any better solution of doing this, which is more  

And another general question:
The monitoring utility of xen, called xentop, provides also  
statistics about networking and vbds. Are there any plans to provide  
this values by libvirt in the future?



More information about the libvir-list mailing list