aodh/ceilometer/objectstore/notifications.py
gordon chung d2af9a72d5 add listener to pick up notification from ceilometermiddleware
this patch add listener to create sample/events from new
ceilometermiddleware event.

Change-Id: Ie770e58b3b9643d07f14cec350235356a0b07b34
Implements: blueprint ceilometermiddleware
2015-02-03 07:49:05 -05:00

73 lines
2.5 KiB
Python

#
# Copyright 2015 Red Hat. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import oslo.messaging
from oslo_config import cfg
from ceilometer.agent import plugin_base
from ceilometer import sample
OPTS = [
cfg.StrOpt('swift_control_exchange',
default='swift',
help="Exchange name for Swift notifications."),
]
cfg.CONF.register_opts(OPTS)
class _Base(plugin_base.NotificationBase):
"""Convert objectstore notification into Samples."""
@staticmethod
def get_targets(conf):
"""Return a sequence of oslo.messaging.Target
Sequence defining the exchange and topics to be connected for this
plugin.
"""
return [oslo.messaging.Target(topic=topic,
exchange=conf.swift_control_exchange)
for topic in conf.notification_topics]
class SwiftWsgiMiddleware(_Base):
def event_types(self):
return ['objectstore.http.request']
def process_notification(self, message):
if message['payload']['measurements']:
for meter in message['payload']['measurements']:
yield sample.Sample.from_notification(
name=meter['metric']['name'],
type=sample.TYPE_DELTA,
unit=meter['metric']['unit'],
volume=meter['result'],
resource_id=message['payload']['target']['id'],
user_id=message['payload']['initiator']['id'],
project_id=message['payload']['initiator']['project_id'],
message=message)
yield sample.Sample.from_notification(
name='storage.api.request',
type=sample.TYPE_DELTA,
unit='request',
volume=1,
resource_id=message['payload']['target']['id'],
user_id=message['payload']['initiator']['id'],
project_id=message['payload']['initiator']['project_id'],
message=message)