add counter type field

bug 1006425

Rename the existing counter "type" field to "name" and add
a new field with values of "cumulative" or "delta".

Change-Id: I459049bab28c3e2146b7a1b2e134dddabe381a6a
This commit is contained in:
Doug Hellmann 2012-06-06 16:11:07 -04:00
parent 14c068d2e8
commit f5b08423b9
12 changed files with 36 additions and 21 deletions

View File

@ -78,7 +78,7 @@ class AgentManager(manager.Manager):
}
rpc.cast(context, cfg.CONF.metering_topic, msg)
rpc.cast(context,
cfg.CONF.metering_topic + '.' + c.type,
cfg.CONF.metering_topic + '.' + c.name,
msg)
except Exception as err:
LOG.warning('Continuing after error from %s: %s', name, err)

View File

@ -84,7 +84,7 @@ class CollectorManager(manager.Manager):
ctxt = context.get_admin_context()
nova_rpc.cast(ctxt, cfg.CONF.metering_topic, msg)
nova_rpc.cast(ctxt,
cfg.CONF.metering_topic + '.' + counter.type,
cfg.CONF.metering_topic + '.' + counter.name,
msg)
def record_metering_data(self, context, data):

View File

@ -37,9 +37,10 @@ LOG = logging.getLogger('nova.' + __name__)
MIB = 2 ** 20 # mebibytes
def make_counter_from_instance(instance, type, volume):
def make_counter_from_instance(instance, name, type, volume):
return counter.Counter(
source='?',
name=name,
type=type,
volume=volume,
user_id=instance.user_id,
@ -91,7 +92,8 @@ class DiskIOPollster(plugin.PollsterBase):
stats[2], stats[3], stats[4])
bytes += stats[1] + stats[3] # combine read and write
yield make_counter_from_instance(instance,
type='disk',
name='disk',
type='cumulative',
volume=bytes / MIB,
)
@ -112,7 +114,8 @@ class CPUPollster(plugin.PollsterBase):
self.LOG.info("CPUTIME USAGE: %s %d",
instance, cpu_info['cpu_time'])
yield make_counter_from_instance(instance,
type='cpu',
name='cpu',
type='cumulative',
volume=cpu_info['cpu_time'],
)
except Exception as err:

View File

@ -36,12 +36,13 @@ class FloatingIPPollster(plugin.PollsterBase):
for ip in ips:
self.LOG.info("FLOATING IP USAGE: %s" % ip.address)
yield counter.Counter(source='?',
type='floating_ip',
name='floating_ip',
type='delta',
volume=1,
user_id=None,
project_id=ip.project_id,
resource_id=ip.id,
datetime=None,
timestamp=None,
duration=None,
resource_metadata={
'address': ip.address,

View File

@ -26,7 +26,8 @@ def c1(body):
"""Generate c1(instance) counters for a notice."""
return counter.Counter(
source='?',
type='instance',
name='instance',
type='delta',
volume=1,
user_id=body['payload']['user_id'],
project_id=body['payload']['tenant_id'],

View File

@ -27,6 +27,7 @@ import collections
Counter = collections.namedtuple('Counter',
' '.join(['source',
'name',
'type',
'volume',
'user_id',

View File

@ -59,6 +59,7 @@ def meter_message_from_counter(counter):
for a notification message and a Counter instance.
"""
msg = {'source': counter.source,
'counter_name': counter.name,
'counter_type': counter.type,
'counter_volume': counter.volume,
'user_id': counter.user_id,

View File

@ -41,7 +41,8 @@ class TestRunTasks(test.TestCase):
counters = []
test_data = counter.Counter(
source='test',
type='test',
name='test',
type='cumulative',
volume=1,
user_id='test',
project_id='test',

View File

@ -73,7 +73,7 @@ def test_notify():
d.notify(TEST_NOTICE)
assert len(results) == 1
counter = results[0]
assert counter.type == 'instance'
assert counter.name == 'instance'
def test_load_compute_plugins():
@ -103,4 +103,4 @@ def test_notify_through_plugin():
d.notify(TEST_NOTICE)
assert len(results) == 1
counter = results[0]
assert counter.type == 'instance'
assert counter.name == 'instance'

View File

@ -34,19 +34,23 @@ class TestFloatingIPPollster(test.TestCase):
super(TestFloatingIPPollster, self).setUp()
def test_get_counters(self):
self.assertEqual(list(self.pollster.get_counters(self.manager, self.context)), [])
self.assertEqual(list(self.pollster.get_counters(self.manager,
self.context)),
[])
def test_get_counters_not_empty(self):
db.floating_ip_create(self.context,
{'address': '1.1.1.1',
'host': self.manager.host })
'host': self.manager.host,
})
db.floating_ip_create(self.context,
{'address': '1.1.1.2',
'host': self.manager.host + "randomstring" })
'host': self.manager.host + "randomstring",
})
db.floating_ip_create(self.context,
{'address': '1.1.1.3',
'host': self.manager.host + "randomstring" })
'host': self.manager.host + "randomstring",
})
counters = list(self.pollster.get_counters(self.manager, self.context))
self.assertEqual(len(counters), 1)
self.assertEqual(counters[0].resource_metadata['address'], '1.1.1.1')

View File

@ -135,7 +135,8 @@ def test_c1():
info = notifications.c1(INSTANCE_CREATE_END)
for name, actual, expected in [
('counter_type', info.type, 'instance'),
('counter_name', info.name, 'instance'),
('counter_type', info.type, 'delta'),
('counter_volume', info.volume, 1),
('timestamp', info.timestamp,
INSTANCE_CREATE_END['timestamp']),
@ -155,18 +156,18 @@ def test_instance_create():
ic = notifications.InstanceNotifications()
counters = ic.process_notification(INSTANCE_CREATE_END)
assert len(counters) == 1
assert counters[0].type == 'instance'
assert counters[0].name == 'instance'
def test_instance_exists():
ic = notifications.InstanceNotifications()
counters = ic.process_notification(INSTANCE_EXISTS)
assert len(counters) == 1
assert counters[0].type == 'instance'
assert counters[0].name == 'instance'
def test_instance_delete():
ic = notifications.InstanceNotifications()
counters = ic.process_notification(INSTANCE_DELETE_START)
assert len(counters) == 1
assert counters[0].type == 'instance'
assert counters[0].name == 'instance'

View File

@ -62,6 +62,7 @@ def test_compute_signature_use_configured_secret():
TEST_COUNTER = counter.Counter(source='src',
name='name',
type='typ',
volume=1,
user_id='user',
@ -124,7 +125,8 @@ def test_meter_message_from_counter_field():
def compare(f, c, msg_f, msg):
assert msg == c
msg = meter.meter_message_from_counter(TEST_COUNTER)
name_map = {'type': 'counter_type',
name_map = {'name': 'counter_name',
'type': 'counter_type',
'volume': 'counter_volume',
'duration': 'counter_duration',
}