[libvirt-users] data monitored by "virDomainBlockStats" API not consistent with ones reading from /proc/[pid]/io, and corrugated with /proc/diskstats

coperd
Tue, 24 Jun 2014 08:24:31 -0000

Hi, all.
While monitoring KVM VMs’ disk utilisation using libvirt API
“virDomainBlockStats", I find that the results acquired is not consistent
with the value read from /proc/[vm_pid]/io(i only care about “rd_bytes" and
“wr_bytes” fields). Since libvirt doesn’t support host level monitoring,
i have to calculate the host’s disk utilisation by reading from the
/proc/diskstats file. What’s worse, the individual VM’s disk data may
be greater that the physical disk’s total value during some sampling time.

It is supposed that the VM’s disk “rd_bytes" and “wr_bytes" should
never exceed the value of the physical disk respectively, right ? Doesn’t
libvirt virDomainBlockStats read disk information from “proc” ?

I want to calculate VM’s bandwidth, here is my way:
	Firstly, we can get total disk utilisation using tools like iostat("iostat
-x”, the %util field represent the disk’s utilisation percentage)
	Then, given a sampling time period, 10s for example, i collected total bytes
read/written by each VM by virDomainBlockStats and total
		bytes of the physical disk by /proc/diskstats, then delta(VM’s rd+wr
bytes)/delta(physical disk’s rd+wr bytes) * %util is the VM’s
		disk utilization percentage during this time period.
Since the appearance of the above situation, i can’t get correct result. I have
search a lot for this question, but no answers.  Any help would
be appreciated.