From bc8daafa83c4a53b9835d222c849277a937b70f3 Mon Sep 17 00:00:00 2001 From: Eoghan Glynn Date: Fri, 12 Jul 2013 10:41:30 +0000 Subject: [PATCH] Provide CPU number as additional metadata. So that a tranformer can access the CPU number in order to calculate CPU utilization %, we now include this in the resource metadata of samples for the cpu meter. Change-Id: I6eb8c65bf4ddf4dd3447e5e32c79d92a3d38f5f1 --- ceilometer/compute/pollsters/cpu.py | 2 ++ ceilometer/compute/pollsters/util.py | 7 +++++-- tests/compute/pollsters/test_cpu.py | 2 ++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/ceilometer/compute/pollsters/cpu.py b/ceilometer/compute/pollsters/cpu.py index 7bad23fd7..eecdfbf38 100644 --- a/ceilometer/compute/pollsters/cpu.py +++ b/ceilometer/compute/pollsters/cpu.py @@ -69,12 +69,14 @@ class CPUPollster(_Base): def _get_counter(instance, instance_name, cpu_info): LOG.info("CPUTIME USAGE: %s %d", instance.__dict__, cpu_info.time) + cpu_num = {'cpu_number': cpu_info.number} return util.make_counter_from_instance( instance, name='cpu', type=counter.TYPE_CUMULATIVE, unit='ns', volume=cpu_info.time, + additional_metadata=cpu_num, ) diff --git a/ceilometer/compute/pollsters/util.py b/ceilometer/compute/pollsters/util.py index 429cd57ee..97b2c8da0 100644 --- a/ceilometer/compute/pollsters/util.py +++ b/ceilometer/compute/pollsters/util.py @@ -96,7 +96,10 @@ def _get_metadata_from_object(instance): return _add_reserved_user_metadata(instance, metadata) -def make_counter_from_instance(instance, name, type, unit, volume): +def make_counter_from_instance(instance, name, type, unit, volume, + additional_metadata={}): + resource_metadata = _get_metadata_from_object(instance) + resource_metadata.update(additional_metadata) return counter.Counter( name=name, type=type, @@ -106,7 +109,7 @@ def make_counter_from_instance(instance, name, type, unit, volume): project_id=instance.tenant_id, resource_id=instance.id, timestamp=timeutils.isotime(), - resource_metadata=_get_metadata_from_object(instance), + resource_metadata=resource_metadata, ) diff --git a/tests/compute/pollsters/test_cpu.py b/tests/compute/pollsters/test_cpu.py index 66160cfde..9184281a7 100644 --- a/tests/compute/pollsters/test_cpu.py +++ b/tests/compute/pollsters/test_cpu.py @@ -57,6 +57,8 @@ class TestCPUPollster(base.TestPollsterBase): assert counters[0].volume == expected_time assert pollster.CACHE_KEY_CPU in cache assert self.instance.name in cache[pollster.CACHE_KEY_CPU] + self.assertEquals(counters[0].resource_metadata.get('cpu_number'), + 2) # ensure elapsed time between polling cycles is non-zero time.sleep(0.001)