[Libvir] Proposal: Block device and network stats

Richard W.M. Jones rjones at redhat.com
Fri Aug 10 11:49:50 UTC 2007


With the very timely question that has been raised about block and 
network device stats, I'm posting my proposed interface.  I almost have 
this working for the Xen case on my test machine.

The idea of this interface is to be optimised for the following case:

  * stats need to be fetched frequently (eg. once per second)
  * the layout of devices doesn't change often (ie. adding or removing 
devices from domains is very infrequent)
  * most domains have only a single block and single network device

With the above assumptions, the idea is that you would use the API like 
this:

(1) When the program starts up or (infrequently) is notified of a change 
or when a new domain appears, the program calls virDomainGetXMLDesc and 
parses out the //domain/devices/interface and //domain/devices/disk 
fields to get the list of network interfaces and block devices.

   So for each domain, you'll have two lists like this:

     dom[1]["blockdevs"] = ["xvda"]
     dom[1]["interfaces"] = ["virbr0"]

(2) Frequently (eg. once per second) the program calls (in the above case):

   virDomainBlockStats (dom1, "xvda", &bstats, sizeof bstats);
   virDomainInterfaceStats (dom1, "virbr0", &istats, sizeof istats);

(3) Since stats are cumulative the program must do its own subtraction 
and calculation in order to display throughput per second.

The implementation goes directly from the name "xvda" to the backend 
device (/sys/devices/xen-backend/- 
[type]-[domid]-[major:minor]/statistics) for block devices, and slightly 
more complicatedly to a particular line in /proc/net/dev for network 
interfaces.  (Note in the Xen case, the name "virbr0" is little more 
than a placeholder to mean "the zeroth interface for domain d").  In 
particular the current implementation doesn't cache anything.

This should all work fine in the Linux / Xen case.  libxenstat gives us 
sample code that we can copy for the Solaris / Xen case, but it would 
need testing from someone with access to such a machine.  I don't think 
qemu supports stats at all.  Initially we won't support stats for tap 
devices because there needs to be an upstream patch to support this 
(http://lists.xensource.com/archives/html/xen-changelog/2007-02/msg00278.html).

The extra size parameter will allow us to extend the stats structures in 
future, maintaining binary backwards compatibility with existing clients.

Rich.

-- 
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom.  Registered in
England and Wales under Company Registration No. 03798903
-------------- next part --------------
A non-text attachment was scrubbed...
Name: libvirt-stats-interface.patch
Type: text/x-patch
Size: 2316 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20070810/6462c3f7/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3237 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20070810/6462c3f7/attachment-0003.bin>


More information about the libvir-list mailing list