Hyper-V: Adds memory metrics implementation
This change targets compute nodes that run on Windows Hyper-v / Server 2012 or Windows 8 or newer. It retrieves the memory usage associated with the given instance and returns a MemoryUsageStats object containing the value. This change is particularly useful for compute nodes that have dynamic memory enabled in nova.conf. DocImpact Implements: blueprint hyper-v-memory-metrics Change-Id: I6496133c3c49ebcc37873004ed58f4d37dbbdd9c
This commit is contained in:
parent
cdddf83227
commit
10c3e3eb94
@ -45,6 +45,11 @@ class HyperVInspector(virt_inspector.Inspector):
|
|||||||
|
|
||||||
return virt_inspector.CPUStats(number=cpu_count, time=cpu_time)
|
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):
|
def inspect_vnics(self, instance):
|
||||||
instance_name = util.instance_name(instance)
|
instance_name = util.instance_name(instance)
|
||||||
for vnic_metrics in self._utils.get_vnic_metrics(instance_name):
|
for vnic_metrics in self._utils.get_vnic_metrics(instance_name):
|
||||||
|
@ -41,6 +41,7 @@ class UtilsV2(object):
|
|||||||
_VIRTUAL_SYSTEM_TYPE_REALIZED = 'Microsoft:Hyper-V:System:Realized'
|
_VIRTUAL_SYSTEM_TYPE_REALIZED = 'Microsoft:Hyper-V:System:Realized'
|
||||||
|
|
||||||
_PROC_SETTING = 'Msvm_ProcessorSettingData'
|
_PROC_SETTING = 'Msvm_ProcessorSettingData'
|
||||||
|
_MEMORY_SETTING = "Msvm_MemorySettingData"
|
||||||
_SYNTH_ETH_PORT = 'Msvm_SyntheticEthernetPortSettingData'
|
_SYNTH_ETH_PORT = 'Msvm_SyntheticEthernetPortSettingData'
|
||||||
_ETH_PORT_ALLOC = 'Msvm_EthernetPortAllocationSettingData'
|
_ETH_PORT_ALLOC = 'Msvm_EthernetPortAllocationSettingData'
|
||||||
_PORT_ACL_SET_DATA = 'Msvm_EthernetSwitchPortAclSettingData'
|
_PORT_ACL_SET_DATA = 'Msvm_EthernetSwitchPortAclSettingData'
|
||||||
@ -50,6 +51,7 @@ class UtilsV2(object):
|
|||||||
_BASE_METRICS_VALUE = 'Msvm_BaseMetricValue'
|
_BASE_METRICS_VALUE = 'Msvm_BaseMetricValue'
|
||||||
|
|
||||||
_CPU_METRIC_NAME = 'Aggregated Average CPU Utilization'
|
_CPU_METRIC_NAME = 'Aggregated Average CPU Utilization'
|
||||||
|
_MEMORY_METRIC_NAME = 'Aggregated Average Memory Utilization'
|
||||||
_NET_IN_METRIC_NAME = 'Filtered Incoming Network Traffic'
|
_NET_IN_METRIC_NAME = 'Filtered Incoming Network Traffic'
|
||||||
_NET_OUT_METRIC_NAME = 'Filtered Outgoing Network Traffic'
|
_NET_OUT_METRIC_NAME = 'Filtered Outgoing Network Traffic'
|
||||||
# Disk metrics are supported from Hyper-V 2012 R2
|
# Disk metrics are supported from Hyper-V 2012 R2
|
||||||
@ -94,6 +96,15 @@ class UtilsV2(object):
|
|||||||
int(cpu_sd.VirtualQuantity),
|
int(cpu_sd.VirtualQuantity),
|
||||||
long(vm.OnTimeInMilliseconds))
|
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):
|
def get_vnic_metrics(self, vm_name):
|
||||||
vm = self._lookup_vm(vm_name)
|
vm = self._lookup_vm(vm_name)
|
||||||
ports = self._get_vm_resources(vm, self._ETH_PORT_ALLOC)
|
ports = self._get_vm_resources(vm, self._ETH_PORT_ALLOC)
|
||||||
|
@ -54,6 +54,14 @@ class TestHyperVInspection(base.BaseTestCase):
|
|||||||
self.assertEqual(fake_cpu_count, cpu_stats.number)
|
self.assertEqual(fake_cpu_count, cpu_stats.number)
|
||||||
self.assertEqual(fake_cpu_time, cpu_stats.time)
|
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):
|
def test_inspect_vnics(self):
|
||||||
fake_instance_name = 'fake_instance_name'
|
fake_instance_name = 'fake_instance_name'
|
||||||
fake_rx_mb = 1000
|
fake_rx_mb = 1000
|
||||||
|
@ -33,6 +33,28 @@ class TestUtilsV2(base.BaseTestCase):
|
|||||||
|
|
||||||
super(TestUtilsV2, self).setUp()
|
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):
|
def test_get_host_cpu_info(self):
|
||||||
_fake_clock_speed = 1000
|
_fake_clock_speed = 1000
|
||||||
_fake_cpu_count = 2
|
_fake_cpu_count = 2
|
||||||
|
@ -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
|
||||||
instance:<type> g instance inst ID both 1, 2, 3, 4 Existence of instance <type> (openstack types)
|
instance:<type> g instance inst ID both 1, 2, 3, 4 Existence of instance <type> (openstack types)
|
||||||
memory g MB inst ID n 1, 2 Volume of RAM allocated
|
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 c ns inst ID p 1, 2 CPU time used
|
||||||
cpu_util g % inst ID p 1, 2, 3, 4 Average CPU utilisation
|
cpu_util g % inst ID p 1, 2, 3, 4 Average CPU utilisation
|
||||||
vcpus g vcpu inst ID n 1, 2 Number of VCPUs
|
vcpus g vcpu inst ID n 1, 2 Number of VCPUs
|
||||||
|
Loading…
Reference in New Issue
Block a user