|
|
9119d9 |
From c491890f920ac0549ec62cc354aea84165714c23 Mon Sep 17 00:00:00 2001
|
|
|
9119d9 |
Message-Id: <c491890f920ac0549ec62cc354aea84165714c23@dist-git>
|
|
|
9119d9 |
From: Francesco Romani <fromani@redhat.com>
|
|
|
9119d9 |
Date: Wed, 1 Oct 2014 11:20:15 +0200
|
|
|
9119d9 |
Subject: [PATCH] qemu: bulk stats: implement interface group
|
|
|
9119d9 |
|
|
|
9119d9 |
https://bugzilla.redhat.com/show_bug.cgi?id=1113116
|
|
|
9119d9 |
|
|
|
9119d9 |
This patch implements the VIR_DOMAIN_STATS_INTERFACE group of
|
|
|
9119d9 |
statistics.
|
|
|
9119d9 |
|
|
|
9119d9 |
Signed-off-by: Francesco Romani <fromani@redhat.com>
|
|
|
9119d9 |
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
|
|
|
9119d9 |
(cherry picked from commit c8e523722ecfced8e937f106b0a07be6c32febdb)
|
|
|
9119d9 |
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
|
|
|
9119d9 |
---
|
|
|
9119d9 |
include/libvirt/libvirt.h.in | 1 +
|
|
|
9119d9 |
src/libvirt.c | 14 +++++++
|
|
|
9119d9 |
src/qemu/qemu_driver.c | 95 ++++++++++++++++++++++++++++++++++++++++++++
|
|
|
9119d9 |
3 files changed, 110 insertions(+)
|
|
|
9119d9 |
|
|
|
9119d9 |
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
|
|
|
9119d9 |
index 8754e1b..72aa47d 100644
|
|
|
9119d9 |
--- a/include/libvirt/libvirt.h.in
|
|
|
9119d9 |
+++ b/include/libvirt/libvirt.h.in
|
|
|
9119d9 |
@@ -2517,6 +2517,7 @@ typedef enum {
|
|
|
9119d9 |
VIR_DOMAIN_STATS_CPU_TOTAL = (1 << 1), /* return domain CPU info */
|
|
|
9119d9 |
VIR_DOMAIN_STATS_BALLOON = (1 << 2), /* return domain balloon info */
|
|
|
9119d9 |
VIR_DOMAIN_STATS_VCPU = (1 << 3), /* return domain virtual CPU info */
|
|
|
9119d9 |
+ VIR_DOMAIN_STATS_INTERFACE = (1 << 4), /* return domain interfaces info */
|
|
|
9119d9 |
} virDomainStatsTypes;
|
|
|
9119d9 |
|
|
|
9119d9 |
typedef enum {
|
|
|
9119d9 |
diff --git a/src/libvirt.c b/src/libvirt.c
|
|
|
9119d9 |
index f2f6f43..46d3e22 100644
|
|
|
9119d9 |
--- a/src/libvirt.c
|
|
|
9119d9 |
+++ b/src/libvirt.c
|
|
|
9119d9 |
@@ -21581,6 +21581,20 @@ virConnectGetDomainCapabilities(virConnectPtr conn,
|
|
|
9119d9 |
* "vcpu.<num>.time" - virtual cpu time spent by virtual CPU <num>
|
|
|
9119d9 |
* as unsigned long long.
|
|
|
9119d9 |
*
|
|
|
9119d9 |
+ * VIR_DOMAIN_STATS_INTERFACE: Return network interface statistics.
|
|
|
9119d9 |
+ * The typed parameter keys are in this format:
|
|
|
9119d9 |
+ * "net.count" - number of network interfaces on this domain
|
|
|
9119d9 |
+ * as unsigned int.
|
|
|
9119d9 |
+ * "net.<num>.name" - name of the interface <num> as string.
|
|
|
9119d9 |
+ * "net.<num>.rx.bytes" - bytes received as unsigned long long.
|
|
|
9119d9 |
+ * "net.<num>.rx.pkts" - packets received as unsigned long long.
|
|
|
9119d9 |
+ * "net.<num>.rx.errs" - receive errors as unsigned long long.
|
|
|
9119d9 |
+ * "net.<num>.rx.drop" - receive packets dropped as unsigned long long.
|
|
|
9119d9 |
+ * "net.<num>.tx.bytes" - bytes transmitted as unsigned long long.
|
|
|
9119d9 |
+ * "net.<num>.tx.pkts" - packets transmitted as unsigned long long.
|
|
|
9119d9 |
+ * "net.<num>.tx.errs" - transmission errors as unsigned long long.
|
|
|
9119d9 |
+ * "net.<num>.tx.drop" - transmit packets dropped as unsigned long long.
|
|
|
9119d9 |
+ *
|
|
|
9119d9 |
* Using 0 for @stats returns all stats groups supported by the given
|
|
|
9119d9 |
* hypervisor.
|
|
|
9119d9 |
*
|
|
|
9119d9 |
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
|
|
|
9119d9 |
index ef2e401..3a46c6d 100644
|
|
|
9119d9 |
--- a/src/qemu/qemu_driver.c
|
|
|
9119d9 |
+++ b/src/qemu/qemu_driver.c
|
|
|
9119d9 |
@@ -17599,6 +17599,100 @@ qemuDomainGetStatsVcpu(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
|
|
|
9119d9 |
return ret;
|
|
|
9119d9 |
}
|
|
|
9119d9 |
|
|
|
9119d9 |
+#define QEMU_ADD_COUNT_PARAM(record, maxparams, type, count) \
|
|
|
9119d9 |
+do { \
|
|
|
9119d9 |
+ char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \
|
|
|
9119d9 |
+ snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, "%s.count", type); \
|
|
|
9119d9 |
+ if (virTypedParamsAddUInt(&(record)->params, \
|
|
|
9119d9 |
+ &(record)->nparams, \
|
|
|
9119d9 |
+ maxparams, \
|
|
|
9119d9 |
+ param_name, \
|
|
|
9119d9 |
+ count) < 0) \
|
|
|
9119d9 |
+ return -1; \
|
|
|
9119d9 |
+} while (0)
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+#define QEMU_ADD_NAME_PARAM(record, maxparams, type, num, name) \
|
|
|
9119d9 |
+do { \
|
|
|
9119d9 |
+ char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \
|
|
|
9119d9 |
+ snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, \
|
|
|
9119d9 |
+ "%s.%zu.name", type, num); \
|
|
|
9119d9 |
+ if (virTypedParamsAddString(&(record)->params, \
|
|
|
9119d9 |
+ &(record)->nparams, \
|
|
|
9119d9 |
+ maxparams, \
|
|
|
9119d9 |
+ param_name, \
|
|
|
9119d9 |
+ name) < 0) \
|
|
|
9119d9 |
+ return -1; \
|
|
|
9119d9 |
+} while (0)
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+#define QEMU_ADD_NET_PARAM(record, maxparams, num, name, value) \
|
|
|
9119d9 |
+do { \
|
|
|
9119d9 |
+ char param_name[VIR_TYPED_PARAM_FIELD_LENGTH]; \
|
|
|
9119d9 |
+ snprintf(param_name, VIR_TYPED_PARAM_FIELD_LENGTH, \
|
|
|
9119d9 |
+ "net.%zu.%s", num, name); \
|
|
|
9119d9 |
+ if (value >= 0 && virTypedParamsAddULLong(&(record)->params, \
|
|
|
9119d9 |
+ &(record)->nparams, \
|
|
|
9119d9 |
+ maxparams, \
|
|
|
9119d9 |
+ param_name, \
|
|
|
9119d9 |
+ value) < 0) \
|
|
|
9119d9 |
+ return -1; \
|
|
|
9119d9 |
+} while (0)
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+static int
|
|
|
9119d9 |
+qemuDomainGetStatsInterface(virQEMUDriverPtr driver ATTRIBUTE_UNUSED,
|
|
|
9119d9 |
+ virDomainObjPtr dom,
|
|
|
9119d9 |
+ virDomainStatsRecordPtr record,
|
|
|
9119d9 |
+ int *maxparams,
|
|
|
9119d9 |
+ unsigned int privflags ATTRIBUTE_UNUSED)
|
|
|
9119d9 |
+{
|
|
|
9119d9 |
+ size_t i;
|
|
|
9119d9 |
+ struct _virDomainInterfaceStats tmp;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ if (!virDomainObjIsActive(dom))
|
|
|
9119d9 |
+ return 0;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ QEMU_ADD_COUNT_PARAM(record, maxparams, "net", dom->def->nnets);
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ /* Check the path is one of the domain's network interfaces. */
|
|
|
9119d9 |
+ for (i = 0; i < dom->def->nnets; i++) {
|
|
|
9119d9 |
+ if (!dom->def->nets[i]->ifname)
|
|
|
9119d9 |
+ continue;
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ memset(&tmp, 0, sizeof(tmp));
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ QEMU_ADD_NAME_PARAM(record, maxparams,
|
|
|
9119d9 |
+ "net", i, dom->def->nets[i]->ifname);
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ if (virNetInterfaceStats(dom->def->nets[i]->ifname, &tmp) < 0) {
|
|
|
9119d9 |
+ virResetLastError();
|
|
|
9119d9 |
+ continue;
|
|
|
9119d9 |
+ }
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ QEMU_ADD_NET_PARAM(record, maxparams, i,
|
|
|
9119d9 |
+ "rx.bytes", tmp.rx_bytes);
|
|
|
9119d9 |
+ QEMU_ADD_NET_PARAM(record, maxparams, i,
|
|
|
9119d9 |
+ "rx.pkts", tmp.rx_packets);
|
|
|
9119d9 |
+ QEMU_ADD_NET_PARAM(record, maxparams, i,
|
|
|
9119d9 |
+ "rx.errs", tmp.rx_errs);
|
|
|
9119d9 |
+ QEMU_ADD_NET_PARAM(record, maxparams, i,
|
|
|
9119d9 |
+ "rx.drop", tmp.rx_drop);
|
|
|
9119d9 |
+ QEMU_ADD_NET_PARAM(record, maxparams, i,
|
|
|
9119d9 |
+ "tx.bytes", tmp.tx_bytes);
|
|
|
9119d9 |
+ QEMU_ADD_NET_PARAM(record, maxparams, i,
|
|
|
9119d9 |
+ "tx.pkts", tmp.tx_packets);
|
|
|
9119d9 |
+ QEMU_ADD_NET_PARAM(record, maxparams, i,
|
|
|
9119d9 |
+ "tx.errs", tmp.tx_errs);
|
|
|
9119d9 |
+ QEMU_ADD_NET_PARAM(record, maxparams, i,
|
|
|
9119d9 |
+ "tx.drop", tmp.tx_drop);
|
|
|
9119d9 |
+ }
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+ return 0;
|
|
|
9119d9 |
+}
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+#undef QEMU_ADD_NET_PARAM
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+#undef QEMU_ADD_NAME_PARAM
|
|
|
9119d9 |
+
|
|
|
9119d9 |
+#undef QEMU_ADD_COUNT_PARAM
|
|
|
9119d9 |
|
|
|
9119d9 |
typedef int
|
|
|
9119d9 |
(*qemuDomainGetStatsFunc)(virQEMUDriverPtr driver,
|
|
|
9119d9 |
@@ -17618,6 +17712,7 @@ static struct qemuDomainGetStatsWorker qemuDomainGetStatsWorkers[] = {
|
|
|
9119d9 |
{ qemuDomainGetStatsCpu, VIR_DOMAIN_STATS_CPU_TOTAL, false },
|
|
|
9119d9 |
{ qemuDomainGetStatsBalloon, VIR_DOMAIN_STATS_BALLOON, true },
|
|
|
9119d9 |
{ qemuDomainGetStatsVcpu, VIR_DOMAIN_STATS_VCPU, false },
|
|
|
9119d9 |
+ { qemuDomainGetStatsInterface, VIR_DOMAIN_STATS_INTERFACE, false },
|
|
|
9119d9 |
{ NULL, 0, false }
|
|
|
9119d9 |
};
|
|
|
9119d9 |
|
|
|
9119d9 |
--
|
|
|
9119d9 |
2.1.2
|
|
|
9119d9 |
|