Determine instance cores from public flavors API
Fixes bug 1078371 Previously the flavor vcpus used in the CPU utilization metering was available from the nova DB instance representation. Now that we retrieve the on-host instances from the public nova API as opposed to the DB, we need to retrieve the flavor vcpus from the flavors API. Note that it's a known issue with nova that a flavor associated with a running instance can be deleted and re-created with the same ID but a different resource configuration (in this case, a different number of cores would led to an incorrect CPU util calculation). This will be addressed in a future nova patch. Change-Id: I093acb94a4818f671782a3cb4e2c846f29b8cec5
This commit is contained in:
@@ -163,6 +163,8 @@ class CPUPollster(LibVirtPollster):
|
||||
delta = self.utilization_map[instance.id][1] - prev_timestamp
|
||||
elapsed = (delta.seconds * (10 ** 6) + delta.microseconds) * 1000
|
||||
cores_fraction = instance.vcpus * 1.0 / multiprocessing.cpu_count()
|
||||
cores_fraction = (instance.flavor['vcpus'] * 1.0 /
|
||||
multiprocessing.cpu_count())
|
||||
# account for cpu_time being reset when the instance is restarted
|
||||
time_used = (cpu_info['cpu_time'] - prev_cpu
|
||||
if prev_cpu <= cpu_info['cpu_time'] else
|
||||
@@ -176,10 +178,10 @@ class CPUPollster(LibVirtPollster):
|
||||
try:
|
||||
cpu_info = conn.get_info({'name': _instance_name(instance)})
|
||||
self.LOG.info("CPUTIME USAGE: %s %d",
|
||||
dict(instance), cpu_info['cpu_time'])
|
||||
instance.__dict__, cpu_info['cpu_time'])
|
||||
cpu_util = self.get_cpu_util(instance, cpu_info)
|
||||
self.LOG.info("CPU UTILIZATION %%: %s %0.2f",
|
||||
dict(instance), cpu_util)
|
||||
instance.__dict__, cpu_util)
|
||||
# FIXME(eglynn): once we have a way of configuring which measures
|
||||
# are published to each sink, we should by default
|
||||
# disable publishing this derived measure to the
|
||||
|
||||
@@ -54,6 +54,7 @@ class Client(object):
|
||||
for instance in instances:
|
||||
fid = instance.flavor['id']
|
||||
instance.flavor['name'] = flavors[fid].name
|
||||
instance.flavor['vcpus'] = flavors[fid].vcpus
|
||||
return instances
|
||||
|
||||
@logged
|
||||
|
||||
@@ -59,7 +59,7 @@ class TestLibvirtBase(test_base.TestCase):
|
||||
setattr(self.instance, 'OS-EXT-SRV-ATTR:instance_name',
|
||||
self.instance.name)
|
||||
self.instance.id = 1
|
||||
self.instance.flavor = {'name': 'm1.small', 'id': 2}
|
||||
self.instance.flavor = {'name': 'm1.small', 'id': 2, 'vcpus': 1}
|
||||
flags.FLAGS.compute_driver = 'libvirt.LibvirtDriver'
|
||||
flags.FLAGS.connection_type = 'libvirt'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user