Hi,
Xen domain ID's are not stable across guest reboots. This means that
interface statistics aren't properly grouped together. The following
patch strips the domain ID from the interface names so that statistics
for a singles guests interfaces are always grouped together.
Xen interface names default to the format "vifXX.Y" where XX is the
domain ID and Y is the interface ID. The patch works by stripping the
"vifXX." from the interface name iff it conforms to the described naming
convention.
The patch assumes the interface naming scheme so not sure how portable
it is. Perhaps a better fix would be to use interface MAC addresses. It
appears that libvirt has no suitable interface for determining the
interface ID...
Please advise
Thanks
diff --git a/src/libvirt.c b/src/libvirt.c
index bcbf0e6..c7f93f4 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -245,6 +245,21 @@ lv_config (const char *key, const char *value)
return -1;
}
+static const char *interface_path_normalize(virDomainPtr dom, const char *path)
+{
+ char tmp[16]; /* strlen(sprintf("vif%s.", MAX_INT)) + 1 */
+ int len;
+
+ len = snprintf(tmp, sizeof(tmp), "vif%u.", virDomainGetID(dom));
+ if ( len <= 0 )
+ return path;
+
+ if ( strncmp(path, tmp, len) )
+ return path;
+
+ return path + len;
+}
+
static int
lv_read (void)
{
@@ -343,6 +358,10 @@ lv_read (void)
/* Get interface stats for each domain. */
for (i = 0; i < nr_interface_devices; ++i) {
struct _virDomainInterfaceStats stats;
+ const char *npath;
+
+ npath = interface_path_normalize(interface_devices[i].dom,
+ interface_devices[i].path);
if (virDomainInterfaceStats (interface_devices[i].dom,
interface_devices[i].path,
@@ -352,22 +371,22 @@ lv_read (void)
if ((stats.rx_bytes != -1) && (stats.tx_bytes != -1))
submit_counter2 ("if_octets",
(counter_t) stats.rx_bytes, (counter_t) stats.tx_bytes,
- t, interface_devices[i].dom, interface_devices[i].path);
+ t, interface_devices[i].dom, npath);
if ((stats.rx_packets != -1) && (stats.tx_packets != -1))
submit_counter2 ("if_packets",
(counter_t) stats.rx_packets, (counter_t) stats.tx_packets,
- t, interface_devices[i].dom, interface_devices[i].path);
+ t, interface_devices[i].dom, npath);
if ((stats.rx_errs != -1) && (stats.tx_errs != -1))
submit_counter2 ("if_errors",
(counter_t) stats.rx_errs, (counter_t) stats.tx_errs,
- t, interface_devices[i].dom, interface_devices[i].path);
+ t, interface_devices[i].dom, npath);
if ((stats.rx_drop != -1) && (stats.tx_drop != -1))
submit_counter2 ("if_dropped",
(counter_t) stats.rx_drop, (counter_t) stats.tx_drop,
- t, interface_devices[i].dom, interface_devices[i].path);
+ t, interface_devices[i].dom, npath);
} /* for (nr_interface_devices) */
return 0;
_______________________________________________
collectd mailing list
[email protected]
http://mailman.verplant.org/listinfo/collectd