Add separate notification handler for instance flavor
This notification handler records a meter event with the instance flavor included, making it easier to query for the amount of time an instance existed as a specific flavor. Change-Id: Ic162ac021f864c2a98c47127288867e940469ceb Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
This commit is contained in:
parent
867f168f61
commit
039f3d893d
@ -124,4 +124,29 @@ class EphemeralDiskSize(_Base):
|
||||
timestamp=message['timestamp'],
|
||||
duration=0,
|
||||
resource_metadata={}),
|
||||
]
|
||||
]
|
||||
|
||||
|
||||
class InstanceFlavor(_Base):
|
||||
|
||||
@staticmethod
|
||||
def process_notification(message):
|
||||
counters = []
|
||||
metadata = instance.get_metadata_from_event(message)
|
||||
instance_type = message.get('payload', {}).get('instance_type')
|
||||
if instance_type:
|
||||
counters.append(
|
||||
counter.Counter(
|
||||
source='?',
|
||||
name='instance:%s' % instance_type,
|
||||
type='absolute',
|
||||
volume=1,
|
||||
user_id=message['payload']['user_id'],
|
||||
project_id=message['payload']['tenant_id'],
|
||||
resource_id=message['payload']['instance_id'],
|
||||
timestamp=message['timestamp'],
|
||||
duration=0,
|
||||
resource_metadata=metadata,
|
||||
)
|
||||
)
|
||||
return counters
|
||||
|
1
setup.py
1
setup.py
@ -38,6 +38,7 @@ setuptools.setup(
|
||||
entry_points=textwrap.dedent("""
|
||||
[ceilometer.collector.compute]
|
||||
instance = ceilometer.compute.notifications:Instance
|
||||
instance_flavor = ceilometer.compute.notifications:InstanceFlavor
|
||||
memory = ceilometer.compute.notifications:Memory
|
||||
vcpus = ceilometer.compute.notifications:VCpus
|
||||
root_disk_size = ceilometer.compute.notifications:RootDiskSize
|
||||
|
@ -197,6 +197,13 @@ class TestNotifications(unittest.TestCase):
|
||||
c = counters[0]
|
||||
self.assertEqual(c.volume, 1)
|
||||
|
||||
def test_instance_create_flavor(self):
|
||||
ic = notifications.InstanceFlavor()
|
||||
counters = ic.process_notification(INSTANCE_CREATE_END)
|
||||
self.assertEqual(len(counters), 1)
|
||||
c = counters[0]
|
||||
self.assertEqual(c.volume, 1)
|
||||
|
||||
def test_instance_create_memory(self):
|
||||
ic = notifications.Memory()
|
||||
counters = ic.process_notification(INSTANCE_CREATE_END)
|
||||
@ -231,8 +238,17 @@ class TestNotifications(unittest.TestCase):
|
||||
counters = ic.process_notification(INSTANCE_EXISTS)
|
||||
self.assertEqual(len(counters), 1)
|
||||
|
||||
def test_instance_exists_flavor(self):
|
||||
ic = notifications.Instance()
|
||||
counters = ic.process_notification(INSTANCE_EXISTS)
|
||||
self.assertEqual(len(counters), 1)
|
||||
|
||||
def test_instance_delete_instance(self):
|
||||
ic = notifications.Instance()
|
||||
counters = ic.process_notification(INSTANCE_DELETE_START)
|
||||
self.assertEqual(len(counters), 1)
|
||||
|
||||
def test_instance_delete_flavor(self):
|
||||
ic = notifications.Instance()
|
||||
counters = ic.process_notification(INSTANCE_DELETE_START)
|
||||
self.assertEqual(len(counters), 1)
|
||||
|
Loading…
Reference in New Issue
Block a user