Francesco Romani has uploaded a new change for review.

Change subject: guest monitor: split monitor from thread
......................................................................

guest monitor: split monitor from thread

We have the GuestMonitor class which inherits from threading.Thread,
and takes care of the per-VM monitor book-keeping and of the monitoring
loop.

This patch splits the class in two, with an explicit monitoring thread.

This is needed for better scalability, because this way we can now
optionally demand the actual invocation of the monitoring code to
the hypervisor, which can integrate it with its monitoring loop(s).

Change-Id: I224104f8b353d92a420723d3415df94aaf68da0c
Signed-off-by: Francesco Romani <[email protected]>
---
M mom/GuestMonitor.py
1 file changed, 23 insertions(+), 16 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/mom refs/changes/91/31591/1

diff --git a/mom/GuestMonitor.py b/mom/GuestMonitor.py
index 605170a..e7a7ca2 100644
--- a/mom/GuestMonitor.py
+++ b/mom/GuestMonitor.py
@@ -23,19 +23,16 @@
 from mom.Collectors import Collector
 
 
-class GuestMonitor(Monitor, threading.Thread):
+class GuestMonitor(Monitor):
     """
     A GuestMonitor thread collects and reports statistics about 1 running guest
     """
     def __init__(self, config, info, hypervisor_iface):
-        threading.Thread.__init__(self, name="guest:%s" % id)
         self.config = config
         self.logger = logging.getLogger('mom.GuestMonitor')
         self.interval = self.config.getint('main', 'guest-monitor-interval')
 
-        self.setName("GuestMonitor-%s" % info['name'])
         Monitor.__init__(self, config, self.getName())
-        self.setDaemon(True)
         with self.data_sem:
             self.properties.update(info)
             self.properties['hypervisor_iface'] = hypervisor_iface
@@ -45,18 +42,6 @@
                             self.properties, self.config)
         if self.collectors is None:
             self.logger.error("Guest Monitor initialization failed")
-            return
-
-    def run(self):
-        try:
-            self.logger.info("%s starting", self.getName())
-            while self._should_run():
-                self.collect()
-                time.sleep(self.interval)
-        except Exception as e:
-            self.logger.error("%s crashed", self.getName(), exc_info=True)
-        else:
-            self.logger.info("%s ending", self.getName())
 
     def getGuestName(self):
         """
@@ -64,3 +49,25 @@
         interface.
         """
         return self.properties.get('name')
+
+
+class GuestMonitorThread(threading.Thread):
+    def __init__(self, info, monitor):
+        threading.Thread.__init__(self, name="guest:%s" % id)
+
+        self.setName("GuestMonitor-%s" % info['name'])
+        self.setDaemon(True)
+        self.logger = logging.getLogger('mom.GuestMonitor')
+
+        self._mon = monitor
+
+    def run(self):
+        try:
+            self.logger.info("%s starting", self.getName())
+            while self._should_run():
+                self._mon.collect()
+                time.sleep(self._mon.interval)
+        except Exception as e:
+            self.logger.error("%s crashed", self.getName(), exc_info=True)
+        else:
+            self.logger.info("%s ending", self.getName())


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I224104f8b353d92a420723d3415df94aaf68da0c
Gerrit-PatchSet: 1
Gerrit-Project: mom
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to