Francesco Romani has uploaded a new change for review.

Change subject: guests: use bulk stats when talking to VDSM
......................................................................

guests: use bulk stats when talking to VDSM

Use getAllVmStats instead of a swarm of getVmStats.
Should be faster and cheaper this way.

Change-Id: I34c990f20d0597258a62fedff3fbf15300901fe6
Signed-off-by: Francesco Romani <from...@redhat.com>
---
M mom/Collectors/Collector.py
M mom/Collectors/GuestBalloon.py
M mom/Collectors/GuestCpuTune.py
M mom/Collectors/GuestMemory.py
M mom/Collectors/GuestNetworkDaemon.py
M mom/Collectors/GuestQemuAgent.py
M mom/Collectors/GuestQemuProc.py
M mom/Collectors/HostCpu.py
M mom/Collectors/HostKSM.py
M mom/Collectors/HostMemory.py
M mom/Collectors/HostTime.py
M mom/GuestManager.py
M mom/HypervisorInterfaces/libvirtInterface.py
M mom/HypervisorInterfaces/vdsmInterface.py
M mom/HypervisorInterfaces/vdsmrpcInterface.py
M mom/Monitor.py
16 files changed, 82 insertions(+), 29 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/mom refs/changes/27/37827/1

diff --git a/mom/Collectors/Collector.py b/mom/Collectors/Collector.py
index 0908918..c2417ab 100644
--- a/mom/Collectors/Collector.py
+++ b/mom/Collectors/Collector.py
@@ -32,7 +32,7 @@
         """
         pass
 
-    def collect(self):
+    def collect(self, stats=None):
         """
         The principle interface for every Collector.  This method is called by 
a
         monitor to initiate data collection.
diff --git a/mom/Collectors/GuestBalloon.py b/mom/Collectors/GuestBalloon.py
index 27e8e03..c529368 100644
--- a/mom/Collectors/GuestBalloon.py
+++ b/mom/Collectors/GuestBalloon.py
@@ -37,8 +37,11 @@
             self.logger.debug(msg)
         self.balloon_info_available = False
 
-    def collect(self):
-        stat = self.hypervisor_iface.getVmBalloonInfo(self.uuid)
+    def collect(self, stats=None):
+        if stats is None:
+            stat = self.hypervisor_iface.getVmBalloonInfo(self.uuid)
+        else:
+            stat = stats.get(self.uuid)
         if stat == None:
             self.stats_error('getVmBalloonInfo() is not ready')
         else:
diff --git a/mom/Collectors/GuestCpuTune.py b/mom/Collectors/GuestCpuTune.py
index 86763db..6443415 100644
--- a/mom/Collectors/GuestCpuTune.py
+++ b/mom/Collectors/GuestCpuTune.py
@@ -40,8 +40,11 @@
             self.logger.debug(msg)
         self.cpu_tune_info_available = False
 
-    def collect(self):
-        stat = self.hypervisor_iface.getVmCpuTuneInfo(self.uuid)
+    def collect(self, stats=None):
+        if stats is None:
+            stat = self.hypervisor_iface.getVmCpuTuneInfo(self.uuid)
+        else:
+            stat = stats.get(self.uuid)
 
         if stat == None:
             self.stats_error('getVmCpuTuneInfo() is not ready')
diff --git a/mom/Collectors/GuestMemory.py b/mom/Collectors/GuestMemory.py
index 24f38f1..bb673e3 100644
--- a/mom/Collectors/GuestMemory.py
+++ b/mom/Collectors/GuestMemory.py
@@ -45,9 +45,12 @@
             self.logger.warn(msg)
         self.memstats_available = False
 
-    def collect(self):
+    def collect(self, stats=None):
         try:
-            stat = self.hypervisor_iface.getVmMemoryStats(self.uuid)
+            if stats is None:
+                stat = self.hypervisor_iface.getVmMemoryStats(self.uuid)
+            else:
+                stat = stats.get(self.uuid)
         except HypervisorInterfaceError, e:
             self.stats_error('getVmMemoryStats() error: %s' % e.message)
             # We don't raise a CollectionError here because a different
diff --git a/mom/Collectors/GuestNetworkDaemon.py 
b/mom/Collectors/GuestNetworkDaemon.py
index b48ffff..c455fc6 100755
--- a/mom/Collectors/GuestNetworkDaemon.py
+++ b/mom/Collectors/GuestNetworkDaemon.py
@@ -123,7 +123,7 @@
             raise CollectionError('Network connection to %s failed: %s' %
                                   (self.name, msg))
 
-    def collect(self):
+    def collect(self, stats=None):
         if self.state == 'dead':
             return {}
         if self.ip is None:
diff --git a/mom/Collectors/GuestQemuAgent.py b/mom/Collectors/GuestQemuAgent.py
index 1d1d6b5..d59d264 100644
--- a/mom/Collectors/GuestQemuAgent.py
+++ b/mom/Collectors/GuestQemuAgent.py
@@ -141,7 +141,7 @@
         self.agent_cmd('file_close', fh)
         return data
 
-    def collect(self):
+    def collect(self, stats=None):
         if not self.connect():
             raise CollectionError('Unable to connect to agent')
         meminfo = self.getfile("/proc/meminfo")
diff --git a/mom/Collectors/GuestQemuProc.py b/mom/Collectors/GuestQemuProc.py
index a73bae6..378efb4 100644
--- a/mom/Collectors/GuestQemuProc.py
+++ b/mom/Collectors/GuestQemuProc.py
@@ -40,7 +40,7 @@
         if self.pid_stat_file is not None:
             self.pid_stat_file.close()
 
-    def collect(self):
+    def collect(self, stats=None):
         if self.pid_stat_file is None:
             return {}
 
diff --git a/mom/Collectors/HostCpu.py b/mom/Collectors/HostCpu.py
index 3107f34..1ca3e67 100644
--- a/mom/Collectors/HostCpu.py
+++ b/mom/Collectors/HostCpu.py
@@ -26,7 +26,7 @@
         if self.cpuinfo is not None:
             self.cpuinfo.close()
 
-    def collect(self):
+    def collect(self, stats=None):
         self.cpuinfo.seek(0)
 
         contents = self.cpuinfo.read()
diff --git a/mom/Collectors/HostKSM.py b/mom/Collectors/HostKSM.py
index 68ab957..4dfd843 100644
--- a/mom/Collectors/HostKSM.py
+++ b/mom/Collectors/HostKSM.py
@@ -105,7 +105,7 @@
             mem_tot = mem_tot + int(mem)
         return mem_tot
 
-    def collect(self):
+    def collect(self, stats=None):
         data = {}
         for (datum, file) in self.files.items():
             file.seek(0)
diff --git a/mom/Collectors/HostMemory.py b/mom/Collectors/HostMemory.py
index f572028..d883669 100644
--- a/mom/Collectors/HostMemory.py
+++ b/mom/Collectors/HostMemory.py
@@ -41,7 +41,7 @@
         if self.vmstat is not None:
             self.vmstat.close()
 
-    def collect(self):
+    def collect(self, stats=None):
         self.meminfo.seek(0)
         self.vmstat.seek(0)
 
diff --git a/mom/Collectors/HostTime.py b/mom/Collectors/HostTime.py
index 628143e..f18ac89 100644
--- a/mom/Collectors/HostTime.py
+++ b/mom/Collectors/HostTime.py
@@ -25,7 +25,7 @@
     def __init__(self, properties):
         pass
 
-    def collect(self):
+    def collect(self, stats=None):
         now = datetime.datetime.now()
         data = { 'time_year': now.year, 'time_month': now.month, \
                  'time_day': now.day, 'time_hour': now.hour, 'time_minute': 
now.minute, \
diff --git a/mom/GuestManager.py b/mom/GuestManager.py
index bcc65ff..8af64b6 100644
--- a/mom/GuestManager.py
+++ b/mom/GuestManager.py
@@ -70,12 +70,8 @@
             self.logger.info("Guest Manager starting");
             interval = self.config.getint('main', 'guest-manager-interval')
             while self.config.getint('__int__', 'running') == 1:
-                domain_list = self.hypervisor_iface.getVmList()
-                if domain_list is not None:
-                    self._spawn_guest_monitors(domain_list)
-                    self._check_guest_monitors(domain_list)
 
-                self._collect_from_guest_monitors()
+                self._step()
 
                 time.sleep(interval)
             self._wait_for_guest_monitors()
@@ -107,6 +103,11 @@
 
     # to be filled
 
+    def _step(self):
+        """
+        Perform one collection step
+        """
+
     def _create_monitor(self, info):
         """
         must return GuestData
@@ -123,12 +124,6 @@
         """
         Wait for GuestMonitors to exit
         """
-
-    def _collect_from_guest_monitors(self):
-        """
-        Trigger data collection from all monitors
-        """
-        pass
 
     # utilities
 
@@ -187,6 +182,12 @@
                 elif uuid not in domain_list:
                     self._unregister_guest(uuid)
 
+    def _step(self):
+        domain_list = self.hypervisor_iface.getVmList()
+        if domain_list is not None:
+            self._spawn_guest_monitors(domain_list)
+            self._check_guest_monitors(domain_list)
+
 
 class SingleThreadGuestManager(_GuestManager):
     def __init__(self, config, hypervisor_iface):
@@ -206,11 +207,17 @@
                 if uuid not in domain_list:
                     self._unregister_guest(uuid)
 
-    def _collect_from_guest_monitors(self):
+    def _step(self):
+        stats = self.hypervisor_iface.getAllVmStats()
+        if stats is not None:
+            domain_list = stats.keys()
+            self._spawn_guest_monitors(domain_list)
+            self._check_guest_monitors(domain_list)
+
         with self.guests_sem:
             for uuid, guest in self.guests.items():
                 if guest.monitor.isAlive():
-                    guest.monitor.collect()
+                    guest.monitor.collect(stats)
 
 
 def make(config, hypervisor_iface):
diff --git a/mom/HypervisorInterfaces/libvirtInterface.py 
b/mom/HypervisorInterfaces/libvirtInterface.py
index 641dd24..62d9835 100644
--- a/mom/HypervisorInterfaces/libvirtInterface.py
+++ b/mom/HypervisorInterfaces/libvirtInterface.py
@@ -181,6 +181,21 @@
             return []
         return dom_list
 
+    def getAllVmStats(self):
+        try:
+            dom_stats = {}
+            for domId in self.conn.listDomainsID():
+                stat = {}
+                stat.update(self.getVmMemoryStats(domId))
+                stat.update(self.getVmBalloonInfo(domId))
+                stat.update(self.getVmCpuTuneInfo(domId))
+                dom_stats[domId] = stat
+        except libvirt.libvirtError, e:
+            self._handleException(e)
+            return {}
+        else:
+            return dom_stats
+
     def getVmInfo(self, id):
         data = {}
         guest_domain = self._getDomainFromID(id)
diff --git a/mom/HypervisorInterfaces/vdsmInterface.py 
b/mom/HypervisorInterfaces/vdsmInterface.py
index 1193785..a0f1a35 100644
--- a/mom/HypervisorInterfaces/vdsmInterface.py
+++ b/mom/HypervisorInterfaces/vdsmInterface.py
@@ -84,6 +84,19 @@
             e.handle_exception()
             return None
 
+    def getAllVmStats(self):
+        try:
+            response = self.vdsm_api.getAllVmStats()
+            self._check_status(response)
+            stats_list = response['statsList']
+            vmStats = dict((stat['vmId'], stat)
+                           for stat in stats_list)
+            self.logger.debug('VM Stats: %s', vmStats.keys())
+            return vmStats
+        except vdsmException, e:
+            e.handle_exception()
+            return None
+
     def getVmMemoryStats(self, uuid):
         ret = {}
         try:
diff --git a/mom/HypervisorInterfaces/vdsmrpcInterface.py 
b/mom/HypervisorInterfaces/vdsmrpcInterface.py
index 627d972..d82f455 100644
--- a/mom/HypervisorInterfaces/vdsmrpcInterface.py
+++ b/mom/HypervisorInterfaces/vdsmrpcInterface.py
@@ -162,6 +162,15 @@
             e.handle_exception()
             return None
 
+    def getAllVmStats(self):
+        try:
+            response = self._call('Host.getAllVmStats')
+            return dict((stat['vmId'], stat)
+                        for stat in response['result'])
+        except vdsmException, e:
+            e.handle_exception()
+            return None
+
     def getVmMemoryStats(self, uuid):
         ret = {}
         try:
diff --git a/mom/Monitor.py b/mom/Monitor.py
index dd09d79..060288f 100644
--- a/mom/Monitor.py
+++ b/mom/Monitor.py
@@ -54,7 +54,7 @@
     def valid_fields(self):
         return self.fields.union(self.optional_fields)
 
-    def collect(self):
+    def collect(self, stats=None):
         """
         Collect a set of statistics by invoking all defined collectors and
         merging the data into one dictionary and pushing it onto the deque of
@@ -92,7 +92,7 @@
         data = {}
         for c in self.collectors:
             try:
-                collected = c.collect()
+                collected = c.collect(stats)
                 if collected is None:
                     self.logger.debug("Collector %s did not "
                                       "return any data", str(c))


-- 
To view, visit http://gerrit.ovirt.org/37827
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I34c990f20d0597258a62fedff3fbf15300901fe6
Gerrit-PatchSet: 1
Gerrit-Project: mom
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <from...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to