[virt-tools-list] [PATCHv2 2/2] Base mem statistics on virDomainMemoryStats if available.
Cole Robinson
crobinso at redhat.com
Mon Jan 6 17:09:18 UTC 2014
On 12/18/2013 08:42 AM, Thorsten Behrens wrote:
> 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
There's a few issues here. curmem should only be 0 if self.is_active(),
independent of the support check. So the GetInfo fallback doesn't work.
That said, I don't want the memory graph to mean different things if
memoryStats isn't supported, since that's just going to confuse people. So I
removed the GetInfo fallback.
We should find a way to make this case more clear in the UI, but that can come
later.
Pushed now, thanks.
- Cole
> + 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
>
More information about the virt-tools-list
mailing list