Martin Sivák has uploaded a new change for review.

Change subject: Add collector that computes the amount of swap used by Qemu 
alone
......................................................................

Add collector that computes the amount of swap used by Qemu alone

Change-Id: Icf83e864b20d8cb734d5c9217bd2e8db7c175487
Signed-off-by: Martin Sivak <[email protected]>
---
M mom/Collectors/Collector.py
A mom/Collectors/QemuProcessesDetails.py
M mom/HostMonitor.py
M mom/HypervisorInterfaces/libvirtInterface.py
M mom/HypervisorInterfaces/vdsmInterface.py
M mom/__init__.py
6 files changed, 69 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/mom refs/changes/70/21970/1

diff --git a/mom/Collectors/Collector.py b/mom/Collectors/Collector.py
index 46b3a5e..8e936bd 100644
--- a/mom/Collectors/Collector.py
+++ b/mom/Collectors/Collector.py
@@ -32,7 +32,7 @@
         """
         pass
 
-    def collect():
+    def collect(self):
         """
         The principle interface for every Collector.  This method is called by 
a
         monitor to initiate data collection.
diff --git a/mom/Collectors/QemuProcessesDetails.py 
b/mom/Collectors/QemuProcessesDetails.py
new file mode 100644
index 0000000..313e73b
--- /dev/null
+++ b/mom/Collectors/QemuProcessesDetails.py
@@ -0,0 +1,48 @@
+# Memory Overcommitment Manager
+# Copyright (C) 2013 Martin Sivak, Red Hat
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+from mom.Collectors.Collector import *
+import os
+
+class QemuProcessesDetails(Collector):
+    """
+    This collector returns summary memory statistics of qemu processes by 
examining
+    /proc/<pid>/smaps.  The fields provided are:
+        qemu_swap_usage - The total amount of memory in swap (kB)
+    """
+    def __init__(self, properties):
+        self.hypervisor_iface = properties['hypervisor_iface']
+
+    @staticmethod
+    def smaps_file(pid):
+        return os.path.join("/proc", str(pid), "smaps")
+
+    def collect(self):
+        pids = self.hypervisor_iface.getAllVmPids()
+
+        # compute the swap usage of all qemu processes
+        usage = 0
+        for pid in pids:
+            meminfo = open_datafile(self.smaps_file(pid))
+            contents = meminfo.read()
+            meminfo.close()
+            usage += parse_int("^Swap: (.*) kB", contents)
+
+        data = { 'qemu_swap_usage': usage }
+        return data
+
+    def getFields(self=None):
+        return set(['qemu_swap_usage'])
diff --git a/mom/HostMonitor.py b/mom/HostMonitor.py
index e5f54f1..a64d4f8 100644
--- a/mom/HostMonitor.py
+++ b/mom/HostMonitor.py
@@ -26,7 +26,7 @@
     """
     The Host Monitor thread collects and reports statistics about the host.
     """
-    def __init__(self, config):
+    def __init__(self, config, hypervisor_iface):
         threading.Thread.__init__(self, name="HostMonitor")
         Monitor.__init__(self, config, self.getName())
         self.setDaemon(True)
@@ -36,6 +36,7 @@
         # Append monitor interval to properties because HostKSM needs it
         # to calculate ksmd cpu usage.
         self.properties['interval'] = self.interval
+        self.properties['hypervisor_iface'] = hypervisor_iface
         collector_list = self.config.get('host', 'collectors')
         self.collectors = Collector.get_collectors(collector_list,
                             self.properties, self.config)
diff --git a/mom/HypervisorInterfaces/libvirtInterface.py 
b/mom/HypervisorInterfaces/libvirtInterface.py
index 916ca12..6d66038 100644
--- a/mom/HypervisorInterfaces/libvirtInterface.py
+++ b/mom/HypervisorInterfaces/libvirtInterface.py
@@ -178,6 +178,14 @@
             return []
         return dom_list
 
+    def getAllVmPids(self):
+        try:
+            dom_list = self.conn.listDomainsID()
+            return [self.getVmInfo(id)["pid"] for id in dom_list]
+        except libvirt.libvirtError, e:
+            self._handleException(e)
+            return []
+
     def getVmInfo(self, id):
         data = {}
         guest_domain = self._getDomainFromID(id)
diff --git a/mom/HypervisorInterfaces/vdsmInterface.py 
b/mom/HypervisorInterfaces/vdsmInterface.py
index ddf8981..1ee3eb2 100644
--- a/mom/HypervisorInterfaces/vdsmInterface.py
+++ b/mom/HypervisorInterfaces/vdsmInterface.py
@@ -69,6 +69,15 @@
             e.handle_exception()
             return None
 
+    def getAllVmPids(self):
+        try:
+            response = self.vdsm_api.getVMList()
+            self._check_status(response)
+            return [vm['pid'] for vm in response['vmList']]
+        except vdsmException, e:
+            e.handle_exception()
+            return None
+
     def getVmList(self):
         vmIds = []
         try:
diff --git a/mom/__init__.py b/mom/__init__.py
index 97c0c11..401004e 100644
--- a/mom/__init__.py
+++ b/mom/__init__.py
@@ -24,8 +24,8 @@
         # Start threads
         self.logger.info("MOM starting")
         self.config.set('__int__', 'running', '1')
-        host_monitor = HostMonitor(self.config)
         hypervisor_iface = self.get_hypervisor_interface()
+        host_monitor = HostMonitor(self.config, 
hypervisor_iface=hypervisor_iface)
         if not hypervisor_iface:
             self.shutdown()
         guest_manager = GuestManager(self.config, hypervisor_iface)


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

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

Reply via email to