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
This commit is contained in:
Eoghan Glynn 2013-07-12 10:41:30 +00:00
parent a1a80e0a1f
commit bc8daafa83
3 changed files with 9 additions and 2 deletions

View File

@ -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,
)

View File

@ -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,
)

View File

@ -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)