前面说到用MQ做解耦,为系统扩展性提供了很好的方式,如果仔细看source code可以看到:
NOTIFIER = messaging.Notifier(TRANSPORT, serializer=serializer)
def get_notifier(service=None, host=None, publisher_id=None):
assert NOTIFIER is not None
if not publisher_id:
publisher_id = "%s.%s" % (service, host or cfg.CONF.host)
return NOTIFIER.prepare(publisher_id=publisher_id)
还有self.notifier = rpc.get_notifier('compute', CONF.host) #除了compute,还有scheduler,api 等等
从系统设计角度,MQ作为进程间通信的方式,我们除了使用log将通信过程的情况记录下来,为了窥探系统的运行状况,做了哪些事情,
这时,有个openstack的module叫ceilometer,也叫计量模块或者计费模块。
如果没有agent,怎么做到呢,不错,使用notifier就可以。
前面也提过这个链接,可以温习一下:http://www.cnblogs.com/sammyliu/p/4384470.html
如果trace进入源码:在/usr/lib/python2.7/site-packages/oslo/messaging/notify中的类Notifier:
transport.conf.register_opts(_notifier_opts)
self.transport = transport
self.publisher_id = publisher_id
self.retry = retry
self._driver_names = ([driver] if driver is not None
else transport.conf.notification_driver)
self._topics = ([topic] if topic is not None
else transport.conf.notification_topics)
self._serializer = serializer or msg_serializer.NoOpSerializer()
self._driver_mgr = named.NamedExtensionManager(
'oslo.messaging.notify.drivers',
看起来和MQ需要的参数很像,但是侧重点不一样,或者说使用目的不一样
notifier_opts = [
cfg.MultiStrOpt('notification_driver',
default=[],
help='Driver or drivers to handle sending notifications.'),
cfg.ListOpt('notification_topics',
default=['notifications', ],
deprecated_name='topics',
deprecated_group='rpc_notifier2',
help='AMQP topic used for OpenStack notifications.'),
]
在/etc/nova/nova.conf中我们可以看到关于notification_driver和notification_topics的配置
oslo.messaging.notify.drivers =
nova.openstack.common.notifier.log_notifier = oslo.messaging.notify._impl_log:LogDriver
nova.openstack.common.notifier.no_op_notifier = oslo.messaging.notify._impl_noop:NoOpDriver
nova.openstack.common.notifier.rpc_notifier2 = oslo.messaging.notify._impl_messaging:MessagingV2Driver
nova.openstack.common.notifier.rpc_notifier = oslo.messaging.notify._impl_messaging:MessagingDriver
nova.openstack.common.notifier.test_notifier = oslo.messaging.notify._impl_test:TestDriver
而Notifier类中会指明使用什么类型的driver,不同driver表现出不同的notify能力,常用的是LogDriver和MessagingDriver,分别是将
notify的信息写入log和通过rpc发出去。
notifier发送消息时的结构一般为,在Notifier类中可以看到:
{'message_id': six.text_type(uuid.uuid4()),
'publisher_id': 'compute.host1',
'timestamp': timeutils.utcnow(),
'priority': 'WARN',
'event_type': 'compute.create_instance',
NOTIFIER = messaging.Notifier(TRANSPORT, serializer=serializer)
def get_notifier(service=None, host=None, publisher_id=None):
assert NOTIFIER is not None
if not publisher_id:
publisher_id = "%s.%s" % (service, host or cfg.CONF.host)
return NOTIFIER.prepare(publisher_id=publisher_id)
还有self.notifier = rpc.get_notifier('compute', CONF.host) #除了compute,还有scheduler,api 等等
从系统设计角度,MQ作为进程间通信的方式,我们除了使用log将通信过程的情况记录下来,为了窥探系统的运行状况,做了哪些事情,
这时,有个openstack的module叫ceilometer,也叫计量模块或者计费模块。
如果没有agent,怎么做到呢,不错,使用notifier就可以。
前面也提过这个链接,可以温习一下:http://www.cnblogs.com/sammyliu/p/4384470.html
如果trace进入源码:在/usr/lib/python2.7/site-packages/oslo/messaging/notify中的类Notifier:
transport.conf.register_opts(_notifier_opts)
self.transport = transport
self.publisher_id = publisher_id
self.retry = retry
self._driver_names = ([driver] if driver is not None
else transport.conf.notification_driver)
self._topics = ([topic] if topic is not None
else transport.conf.notification_topics)
self._serializer = serializer or msg_serializer.NoOpSerializer()
self._driver_mgr = named.NamedExtensionManager(
'oslo.messaging.notify.drivers',
看起来和MQ需要的参数很像,但是侧重点不一样,或者说使用目的不一样
notifier_opts = [
cfg.MultiStrOpt('notification_driver',
default=[],
help='Driver or drivers to handle sending notifications.'),
cfg.ListOpt('notification_topics',
default=['notifications', ],
deprecated_name='topics',
deprecated_group='rpc_notifier2',
help='AMQP topic used for OpenStack notifications.'),
]
在/etc/nova/nova.conf中我们可以看到关于notification_driver和notification_topics的配置
notification_driver=ceilometer.compute.nova_notifier
notification_driver=nova.openstack.common.notifier.rpc_notifier
oslo.messaging.notify.drivers =
nova.openstack.common.notifier.log_notifier = oslo.messaging.notify._impl_log:LogDriver
nova.openstack.common.notifier.no_op_notifier = oslo.messaging.notify._impl_noop:NoOpDriver
nova.openstack.common.notifier.rpc_notifier2 = oslo.messaging.notify._impl_messaging:MessagingV2Driver
nova.openstack.common.notifier.rpc_notifier = oslo.messaging.notify._impl_messaging:MessagingDriver
nova.openstack.common.notifier.test_notifier = oslo.messaging.notify._impl_test:TestDriver
而Notifier类中会指明使用什么类型的driver,不同driver表现出不同的notify能力,常用的是LogDriver和MessagingDriver,分别是将
notify的信息写入log和通过rpc发出去。
notifier发送消息时的结构一般为,在Notifier类中可以看到:
{'message_id': six.text_type(uuid.uuid4()),
'publisher_id': 'compute.host1',
'timestamp': timeutils.utcnow(),
'priority': 'WARN',
'event_type': 'compute.create_instance',
'payload': {'instance_id': 12, ... }}