[PATCH 2/2] manager: Implement virConnectGetAllDomainStats API

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

 



Instead of each object gathering its own statistics, domain's
statistics will be gathered by connection and passed to domain.
If virConnectGetAllDomainStats is not supported, fallback is
to use the old way of gathering statistics.

Signed-off-by: Simon Kobyda <skobyda@xxxxxxxxxx>
---
 virtManager/connection.py | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/virtManager/connection.py b/virtManager/connection.py
index 7cadd97f..c510f03e 100644
--- a/virtManager/connection.py
+++ b/virtManager/connection.py
@@ -1332,6 +1332,11 @@ class vmmConnection(vmmGObject):
             initial_poll, pollvm, pollnet, pollpool, polliface, pollnodedev)
         self.idle_add(self._gone_object_signals, gone_objects)
 
+        if stats_update:
+            self._load_vm_stats(
+                [o for o in preexisting_objects if o.reports_stats()],
+                pollvm, stats_update)
+
         # Only tick() pre-existing objects, since new objects will be
         # initialized asynchronously and tick() would be redundant
         for obj in preexisting_objects:
@@ -1349,7 +1354,8 @@ class vmmConnection(vmmGObject):
                 elif obj.__class__ is vmmNodeDevice and not pollnodedev:
                     continue
 
-                obj.tick(stats_update=stats_update)
+                if obj.__class__ is not vmmDomain:
+                    obj.tick(stats_update=stats_update)
             except Exception as e:
                 logging.exception("Tick for %s failed", obj)
                 if (isinstance(e, libvirt.libvirtError) and
@@ -1366,6 +1372,27 @@ class vmmConnection(vmmGObject):
                 [o for o in preexisting_objects if o.reports_stats()])
             self.idle_emit("resources-sampled")
 
+    def _load_vm_stats(self, vms, pollvm, stats_update):
+        try:
+            stats = self._backend.getAllDomainStats(
+                libvirt.VIR_DOMAIN_STATS_STATE |
+                libvirt.VIR_DOMAIN_STATS_CPU_TOTAL |
+                libvirt.VIR_DOMAIN_STATS_VCPU |
+                libvirt.VIR_DOMAIN_STATS_BALLOON |
+                libvirt.VIR_DOMAIN_STATS_BLOCK |
+                libvirt.VIR_DOMAIN_STATS_INTERFACE,
+                0)
+        except libvirt.libvirtError as err:
+            if util.is_error_nosupport(err):
+                logging.debug("Method getAllDomainStats() not supported: %s", err)
+            else:
+                logging.error("Error loading statistics: %s", err)
+
+        for obj in vms:
+            for domstat in stats:
+                if obj._backend.UUID() == domstat[0].UUID():
+                    obj.tick(stats_update, domstat[1])
+
     def _recalculate_stats(self, vms):
         if not self._backend.is_open():
             return
-- 
2.17.1

_______________________________________________
virt-tools-list mailing list
virt-tools-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/virt-tools-list



[Index of Archives]     [Linux Virtualization]     [KVM Development]     [CentOS Virtualization]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite Forum]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]     [Video 4 Linux]

  Powered by Linux