2
# Copyright 2015 Red Hat. All Rights Reserved.
4
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5
# not use this file except in compliance with the License. You may obtain
6
# a copy of the License at
8
# http://www.apache.org/licenses/LICENSE-2.0
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
# License for the specific language governing permissions and limitations
17
from oslo_config import cfg
19
from ceilometer.agent import plugin_base
20
from ceilometer import sample
23
cfg.StrOpt('swift_control_exchange',
25
help="Exchange name for Swift notifications."),
29
cfg.CONF.register_opts(OPTS)
32
class _Base(plugin_base.NotificationBase):
33
"""Convert objectstore notification into Samples."""
36
def get_targets(conf):
37
"""Return a sequence of oslo.messaging.Target
39
Sequence defining the exchange and topics to be connected for this
42
return [oslo.messaging.Target(topic=topic,
43
exchange=conf.swift_control_exchange)
44
for topic in conf.notification_topics]
47
class SwiftWsgiMiddleware(_Base):
49
def event_types(self):
50
return ['objectstore.http.request']
52
def process_notification(self, message):
53
if message['payload']['measurements']:
54
for meter in message['payload']['measurements']:
55
yield sample.Sample.from_notification(
56
name=meter['metric']['name'],
57
type=sample.TYPE_DELTA,
58
unit=meter['metric']['unit'],
59
volume=meter['result'],
60
resource_id=message['payload']['target']['id'],
61
user_id=message['payload']['initiator']['id'],
62
project_id=message['payload']['initiator']['project_id'],
64
yield sample.Sample.from_notification(
65
name='storage.api.request',
66
type=sample.TYPE_DELTA,
69
resource_id=message['payload']['target']['id'],
70
user_id=message['payload']['initiator']['id'],
71
project_id=message['payload']['initiator']['project_id'],