~ubuntu-branches/ubuntu/vivid/ceilometer/vivid

« back to all changes in this revision

Viewing changes to ceilometer/objectstore/notifications.py

  • Committer: Package Import Robot
  • Author(s): James Page, Corey Bryant, James Page
  • Date: 2015-02-19 14:59:07 UTC
  • mfrom: (1.2.3)
  • Revision ID: package-import@ubuntu.com-20150219145907-9jojybdsl64zcn14
Tags: 2015.1~b2-0ubuntu1
[ Corey Bryant ]
* New upstream release.
  - d/control: Align requirements with upstream.
  - d/p/skip-test.patch: Rebased.

[ James Page ]
* d/rules,d/p/skip-gabbi.patch: Skip tests that rely on python-gabbi until
  packaging and MIR is complete.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Copyright 2015 Red Hat. All Rights Reserved.
 
3
#
 
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
 
7
#
 
8
#      http://www.apache.org/licenses/LICENSE-2.0
 
9
#
 
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
 
14
# under the License.
 
15
 
 
16
import oslo.messaging
 
17
from oslo_config import cfg
 
18
 
 
19
from ceilometer.agent import plugin_base
 
20
from ceilometer import sample
 
21
 
 
22
OPTS = [
 
23
    cfg.StrOpt('swift_control_exchange',
 
24
               default='swift',
 
25
               help="Exchange name for Swift notifications."),
 
26
]
 
27
 
 
28
 
 
29
cfg.CONF.register_opts(OPTS)
 
30
 
 
31
 
 
32
class _Base(plugin_base.NotificationBase):
 
33
    """Convert objectstore notification into Samples."""
 
34
 
 
35
    @staticmethod
 
36
    def get_targets(conf):
 
37
        """Return a sequence of oslo.messaging.Target
 
38
 
 
39
        Sequence defining the exchange and topics to be connected for this
 
40
        plugin.
 
41
        """
 
42
        return [oslo.messaging.Target(topic=topic,
 
43
                                      exchange=conf.swift_control_exchange)
 
44
                for topic in conf.notification_topics]
 
45
 
 
46
 
 
47
class SwiftWsgiMiddleware(_Base):
 
48
 
 
49
    def event_types(self):
 
50
        return ['objectstore.http.request']
 
51
 
 
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'],
 
63
                    message=message)
 
64
        yield sample.Sample.from_notification(
 
65
            name='storage.api.request',
 
66
            type=sample.TYPE_DELTA,
 
67
            unit='request',
 
68
            volume=1,
 
69
            resource_id=message['payload']['target']['id'],
 
70
            user_id=message['payload']['initiator']['id'],
 
71
            project_id=message['payload']['initiator']['project_id'],
 
72
            message=message)