diff --git a/ceilometer/compute/libvirt.py b/ceilometer/compute/libvirt.py index c6c0d8020..c389c994e 100644 --- a/ceilometer/compute/libvirt.py +++ b/ceilometer/compute/libvirt.py @@ -18,7 +18,6 @@ import copy import datetime -import multiprocessing from lxml import etree @@ -167,8 +166,7 @@ class CPUPollster(LibVirtPollster): prev_timestamp = prev_times[1] delta = self.utilization_map[instance.id][1] - prev_timestamp elapsed = (delta.seconds * (10 ** 6) + delta.microseconds) * 1000 - cores_fraction = (instance.flavor['vcpus'] * 1.0 / - multiprocessing.cpu_count()) + cores_fraction = 1.0 / cpu_info['num_cpu'] # 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 diff --git a/ceilometer/nova_client.py b/ceilometer/nova_client.py index 470182caa..77359db5e 100644 --- a/ceilometer/nova_client.py +++ b/ceilometer/nova_client.py @@ -54,7 +54,6 @@ 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 diff --git a/tests/compute/test_libvirt.py b/tests/compute/test_libvirt.py index b306addbf..5983550ef 100644 --- a/tests/compute/test_libvirt.py +++ b/tests/compute/test_libvirt.py @@ -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, 'vcpus': 1} + self.instance.flavor = {'name': 'm1.small', 'id': 2} flags.FLAGS.compute_driver = 'libvirt.LibvirtDriver' flags.FLAGS.connection_type = 'libvirt' @@ -215,16 +215,15 @@ class TestCPUPollster(TestLibvirtBase): self.pollster = libvirt.CPUPollster() def test_get_counter(self): - self.instance.vcpus = 1 conn = fake_libvirt_conn(self.mox, 3) self.mox.StubOutWithMock(conn, 'get_info') conn.get_info({'name': self.instance.name}).AndReturn( - {'cpu_time': 1 * (10 ** 6)}) + {'cpu_time': 1 * (10 ** 6), 'num_cpu': 2}) conn.get_info({'name': self.instance.name}).AndReturn( - {'cpu_time': 3 * (10 ** 6)}) + {'cpu_time': 3 * (10 ** 6), 'num_cpu': 2}) # cpu_time resets on instance restart conn.get_info({'name': self.instance.name}).AndReturn( - {'cpu_time': 2 * (10 ** 6)}) + {'cpu_time': 2 * (10 ** 6), 'num_cpu': 2}) self.mox.ReplayAll() def _verify_cpu_metering(zero, expected_time):