diff --git a/ceilometer/compute/virt/hyperv/inspector.py b/ceilometer/compute/virt/hyperv/inspector.py index d46e416b8..6e57cd58a 100644 --- a/ceilometer/compute/virt/hyperv/inspector.py +++ b/ceilometer/compute/virt/hyperv/inspector.py @@ -45,6 +45,11 @@ class HyperVInspector(virt_inspector.Inspector): return virt_inspector.CPUStats(number=cpu_count, time=cpu_time) + def inspect_memory_usage(self, instance, duration=None): + instance_name = util.instance_name(instance) + usage = self._utils.get_memory_metrics(instance_name) + return virt_inspector.MemoryUsageStats(usage=usage) + def inspect_vnics(self, instance): instance_name = util.instance_name(instance) for vnic_metrics in self._utils.get_vnic_metrics(instance_name): diff --git a/ceilometer/compute/virt/hyperv/utilsv2.py b/ceilometer/compute/virt/hyperv/utilsv2.py index c4e3ce59f..a4ee07c3d 100644 --- a/ceilometer/compute/virt/hyperv/utilsv2.py +++ b/ceilometer/compute/virt/hyperv/utilsv2.py @@ -41,6 +41,7 @@ class UtilsV2(object): _VIRTUAL_SYSTEM_TYPE_REALIZED = 'Microsoft:Hyper-V:System:Realized' _PROC_SETTING = 'Msvm_ProcessorSettingData' + _MEMORY_SETTING = "Msvm_MemorySettingData" _SYNTH_ETH_PORT = 'Msvm_SyntheticEthernetPortSettingData' _ETH_PORT_ALLOC = 'Msvm_EthernetPortAllocationSettingData' _PORT_ACL_SET_DATA = 'Msvm_EthernetSwitchPortAclSettingData' @@ -50,6 +51,7 @@ class UtilsV2(object): _BASE_METRICS_VALUE = 'Msvm_BaseMetricValue' _CPU_METRIC_NAME = 'Aggregated Average CPU Utilization' + _MEMORY_METRIC_NAME = 'Aggregated Average Memory Utilization' _NET_IN_METRIC_NAME = 'Filtered Incoming Network Traffic' _NET_OUT_METRIC_NAME = 'Filtered Outgoing Network Traffic' # Disk metrics are supported from Hyper-V 2012 R2 @@ -94,6 +96,15 @@ class UtilsV2(object): int(cpu_sd.VirtualQuantity), long(vm.OnTimeInMilliseconds)) + def get_memory_metrics(self, vm_name): + vm = self._lookup_vm(vm_name) + memory_def = self._get_metric_def(self._MEMORY_METRIC_NAME) + metric_memory = self._get_metrics(vm, memory_def) + memory_usage = 0 + if metric_memory: + memory_usage = long(metric_memory[0].MetricValue) + return memory_usage + def get_vnic_metrics(self, vm_name): vm = self._lookup_vm(vm_name) ports = self._get_vm_resources(vm, self._ETH_PORT_ALLOC) diff --git a/ceilometer/tests/compute/virt/hyperv/test_inspector.py b/ceilometer/tests/compute/virt/hyperv/test_inspector.py index 56dda29ff..6745d3ab9 100644 --- a/ceilometer/tests/compute/virt/hyperv/test_inspector.py +++ b/ceilometer/tests/compute/virt/hyperv/test_inspector.py @@ -54,6 +54,14 @@ class TestHyperVInspection(base.BaseTestCase): self.assertEqual(fake_cpu_count, cpu_stats.number) self.assertEqual(fake_cpu_time, cpu_stats.time) + @mock.patch('ceilometer.compute.virt.hyperv.utilsv2.UtilsV2.' + 'get_memory_metrics') + def test_inspect_memory_usage(self, mock_get_memory_metrics): + fake_usage = self._inspector._utils.get_memory_metrics.return_value + usage = self._inspector.inspect_memory_usage( + mock.sentinel.FAKE_INSTANCE, mock.sentinel.FAKE_DURATION) + self.assertEqual(fake_usage, usage.usage) + def test_inspect_vnics(self): fake_instance_name = 'fake_instance_name' fake_rx_mb = 1000 diff --git a/ceilometer/tests/compute/virt/hyperv/test_utilsv2.py b/ceilometer/tests/compute/virt/hyperv/test_utilsv2.py index b519ce52d..f80c69062 100644 --- a/ceilometer/tests/compute/virt/hyperv/test_utilsv2.py +++ b/ceilometer/tests/compute/virt/hyperv/test_utilsv2.py @@ -33,6 +33,28 @@ class TestUtilsV2(base.BaseTestCase): super(TestUtilsV2, self).setUp() + @mock.patch.object(utilsv2.UtilsV2, '_get_metrics') + @mock.patch.object(utilsv2.UtilsV2, '_get_metric_def') + @mock.patch.object(utilsv2.UtilsV2, '_lookup_vm') + def test_get_memory_metrics(self, mock_lookup_vm, mock_get_metric_def, + mock_get_metrics): + mock_vm = mock_lookup_vm.return_value + + mock_metric_def = mock_get_metric_def.return_value + + metric_memory = mock.MagicMock() + metric_memory.MetricValue = 3 + mock_get_metrics.return_value = [metric_memory] + + response = self._utils.get_memory_metrics(mock.sentinel._FAKE_INSTANCE) + + mock_lookup_vm.assert_called_once_with(mock.sentinel._FAKE_INSTANCE) + mock_get_metric_def.assert_called_once_with( + self._utils._MEMORY_METRIC_NAME) + mock_get_metrics.assert_called_once_with(mock_vm, mock_metric_def) + + self.assertEqual(3, response) + def test_get_host_cpu_info(self): _fake_clock_speed = 1000 _fake_cpu_count = 2 diff --git a/doc/source/measurements.rst b/doc/source/measurements.rst index 39a340cde..50b095c98 100644 --- a/doc/source/measurements.rst +++ b/doc/source/measurements.rst @@ -71,7 +71,7 @@ Name Type* Unit Resource Origin** Support** instance g instance inst ID both 1, 2, 3, 4 Existence of instance instance: g instance inst ID both 1, 2, 3, 4 Existence of instance (openstack types) memory g MB inst ID n 1, 2 Volume of RAM allocated -memory.usage g MB inst ID p 1, 3, 4 Volume of RAM used +memory.usage g MB inst ID p 1, 2, 3, 4 Volume of RAM used cpu c ns inst ID p 1, 2 CPU time used cpu_util g % inst ID p 1, 2, 3, 4 Average CPU utilisation vcpus g vcpu inst ID n 1, 2 Number of VCPUs