Change hardware.cpu_util in workload_stabilization

In this change set, hardware.cpu_util is changed to
compute.node.cpu.percent in workload_stabilization.
By doing so, one can run this strategy on a simple devstack
without having to setup the SNMP plugin.

Change-Id: I8df8921337ea3f4e751c0c822d823e64e3ca7e1c
This commit is contained in:
Hidekazu Nakamura
2016-11-16 20:07:38 +09:00
parent 3532c74001
commit 5151b666fd
2 changed files with 25 additions and 16 deletions

View File

@@ -31,6 +31,7 @@ import copy
import itertools
import math
import random
import re
import oslo_cache
from oslo_config import cfg
@@ -119,7 +120,7 @@ class WorkloadStabilization(base.WorkloadStabilizationBaseStrategy):
"description": "Mapping to get hardware statistics using"
" instance metrics",
"type": "object",
"default": {"cpu_util": "hardware.cpu.util",
"default": {"cpu_util": "compute.node.cpu.percent",
"memory.resident": "hardware.memory.used"}
},
"host_choice": {
@@ -224,7 +225,7 @@ class WorkloadStabilization(base.WorkloadStabilizationBaseStrategy):
def get_hosts_load(self):
"""Get load of every available host by gathering instances load"""
hosts_load = {}
for node_id in self.get_available_nodes():
for node_id, node in self.get_available_nodes().items():
hosts_load[node_id] = {}
host_vcpus = self.compute_model.get_resource_by_uuid(
element.ResourceType.cpu_cores).get_capacity(
@@ -232,19 +233,27 @@ class WorkloadStabilization(base.WorkloadStabilizationBaseStrategy):
hosts_load[node_id]['vcpus'] = host_vcpus
for metric in self.metrics:
resource_id = ''
meter_name = self.instance_metrics[metric]
if re.match('^compute.node', meter_name) is not None:
resource_id = "%s_%s" % (node.uuid, node.hostname)
else:
resource_id = node_id
avg_meter = self.ceilometer.statistic_aggregation(
resource_id=node_id,
resource_id=resource_id,
meter_name=self.instance_metrics[metric],
period="60",
aggregate='avg'
)
if avg_meter is None:
raise exception.NoSuchMetricForHost(
metric=self.instance_metrics[metric],
metric=meter_name,
host=node_id)
if self.instance_metrics[metric] == 'hardware.memory.used':
if meter_name == 'hardware.memory.used':
avg_meter /= oslo_utils.units.Ki
if self.instance_metrics[metric] == 'hardware.cpu.util':
if meter_name == 'compute.node.cpu.percent':
avg_meter /= 100
hosts_load[node_id][metric] = avg_meter
return hosts_load