Merge "Provide CPU number as additional metadata."
This commit is contained in:
commit
65c4790303
@ -69,12 +69,14 @@ class CPUPollster(_Base):
|
|||||||
def _get_counter(instance, instance_name, cpu_info):
|
def _get_counter(instance, instance_name, cpu_info):
|
||||||
LOG.info("CPUTIME USAGE: %s %d",
|
LOG.info("CPUTIME USAGE: %s %d",
|
||||||
instance.__dict__, cpu_info.time)
|
instance.__dict__, cpu_info.time)
|
||||||
|
cpu_num = {'cpu_number': cpu_info.number}
|
||||||
return util.make_counter_from_instance(
|
return util.make_counter_from_instance(
|
||||||
instance,
|
instance,
|
||||||
name='cpu',
|
name='cpu',
|
||||||
type=counter.TYPE_CUMULATIVE,
|
type=counter.TYPE_CUMULATIVE,
|
||||||
unit='ns',
|
unit='ns',
|
||||||
volume=cpu_info.time,
|
volume=cpu_info.time,
|
||||||
|
additional_metadata=cpu_num,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,7 +96,10 @@ def _get_metadata_from_object(instance):
|
|||||||
return _add_reserved_user_metadata(instance, metadata)
|
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(
|
return counter.Counter(
|
||||||
name=name,
|
name=name,
|
||||||
type=type,
|
type=type,
|
||||||
@ -106,7 +109,7 @@ def make_counter_from_instance(instance, name, type, unit, volume):
|
|||||||
project_id=instance.tenant_id,
|
project_id=instance.tenant_id,
|
||||||
resource_id=instance.id,
|
resource_id=instance.id,
|
||||||
timestamp=timeutils.isotime(),
|
timestamp=timeutils.isotime(),
|
||||||
resource_metadata=_get_metadata_from_object(instance),
|
resource_metadata=resource_metadata,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,6 +57,8 @@ class TestCPUPollster(base.TestPollsterBase):
|
|||||||
assert counters[0].volume == expected_time
|
assert counters[0].volume == expected_time
|
||||||
assert pollster.CACHE_KEY_CPU in cache
|
assert pollster.CACHE_KEY_CPU in cache
|
||||||
assert self.instance.name in cache[pollster.CACHE_KEY_CPU]
|
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
|
# ensure elapsed time between polling cycles is non-zero
|
||||||
time.sleep(0.001)
|
time.sleep(0.001)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user