once you dive into the notifier(2)

前面说到用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的配置

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, ... }}


如果使用了Ceilometer,那么Ceilometer会接收这些notifer发出的message,从log或者MQ中读取处理即可。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值