inspector: memory: use usable of memoryStats if available
Since kernel v4.6, virtio balloon driver commit 5057dcd0f introduced metric VIRTIO_BALLOON_S_AVAIL, corresponding to 'Available' in /proc/meminfo. Libvirt exposed this metric as 'usable'. As 'Available' of meminfo is an estimate of how much memory is available for starting new applications, without swapping. It's a better metric for calculating memory_usage. Change-Id: I3b935f1fc2ed74ca45b26990c4f2bd5996e1dfea Signed-off-by: Chen Hanxiao <chenhx@certusnet.com.cn>
This commit is contained in:
parent
93eca81e58
commit
2dee485da7
@ -151,7 +151,10 @@ class LibvirtInspector(virt_inspector.Inspector):
|
||||
memory_swap_in = memory_swap_out = None
|
||||
memory_stats = domain.memoryStats()
|
||||
# Stat provided from libvirt is in KB, converting it to MB.
|
||||
if 'available' in memory_stats and 'unused' in memory_stats:
|
||||
if 'usable' in memory_stats and 'available' in memory_stats:
|
||||
memory_used = (memory_stats['available'] -
|
||||
memory_stats['usable']) / units.Ki
|
||||
elif 'available' in memory_stats and 'unused' in memory_stats:
|
||||
memory_used = (memory_stats['available'] -
|
||||
memory_stats['unused']) / units.Ki
|
||||
if 'rss' in memory_stats:
|
||||
|
@ -474,6 +474,27 @@ class TestLibvirtInspection(base.BaseTestCase):
|
||||
self.assertIsNone(stats.memory_swap_in)
|
||||
self.assertIsNone(stats.memory_swap_out)
|
||||
|
||||
def test_inspect_memory_with_usable(self):
|
||||
domain = mock.Mock()
|
||||
domain.info.return_value = (0, 0, 0, 2, 999999)
|
||||
domain.memoryStats.return_value = {'available': 76800,
|
||||
'rss': 30000,
|
||||
'swap_in': 5120,
|
||||
'swap_out': 8192,
|
||||
'unused': 25600,
|
||||
'usable': 51200}
|
||||
conn = mock.Mock()
|
||||
conn.domainListGetStats.return_value = [({}, {})]
|
||||
conn.lookupByUUIDString.return_value = domain
|
||||
|
||||
with mock.patch('ceilometer.compute.virt.libvirt.utils.'
|
||||
'refresh_libvirt_connection', return_value=conn):
|
||||
stats = self.inspector.inspect_instance(self.instance, None)
|
||||
self.assertEqual(25600 / units.Ki, stats.memory_usage)
|
||||
self.assertEqual(30000 / units.Ki, stats.memory_resident)
|
||||
self.assertEqual(5120 / units.Ki, stats.memory_swap_in)
|
||||
self.assertEqual(8192 / units.Ki, stats.memory_swap_out)
|
||||
|
||||
def test_inspect_perf_events_libvirt_less_than_2_3_0(self):
|
||||
domain = mock.Mock()
|
||||
domain.info.return_value = (0, 0, 51200, 2, 999999)
|
||||
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
features:
|
||||
- use memory usable metric from libvirt memoryStats if available.
|
Loading…
x
Reference in New Issue
Block a user