[Kimchi-devel] [PATCH] Issue #751: Fix guest memory utilization calculation.

pvital at linux.vnet.ibm.com pvital at linux.vnet.ibm.com
Thu Nov 5 13:20:50 UTC 2015


From: Paulo Vital <pvital at linux.vnet.ibm.com>

The return of Pyhton's function memoryStats() returns the guest's memory
utilization statistcs by the Libvirt API virDomainMemoryStats. However,
the content of the return (a dictionary) depends on the combination of
host and guest OS.

This patch fix the issue of not returning the curent utilization of
guest memory when host and guest are running different OS and not all
statistics are returned.

Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
---
 src/wok/plugins/kimchi/model/vms.py | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/wok/plugins/kimchi/model/vms.py b/src/wok/plugins/kimchi/model/vms.py
index 63681c7..0641ae8 100644
--- a/src/wok/plugins/kimchi/model/vms.py
+++ b/src/wok/plugins/kimchi/model/vms.py
@@ -919,13 +919,15 @@ class VMModel(object):
     def _get_percentage_mem_usage(self, vm_uuid, dom, seconds):
         # Get the guest's memory stats
         memStats = dom.memoryStats()
-        if memStats:
+        if ('available' in memStats) and ('unused' in memStats):
             memUsed = memStats.get('available') - memStats.get('unused')
+            percentage = ((memUsed * 100.0) / memStats.get('available'))
+        elif ('rss' in memStats) and ('actual' in memStats):
+            percentage = memStats.get('rss') * 100.0 / memStats.get('actual')
         else:
-            wok_log.debug('Failed to measure memory usage of the guest.')
+            wok_log.error('Failed to measure memory usage of the guest.')
 
-        percentage = max(0.0, min(100.0, ((memUsed * 100.0) /
-                                          memStats.get('available'))))
+        percentage = max(0.0, min(100.0, percentage))
 
         self.stats[vm_uuid].update({'mem_usage': percentage})
 
-- 
2.4.3




More information about the Kimchi-devel mailing list