[PATCH 09/11] qemu: bulk stats: implement interface group

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

 



This patch implements the VIR_DOMAIN_STATS_INTERFACE
group of statistics.

Signed-off-by: Francesco Romani <fromani@xxxxxxxxxx>
---
 include/libvirt/libvirt.h.in |  1 +
 src/qemu/qemu_driver.c       | 53 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+)

diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 86ef18b..8c15583 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -2514,6 +2514,7 @@ typedef enum {
     VIR_DOMAIN_STATS_CPU_TOTAL = (1 << 1), /* return domain CPU info */
     VIR_DOMAIN_STATS_BALLOON = (1 << 2), /* return domain balloon info */
     VIR_DOMAIN_STATS_VCPU = (1 << 3), /* return domain virtual CPU info */
+    VIR_DOMAIN_STATS_INTERFACE = (1 << 4), /* return domain interfaces info */
 } virDomainStatsTypes;
 
 typedef enum {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 527a6b4..818fcbc 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -17500,6 +17500,58 @@ qemuDomainGetStatsVcpu(virConnectPtr conn ATTRIBUTE_UNUSED,
 }
 
 
+#define QEMU_ADD_NET_PARAM(RECORD, MAXPARAMS, IFNAME, NAME, VALUE) \
+do { \
+    char param_name[NAME_MAX]; \
+    snprintf(param_name, NAME_MAX, "net.%s.%s", IFNAME, NAME); \
+    if (virTypedParamsAddLLong(&RECORD->params, \
+                               &RECORD->nparams, \
+                               MAXPARAMS, \
+                               param_name, \
+                               VALUE) < 0) \
+        return -1; \
+} while (0)
+
+static int
+qemuDomainGetStatsInterface(virConnectPtr conn ATTRIBUTE_UNUSED,
+                            virDomainObjPtr dom,
+                            virDomainStatsRecordPtr record,
+                            int *maxparams,
+                            unsigned int privflags ATTRIBUTE_UNUSED)
+{
+    size_t i;
+    struct _virDomainInterfaceStats tmp;
+
+    /* Check the path is one of the domain's network interfaces. */
+    for (i = 0; i < dom->def->nnets; i++) {
+        memset(&tmp, 0, sizeof(tmp));
+
+        if (virNetInterfaceStats(dom->def->nets[i]->ifname, &tmp) < 0)
+            continue;
+
+        QEMU_ADD_NET_PARAM(record, maxparams, dom->def->nets[i]->ifname,
+                           "rx.bytes", tmp.rx_bytes);
+        QEMU_ADD_NET_PARAM(record, maxparams, dom->def->nets[i]->ifname,
+                           "rx.pkts", tmp.rx_packets);
+        QEMU_ADD_NET_PARAM(record, maxparams, dom->def->nets[i]->ifname,
+                           "rx.errs", tmp.rx_errs);
+        QEMU_ADD_NET_PARAM(record, maxparams, dom->def->nets[i]->ifname,
+                           "rx.drop", tmp.rx_drop);
+        QEMU_ADD_NET_PARAM(record, maxparams, dom->def->nets[i]->ifname,
+                           "tx.bytes", tmp.tx_bytes);
+        QEMU_ADD_NET_PARAM(record, maxparams, dom->def->nets[i]->ifname,
+                           "tx.pkts", tmp.tx_packets);
+        QEMU_ADD_NET_PARAM(record, maxparams, dom->def->nets[i]->ifname,
+                           "tx.errs", tmp.tx_errs);
+        QEMU_ADD_NET_PARAM(record, maxparams, dom->def->nets[i]->ifname,
+                           "tx.drop", tmp.tx_drop);
+    }
+
+    return 0;
+}
+
+#undef QEMU_ADD_NET_PARAM
+
 typedef int
 (*qemuDomainGetStatsFunc)(virConnectPtr conn,
                           virDomainObjPtr dom,
@@ -17517,6 +17569,7 @@ static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] = {
     { qemuDomainGetStatsCpu, VIR_DOMAIN_STATS_CPU_TOTAL },
     { qemuDomainGetStatsBalloon, VIR_DOMAIN_STATS_BALLOON },
     { qemuDomainGetStatsVcpu, VIR_DOMAIN_STATS_VCPU },
+    { qemuDomainGetStatsInterface, VIR_DOMAIN_STATS_INTERFACE },
     { NULL, 0 }
 };
 
-- 
1.9.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]