[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libvir] Proposal: Block device and network stats



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
 
+/* Block device stats for virDomainBlockStats.
+ */
+struct _virDomainBlockStats {
+  uint64_t rd_req;
+  uint64_t wr_req;
+  uint64_t errs;   // In Xen this returns the mysterious 'oo_req'.
+};
+typedef struct _virDomainBlockStats *virDomainBlockStatsPtr;
+
+/* Network interface stats for virDomainInterfaceStats.
+ */
+struct _virDomainInterfaceStats {
+  uint64_t rx_bytes;
+  uint64_t rx_packets;
+  uint64_t rx_errs;
+  uint64_t rx_drop;
+  uint64_t tx_bytes;
+  uint64_t tx_packets;
+  uint64_t tx_errs;
+  uint64_t tx_drop;
+};
+typedef struct _virDomainInterfaceStats *virDomainInterfaceStatsPtr;
+
[...]

 
+/**
+ * virDomainBlockStats
+ * @dom: pointer to the domain object
+ * @path: path to the block device
+ * @stats: block device stats (returned)
+ * @size: size of stats structure
+ *
+ * This function returns block device (disk) stats for block
+ * devices attached to the domain.
+ *
+ * The path parameter is the name of the block device.  Get this
+ * by calling virDomainGetXMLDesc and finding the <target dev='...'>
+ * attribute within //domain/devices/disk.  (For example, "xvda").
+ *
+ * Domains may have more than one block device.  To get stats for
+ * each you should make multiple calls to this function.
+ *
+ * Returns: 0 in case of success or -1 in case of failure.
+ */
+int
+virDomainBlockStats (virDomainPtr dom, const char *path,
+                     virDomainBlockStatsPtr stats, size_t size)
+{
[...]
+}



+/**
+ * virDomainInterfaceStats
+ * @dom: pointer to the domain object
+ * @path: path to the interface
+ * @stats: network interface stats (returned)
+ * @size: size of stats structure
+ *
+ * This function returns network interface stats for interfaces
+ * attached to the domain.
+ *
+ * The path parameter is the name of the network interface.  Get
+ * this by calling virDomainGetXMLDesc and finding the
+ * <source ...> attribute within //domain/devices/interface.
+ * (For example, "xenbr0" or "virbr0").
+ *
+ * Domains may have more than network interface.  To get stats for
+ * each you should make multiple calls to this function.
+ *
+ * Returns: 0 in case of success or -1 in case of failure.
+ */
+int
+virDomainInterfaceStats (virDomainPtr dom, const char *path,
+                         virDomainInterfaceStatsPtr stats, size_t size)
+{
[...]
+}

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]