Difference between revisions of "Trove/trove-notifications"
< Trove
(→Task Manager Events) |
|||
(5 intermediate revisions by the same user not shown) | |||
Line 43: | Line 43: | ||
payload) | payload) | ||
</pre> | </pre> | ||
− | |||
Line 52: | Line 51: | ||
<pre>self.send_usage_event('create', instance_size=flavor_ram)</pre> | <pre>self.send_usage_event('create', instance_size=flavor_ram)</pre> | ||
− | + | Example message: | |
<pre> | <pre> | ||
{ | { | ||
− | + | "priority": "INFO", | |
− | + | "event_type": "trove.instance.create", | |
− | + | "timestamp": "2015-06-28 05:54:57.725572", | |
− | + | "publisher_id": "0.0.0.0", | |
− | + | "payload": { | |
− | + | "state_description": "BUILD", | |
− | + | "instance_type": "m1.rd-tiny", | |
− | + | "user_id": "dd2b7a976381419a93f3234050c07bd5", | |
− | + | "name": "test", | |
− | + | "availability_zone": "nova", | |
+ | "tenant_id": "1bd558252da84dbf91bd50e379680b7a", | ||
+ | "instance_size": 512, | ||
+ | "instance_id": "6a0541e4-807e-4e9f-8cc1-44e3a36a6e1c", | ||
+ | "instance_type_id": 10, | ||
+ | "launched_at": "2015-06-28T05:54:52Z", | ||
+ | "instance_name": "test", | ||
+ | "volume_size": 1, | ||
+ | "state": "BUILD", | ||
+ | "nova_volume_id": "FAKE_VOL_dedff250-e668-4720-a583-e38483200569", | ||
+ | "nova_instance_id": "FAKE_1f0be776-49e2-416b-aeeb-f101b5fa93b9", | ||
+ | "service_id": "123", | ||
+ | "created_at": "2015-06-28T05:54:52Z", | ||
+ | "region": "LOCAL_DEV" | ||
+ | }, | ||
+ | "message_id": "7f8ff6b6-2f1f-40db-ae6f-c92cbc9e2827" | ||
} | } | ||
</pre> | </pre> | ||
Line 73: | Line 87: | ||
<pre>self.send_usage_event('modify_volume', launched_at=timeutils.isotime(), modify_at=timeutils.isotime(), volume_size=new_size)</pre> | <pre>self.send_usage_event('modify_volume', launched_at=timeutils.isotime(), modify_at=timeutils.isotime(), volume_size=new_size)</pre> | ||
− | + | Example Message: | |
<pre> | <pre> | ||
{ | { | ||
− | + | "priority": "INFO", | |
− | + | "event_type": "trove.instance.modify_volume", | |
− | + | "timestamp": "2015-06-28 05:58:25.827067", | |
− | + | "publisher_id": "0.0.0.0", | |
− | + | "payload": { | |
− | + | "state_description": "ACTIVE", | |
− | + | "old_volume_size": 1, | |
− | + | "user_id": "dd2b7a976381419a93f3234050c07bd5", | |
− | + | "name": "test", | |
− | + | "availability_zone": "nova", | |
− | + | "tenant_id": "1bd558252da84dbf91bd50e379680b7a", | |
+ | "instance_size": 512, | ||
+ | "instance_id": "6a0541e4-807e-4e9f-8cc1-44e3a36a6e1c", | ||
+ | "instance_type_id": 10, | ||
+ | "launched_at": "2015-06-28T05:58:25Z", | ||
+ | "instance_name": "test", | ||
+ | "volume_size": 3, | ||
+ | "state": "ACTIVE", | ||
+ | "nova_volume_id": "FAKE_VOL_dedff250-e668-4720-a583-e38483200569", | ||
+ | "nova_instance_id": "FAKE_1f0be776-49e2-416b-aeeb-f101b5fa93b9", | ||
+ | "service_id": "123", | ||
+ | "instance_type": "m1.rd-tiny", | ||
+ | "modify_at": "2015-06-28T05:58:25Z", | ||
+ | "region": "LOCAL_DEV", | ||
+ | "created_at": "2015-06-28T05:54:52Z" | ||
+ | }, | ||
+ | "message_id": "0a567714-b244-4c36-903a-e0892fd3cd2c" | ||
} | } | ||
</pre> | </pre> | ||
Line 95: | Line 125: | ||
<pre>self.instance.send_usage_event('modify_flavor', instance_size=self.new_memory_size, launched_at=timeutils.isotime(), modify_at=timeutils.isotime())</pre> | <pre>self.instance.send_usage_event('modify_flavor', instance_size=self.new_memory_size, launched_at=timeutils.isotime(), modify_at=timeutils.isotime())</pre> | ||
− | + | Example Message: | |
<pre> | <pre> | ||
{ | { | ||
− | + | "priority": "INFO", | |
− | + | "event_type": "trove.instance.modify_flavor", | |
− | + | "timestamp": "2015-06-28 06:00:36.490285", | |
− | + | "publisher_id": "0.0.0.0", | |
− | + | "payload": { | |
− | + | "state_description": "ACTIVE", | |
− | + | "instance_type": "m1.rd-smaller", | |
− | + | "user_id": "dd2b7a976381419a93f3234050c07bd5", | |
− | + | "name": "test", | |
− | + | "availability_zone": "nova", | |
− | + | "tenant_id": "1bd558252da84dbf91bd50e379680b7a", | |
+ | "instance_size": 768, | ||
+ | "instance_id": "6a0541e4-807e-4e9f-8cc1-44e3a36a6e1c", | ||
+ | "instance_type_id": 8, | ||
+ | "launched_at": "2015-06-28T06:00:36Z", | ||
+ | "instance_name": "test", | ||
+ | "volume_size": 3, | ||
+ | "state": "ACTIVE", | ||
+ | "nova_instance_id": "FAKE_1f0be776-49e2-416b-aeeb-f101b5fa93b9", | ||
+ | "nova_volume_id": "FAKE_VOL_dedff250-e668-4720-a583-e38483200569", | ||
+ | "old_instance_size": 512, | ||
+ | "service_id": "123", | ||
+ | "created_at": "2015-06-28T05:54:52Z", | ||
+ | "modify_at": "2015-06-28T06:00:36Z", | ||
+ | "region": "LOCAL_DEV" | ||
+ | }, | ||
+ | "message_id": "9e6da3c3-006f-46c1-a5e0-7710a4826ff3" | ||
} | } | ||
</pre> | </pre> | ||
Line 119: | Line 165: | ||
<pre>self.send_usage_event('delete', deleted_at=timeutils.isotime())</pre> | <pre>self.send_usage_event('delete', deleted_at=timeutils.isotime())</pre> | ||
− | + | Example Message: | |
<pre> | <pre> | ||
{ | { | ||
− | + | "priority": "INFO", | |
− | + | "event_type": "trove.instance.delete", | |
− | + | "timestamp": "2015-06-28 06:01:59.848411", | |
− | + | "publisher_id": "0.0.0.0", | |
− | + | "payload": { | |
− | + | "state_description": "SHUTDOWN", | |
− | + | "instance_type": "m1.rd-smaller", | |
− | + | "user_id": "dd2b7a976381419a93f3234050c07bd5", | |
− | + | "name": "test", | |
− | + | "availability_zone": "nova", | |
− | + | "tenant_id": "1bd558252da84dbf91bd50e379680b7a", | |
+ | "instance_size": 768, | ||
+ | "instance_id": "6a0541e4-807e-4e9f-8cc1-44e3a36a6e1c", | ||
+ | "instance_type_id": 8, | ||
+ | "launched_at": "2015-06-28T05:54:52Z", | ||
+ | "instance_name": "test", | ||
+ | "volume_size": 3, | ||
+ | "state": "SHUTDOWN", | ||
+ | "nova_volume_id": "FAKE_VOL_dedff250-e668-4720-a583-e38483200569", | ||
+ | "nova_instance_id": "FAKE_1f0be776-49e2-416b-aeeb-f101b5fa93b9", | ||
+ | "service_id": "123", | ||
+ | "created_at": "2015-06-28T05:54:52Z", | ||
+ | "deleted_at": "2015-06-28T06:01:56Z", | ||
+ | "region": "LOCAL_DEV" | ||
+ | }, | ||
+ | "message_id": "682a9f7b-9723-41a9-a53f-7dbc8de4532a" | ||
} | } | ||
</pre> | </pre> | ||
Line 141: | Line 202: | ||
Exists Events are emitted periodically signifying that the resource exists. | Exists Events are emitted periodically signifying that the resource exists. | ||
− | + | Example Message: | |
<pre> | <pre> | ||
− | { | + | { |
− | + | "priority": "INFO", | |
− | + | "event_type": "trove.instance.exists", | |
− | + | "timestamp": "2015-07-10 20:05:29.989971", | |
− | + | "publisher_id": "taskmanager.0.0.0.0", | |
− | + | "payload": { | |
− | + | "state_description": "active", | |
− | + | "user_id": "12fd0c0eaf4b457eadbded348e7f4860", | |
− | + | "audit_period_beginning": "2015-07-10T20:05:29.870091Z", | |
− | + | "tenant_id": "ce60ec801f814906afab5e3b03d1ecee", | |
− | + | "created_at": "2015-06-29T20:52:12.000000", | |
+ | "instance_type_id": "7", | ||
+ | "launched_at": "2015-06-29T20:52:12.000000", | ||
+ | "instance_id": "75143330-ee41-47cb-aa39-fbdbb5a18190", | ||
+ | "instance_type": "m1.rd-tiny", | ||
+ | "state": "active", | ||
+ | "service_id": "2f3ff068-2bfb-4f70-9a9d-a6bb65bc084b", | ||
+ | "nova_instance_id": "1cf6ce1b-708b-4e6a-8ecf-2b60c8ccd435", | ||
+ | "display_name": "test", | ||
+ | "instance_name": "test", | ||
+ | "region": "LOCAL_DEV", | ||
+ | "audit_period_ending": "2015-07-10T21:05:29.870091Z" | ||
+ | }, | ||
+ | "message_id": "c0374eda-50d7-46d7-a4c4-502169025179" | ||
} | } | ||
</pre> | </pre> |
Latest revision as of 00:11, 12 July 2015
Contents
Trove Notifications
Trove will emit events for resources as they are manipulated. These events can be used to meter the service and possibly used to calculate bills.
Task Manager Events
Trove taskmanager is responsible for dispatching tasks and sending notification events. Here is a typical example:
from trove.openstack.common.notifier import api as notifier from trove.openstack.common import timeutils class NotifyMixin(object): """Notification Mixin This adds the ability to send usage events to an Instance object. """ def send_usage_event(self, event_type, **kwargs): event_type = 'trove.instance.%s' % event_type publisher_id = CONF.host # Grab the instance size from the kwargs or from the nova client instance_size = kwargs.pop('instance_size', None) if instance_size is None: flavor = self.nova_client.flavors.get(self.flavor_id) instance_size = flavor.ram # Default payload created_time = timeutils.isotime(self.db_info.created) payload = { 'instance_size': instance_size, 'tenant_id': self.tenant_id, 'instance_id': self.id, 'instance_name': self.name, 'created_at': created_time, 'launched_at': created_time, 'nova_instance_id': self.server_id, } if CONF.trove_volume_support: payload.update({ 'volume_size': self.volume_size, 'nova_volume_id': self.volume_id }) # Update payload with all other kwargs payload.update(kwargs) notifier.notify(self.context, publisher_id, event_type, 'INFO', payload)
Create Event
Create Events are emitted when a resource is created:
self.send_usage_event('create', instance_size=flavor_ram)
Example message:
{ "priority": "INFO", "event_type": "trove.instance.create", "timestamp": "2015-06-28 05:54:57.725572", "publisher_id": "0.0.0.0", "payload": { "state_description": "BUILD", "instance_type": "m1.rd-tiny", "user_id": "dd2b7a976381419a93f3234050c07bd5", "name": "test", "availability_zone": "nova", "tenant_id": "1bd558252da84dbf91bd50e379680b7a", "instance_size": 512, "instance_id": "6a0541e4-807e-4e9f-8cc1-44e3a36a6e1c", "instance_type_id": 10, "launched_at": "2015-06-28T05:54:52Z", "instance_name": "test", "volume_size": 1, "state": "BUILD", "nova_volume_id": "FAKE_VOL_dedff250-e668-4720-a583-e38483200569", "nova_instance_id": "FAKE_1f0be776-49e2-416b-aeeb-f101b5fa93b9", "service_id": "123", "created_at": "2015-06-28T05:54:52Z", "region": "LOCAL_DEV" }, "message_id": "7f8ff6b6-2f1f-40db-ae6f-c92cbc9e2827" }
Modify Volume Size
self.send_usage_event('modify_volume', launched_at=timeutils.isotime(), modify_at=timeutils.isotime(), volume_size=new_size)
Example Message:
{ "priority": "INFO", "event_type": "trove.instance.modify_volume", "timestamp": "2015-06-28 05:58:25.827067", "publisher_id": "0.0.0.0", "payload": { "state_description": "ACTIVE", "old_volume_size": 1, "user_id": "dd2b7a976381419a93f3234050c07bd5", "name": "test", "availability_zone": "nova", "tenant_id": "1bd558252da84dbf91bd50e379680b7a", "instance_size": 512, "instance_id": "6a0541e4-807e-4e9f-8cc1-44e3a36a6e1c", "instance_type_id": 10, "launched_at": "2015-06-28T05:58:25Z", "instance_name": "test", "volume_size": 3, "state": "ACTIVE", "nova_volume_id": "FAKE_VOL_dedff250-e668-4720-a583-e38483200569", "nova_instance_id": "FAKE_1f0be776-49e2-416b-aeeb-f101b5fa93b9", "service_id": "123", "instance_type": "m1.rd-tiny", "modify_at": "2015-06-28T05:58:25Z", "region": "LOCAL_DEV", "created_at": "2015-06-28T05:54:52Z" }, "message_id": "0a567714-b244-4c36-903a-e0892fd3cd2c" }
Modify Size (Resize)
self.instance.send_usage_event('modify_flavor', instance_size=self.new_memory_size, launched_at=timeutils.isotime(), modify_at=timeutils.isotime())
Example Message:
{ "priority": "INFO", "event_type": "trove.instance.modify_flavor", "timestamp": "2015-06-28 06:00:36.490285", "publisher_id": "0.0.0.0", "payload": { "state_description": "ACTIVE", "instance_type": "m1.rd-smaller", "user_id": "dd2b7a976381419a93f3234050c07bd5", "name": "test", "availability_zone": "nova", "tenant_id": "1bd558252da84dbf91bd50e379680b7a", "instance_size": 768, "instance_id": "6a0541e4-807e-4e9f-8cc1-44e3a36a6e1c", "instance_type_id": 8, "launched_at": "2015-06-28T06:00:36Z", "instance_name": "test", "volume_size": 3, "state": "ACTIVE", "nova_instance_id": "FAKE_1f0be776-49e2-416b-aeeb-f101b5fa93b9", "nova_volume_id": "FAKE_VOL_dedff250-e668-4720-a583-e38483200569", "old_instance_size": 512, "service_id": "123", "created_at": "2015-06-28T05:54:52Z", "modify_at": "2015-06-28T06:00:36Z", "region": "LOCAL_DEV" }, "message_id": "9e6da3c3-006f-46c1-a5e0-7710a4826ff3" }
Delete Event
Delete Events are emitted when a resource is deleted:
self.send_usage_event('delete', deleted_at=timeutils.isotime())
Example Message:
{ "priority": "INFO", "event_type": "trove.instance.delete", "timestamp": "2015-06-28 06:01:59.848411", "publisher_id": "0.0.0.0", "payload": { "state_description": "SHUTDOWN", "instance_type": "m1.rd-smaller", "user_id": "dd2b7a976381419a93f3234050c07bd5", "name": "test", "availability_zone": "nova", "tenant_id": "1bd558252da84dbf91bd50e379680b7a", "instance_size": 768, "instance_id": "6a0541e4-807e-4e9f-8cc1-44e3a36a6e1c", "instance_type_id": 8, "launched_at": "2015-06-28T05:54:52Z", "instance_name": "test", "volume_size": 3, "state": "SHUTDOWN", "nova_volume_id": "FAKE_VOL_dedff250-e668-4720-a583-e38483200569", "nova_instance_id": "FAKE_1f0be776-49e2-416b-aeeb-f101b5fa93b9", "service_id": "123", "created_at": "2015-06-28T05:54:52Z", "deleted_at": "2015-06-28T06:01:56Z", "region": "LOCAL_DEV" }, "message_id": "682a9f7b-9723-41a9-a53f-7dbc8de4532a" }
Exists Event
Exists Events are emitted periodically signifying that the resource exists.
Example Message:
{ "priority": "INFO", "event_type": "trove.instance.exists", "timestamp": "2015-07-10 20:05:29.989971", "publisher_id": "taskmanager.0.0.0.0", "payload": { "state_description": "active", "user_id": "12fd0c0eaf4b457eadbded348e7f4860", "audit_period_beginning": "2015-07-10T20:05:29.870091Z", "tenant_id": "ce60ec801f814906afab5e3b03d1ecee", "created_at": "2015-06-29T20:52:12.000000", "instance_type_id": "7", "launched_at": "2015-06-29T20:52:12.000000", "instance_id": "75143330-ee41-47cb-aa39-fbdbb5a18190", "instance_type": "m1.rd-tiny", "state": "active", "service_id": "2f3ff068-2bfb-4f70-9a9d-a6bb65bc084b", "nova_instance_id": "1cf6ce1b-708b-4e6a-8ecf-2b60c8ccd435", "display_name": "test", "instance_name": "test", "region": "LOCAL_DEV", "audit_period_ending": "2015-07-10T21:05:29.870091Z" }, "message_id": "c0374eda-50d7-46d7-a4c4-502169025179" }