[virt-tools-list] [PATCHv2 2/2] Base mem statistics on virDomainMemoryStats if available.
Thorsten Behrens
tbehrens at suse.com
Wed Dec 18 13:42:43 UTC 2013
Attempt to query domain memory stats via virDomainMemoryStats.
Fallback to old, possibly static virDomainGetInfo when that fails.
---
virtManager/domain.py | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/virtManager/domain.py b/virtManager/domain.py
index c94ac57..11488f9 100644
--- a/virtManager/domain.py
+++ b/virtManager/domain.py
@@ -245,6 +245,8 @@ class vmmDomain(vmmLibvirtObject):
self.remote_console_supported = False
self.title_supported = False
+ self._mem_stats_supported = True
+
self._enable_net_poll = False
self._stats_net_supported = True
self._stats_net_skip = []
@@ -1360,11 +1362,30 @@ class vmmDomain(vmmLibvirtObject):
###################
def _sample_mem_stats(self, info):
+ # fallback - if the below fails, have at least the old
+ # virDomainGetInfo data at hand
curmem = info[2]
- if not self.is_active():
+ totalmem = self.maximum_memory()
+ if (not self._mem_stats_supported or
+ not self.is_active()):
curmem = 0
+ else:
+ # retrieve dynamic mem stats, if supported
+ try:
+ stats = self._backend.memoryStats()
+ # did we get both required stat items back?
+ if set(['actual', 'rss']).issubset(
+ set(stats.keys())):
+ curmem = stats['rss']
+ totalmem = stats['actual']
+ except libvirt.libvirtError, err:
+ if util.is_error_nosupport(err):
+ logging.debug("Mem stats not supported: %s", err)
+ self._mem_stats_supported = False
+ else:
+ logging.error("Error reading mem stats: %s", err)
- pcentCurrMem = curmem * 100.0 / self.maximum_memory()
+ pcentCurrMem = curmem * 100.0 / totalmem
pcentCurrMem = max(0.0, min(pcentCurrMem, 100.0))
return pcentCurrMem, curmem
--
1.8.4
More information about the virt-tools-list
mailing list