Implements memory counter
This adds a memory counter, that is emitted at the same time than instance counter. It is the first counter implementing the 'absolute' counter type. Change-Id: I3bfd57da61029d43ba4f731f98dc58f790f9f8cd Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
dcce2c7323
commit
344ad3eef0
@ -36,8 +36,8 @@ class InstanceNotifications(plugin.NotificationBase):
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def process_notification(message):
|
def process_notification(message):
|
||||||
return [counter.Counter(
|
return [
|
||||||
source='?',
|
counter.Counter(source='?',
|
||||||
name='instance',
|
name='instance',
|
||||||
type='cumulative',
|
type='cumulative',
|
||||||
volume=1,
|
volume=1,
|
||||||
@ -46,5 +46,16 @@ class InstanceNotifications(plugin.NotificationBase):
|
|||||||
resource_id=message['payload']['instance_id'],
|
resource_id=message['payload']['instance_id'],
|
||||||
timestamp=message['timestamp'],
|
timestamp=message['timestamp'],
|
||||||
duration=0,
|
duration=0,
|
||||||
resource_metadata=instance.get_metadata_from_event(message),
|
resource_metadata=instance.get_metadata_from_event(
|
||||||
)]
|
message)),
|
||||||
|
counter.Counter(source='?',
|
||||||
|
name='memory',
|
||||||
|
type='absolute',
|
||||||
|
volume=message['payload']['memory_mb'],
|
||||||
|
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={}),
|
||||||
|
]
|
||||||
|
@ -83,7 +83,7 @@ def test_notify():
|
|||||||
results = []
|
results = []
|
||||||
d = StubDispatcher(None, lambda x: results.append(x))
|
d = StubDispatcher(None, lambda x: results.append(x))
|
||||||
d.notify(TEST_NOTICE)
|
d.notify(TEST_NOTICE)
|
||||||
assert len(results) == 1
|
assert len(results) >= 1
|
||||||
counter = results[0]
|
counter = results[0]
|
||||||
assert counter.name == 'instance'
|
assert counter.name == 'instance'
|
||||||
|
|
||||||
@ -113,6 +113,7 @@ def test_notify_through_plugin():
|
|||||||
lambda x: results.append(x)
|
lambda x: results.append(x)
|
||||||
)
|
)
|
||||||
d.notify(TEST_NOTICE)
|
d.notify(TEST_NOTICE)
|
||||||
assert len(results) == 1
|
assert len(results) >= 1
|
||||||
counter = results[0]
|
results_name = [ result.name for result in results ]
|
||||||
assert counter.name == 'instance'
|
assert 'instance' in results_name
|
||||||
|
assert 'memory' in results_name
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
notification events.
|
notification events.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import unittest
|
||||||
|
|
||||||
from ceilometer.compute import notifications
|
from ceilometer.compute import notifications
|
||||||
|
|
||||||
|
|
||||||
@ -163,11 +165,8 @@ INSTANCE_EXISTS = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def compare(name, actual, expected):
|
class TestNotifications(unittest.TestCase):
|
||||||
assert actual == expected, name
|
def test_process_notification(self):
|
||||||
|
|
||||||
|
|
||||||
def test_process_notification():
|
|
||||||
info = notifications.InstanceNotifications.process_notification(INSTANCE_CREATE_END)[0]
|
info = notifications.InstanceNotifications.process_notification(INSTANCE_CREATE_END)[0]
|
||||||
|
|
||||||
for name, actual, expected in [
|
for name, actual, expected in [
|
||||||
@ -188,22 +187,30 @@ def test_process_notification():
|
|||||||
yield compare, name, actual, expected
|
yield compare, name, actual, expected
|
||||||
|
|
||||||
|
|
||||||
def test_instance_create():
|
def test_instance_create(self):
|
||||||
ic = notifications.InstanceNotifications()
|
ic = notifications.InstanceNotifications()
|
||||||
counters = ic.process_notification(INSTANCE_CREATE_END)
|
counters = ic.process_notification(INSTANCE_CREATE_END)
|
||||||
assert len(counters) == 1
|
|
||||||
assert counters[0].name == 'instance'
|
self.assertEqual(len(counters), 2)
|
||||||
|
|
||||||
|
self.assertEqual(counters[0].name, 'instance')
|
||||||
|
self.assertEqual(counters[0].volume, 1)
|
||||||
|
|
||||||
|
self.assertEqual(counters[1].name, 'memory')
|
||||||
|
self.assertEqual(counters[1].volume, INSTANCE_CREATE_END['payload']['memory_mb'])
|
||||||
|
|
||||||
|
|
||||||
def test_instance_exists():
|
def test_instance_exists(self):
|
||||||
ic = notifications.InstanceNotifications()
|
ic = notifications.InstanceNotifications()
|
||||||
counters = ic.process_notification(INSTANCE_EXISTS)
|
counters = ic.process_notification(INSTANCE_EXISTS)
|
||||||
assert len(counters) == 1
|
self.assertEqual(len(counters), 2)
|
||||||
assert counters[0].name == 'instance'
|
self.assertEqual(counters[0].name, 'instance')
|
||||||
|
self.assertEqual(counters[1].name, 'memory')
|
||||||
|
|
||||||
|
|
||||||
def test_instance_delete():
|
def test_instance_delete(self):
|
||||||
ic = notifications.InstanceNotifications()
|
ic = notifications.InstanceNotifications()
|
||||||
counters = ic.process_notification(INSTANCE_DELETE_START)
|
counters = ic.process_notification(INSTANCE_DELETE_START)
|
||||||
assert len(counters) == 1
|
self.assertEqual(len(counters), 2)
|
||||||
assert counters[0].name == 'instance'
|
self.assertEqual(counters[0].name, 'instance')
|
||||||
|
self.assertEqual(counters[1].name, 'memory')
|
||||||
|
Loading…
Reference in New Issue
Block a user