Debian Codegraph @

doc/source/contributor/plugins.rst

raw
1 ..
2 Copyright 2012 Nicolas Barcet for Canonical
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 =====================
17 Writing Agent Plugins
18 =====================
19
20 This documentation gives you some clues on how to write a new agent or
21 plugin for Ceilometer if you wish to instrument a measurement which
22 has not yet been covered by an existing plugin.
23
24 Plugin Framework
25 ================
26
27 Although we have described a list of the meters Ceilometer should
28 collect, we cannot predict all of the ways deployers will want to
29 measure the resources their customers use. This means that Ceilometer
30 needs to be easy to extend and configure so it can be tuned for each
31 installation. A plugin system based on `setuptools entry points`_
32 makes it easy to add new monitors in the agents. In particular,
33 Ceilometer now uses Stevedore_, and you should put your entry point
34 definitions in the :file:`entry_points.txt` file of your Ceilometer egg.
35
36 .. _setuptools entry points: http://setuptools.readthedocs.io/en/latest/setuptools.html#dynamic-discovery-of-services-and-plugins
37
38 .. _Stevedore: https://docs.openstack.org/stevedore/latest/
39
40 Installing a plugin automatically activates it the next time the
41 ceilometer daemon starts. Rather than running and reporting errors or
42 simply consuming cycles for no-ops, plugins may disable themselves at
43 runtime based on configuration settings defined by other components (for
44 example, the plugin for polling libvirt does not run if it sees that the system
45 is configured using some other virtualization tool). Additionally, if no
46 valid resources can be discovered the plugin will be disabled.
47
48 Polling Agents
49 ==============
50
51 The polling agent is implemented in :file:`ceilometer/polling/manager.py`. As
52 you will see in the manager, the agent loads all plugins defined in
53 the ``ceilometer.poll.*`` and ``ceilometer.builder.poll.*`` namespaces, then
54 periodically calls their :func:`get_samples` method.
55
56 Currently we keep separate namespaces - ``ceilometer.poll.compute``
57 and ``ceilometer.poll.central`` for quick separation of what to poll depending
58 on where is polling agent running. For example, this will load, among others,
59 the :class:`ceilometer.compute.pollsters.instance_stats.CPUPollster`
60
61 Pollster
62 --------
63
64 All pollsters are subclasses of
65 :class:`ceilometer.polling.plugin_base.PollsterBase` class. Pollsters must
66 implement one method: ``get_samples(self, manager, cache, resources)``, which
67 returns a sequence of ``Sample`` objects as defined in the
68 :file:`ceilometer/sample.py` file.
69
70 Compute plugins are defined as subclasses of the
71 :class:`ceilometer.compute.pollsters.GenericComputePollster` class as defined
72 in the :file:`ceilometer/compute/pollsters/__init__.py` file.
73
74 For example, in the ``CPUPollster`` plugin, the ``get_samples`` method takes
75 in a given list of resources representing instances on the local host, loops
76 through them and retrieves the `cpu time` details from resource. Similarly,
77 other metrics are built by pulling the appropriate value from the given list
78 of resources.
79
80 Notifications
81 =============
82
83 Notifications in OpenStack are consumed by the notification agent and passed
84 through `pipelines` to be normalised and re-published to specified targets.
85
86 The existing normalisation pipelines are defined in the namespace
87 ``ceilometer.notification.pipeline``.
88
89 Each normalisation pipeline are defined as subclass of
90 :class:`ceilometer.pipeline.base.PipelineManager` which interprets and builds
91 pipelines based on a given configuration file. Pipelines are required to define
92 `Source` and `Sink` permutations to describe how to process notification.
93 Additionally, it must set ``get_main_endpoints`` which provides endpoints to be
94 added to the main queue listener in the notification agent. This main queue
95 endpoint inherits :class:`ceilometer.pipeline.base.NotificationEndpoint`
96 and defines which notification priorities to listen, normalises the data,
97 and redirects the data for pipeline processing.
98
99 Notification endpoints should implement:
100
101 ``event_types``
102 A sequence of strings defining the event types the endpoint should handle
103
104 ``process_notifications(self, priority, notifications)``
105 Receives an event message from the list provided to ``event_types`` and
106 returns a sequence of objects. Using the SampleEndpoint, it should yield
107 ``Sample`` objects as defined in the :file:`ceilometer/sample.py` file.
108
109 Two pipeline configurations exist and can be found under
110 ``ceilometer.pipeline.*``. The `sample` pipeline loads in multiple endpoints
111 defined in ``ceilometer.sample.endpoint`` namespace. Each of the endpoints
112 normalises a given notification into different samples.