Create "central" agent

This changeset is phase one of changing the pollster API to support
polling individual instance resources. In this change, the single
compute agent is divided into two separate daemons.

The compute agent, for polling instance data, is still meant to
run on the compute server. The new "central" agent, for polling
resources not tied to a compute node, is meant to run on a management
server (probably the same place the collector runs). The configuration
of the pollsters is updated so that they are loaded by the
appropriate agent.

New base classes are introduced for each of the types of pollsters.
For now, the APIs remain the same.

The code implementing the agent and plugins has been moved around
to reflect the new logical relationships, and the documentation
is updated (including new installation instructions).

Change-Id: Ica6e947b2e457f7db6672147af1369a24066037d
Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
This commit is contained in:
Doug Hellmann 2012-07-30 12:44:16 -04:00
parent 2eebd4a8bd
commit 0e8f2359d9
22 changed files with 362 additions and 91 deletions

39
bin/ceilometer-agent-central Executable file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#
# Copyright © 2012 eNovance <licensing@enovance.com>
#
# Author: Julien Danjou <julien@danjou.info>
#
# 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 eventlet
eventlet.monkey_patch()
import sys
from ceilometer.service import prepare_service
from ceilometer.openstack.common import cfg
from nova import service
if __name__ == '__main__':
prepare_service(sys.argv)
server = \
service.Service.create(
binary='ceilometer-agent-central',
topic='ceilometer.agent.central',
manager='ceilometer.central.manager.AgentManager',
periodic_interval=cfg.CONF.periodic_interval)
service.serve(server)
service.wait()

View File

@ -36,9 +36,10 @@ if __name__ == '__main__':
prepare_service(sys.argv)
server = \
service.Service.create(binary='ceilometer-agent',
topic='ceilometer.agent',
manager='ceilometer.agent.manager.AgentManager',
periodic_interval=cfg.CONF.periodic_interval)
service.Service.create(
binary='ceilometer-agent-compute',
topic='ceilometer.agent.compute',
manager='ceilometer.compute.manager.AgentManager',
periodic_interval=cfg.CONF.periodic_interval)
service.serve(server)
service.wait()

View File

@ -0,0 +1,71 @@
# -*- encoding: utf-8 -*-
#
# Copyright © 2012 eNovance <licensing@enovance.com>
#
# Author: Julien Danjou <julien@danjou.info>
#
# 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 pkg_resources
from nova import manager
from ceilometer.openstack.common import log
from ceilometer import publish
LOG = log.getLogger(__name__)
PLUGIN_NAMESPACE = 'ceilometer.poll.central'
class AgentManager(manager.Manager):
def init_host(self):
self._load_plugins()
return
def _load_plugins(self):
self.pollsters = []
for ep in pkg_resources.iter_entry_points(PLUGIN_NAMESPACE):
try:
plugin_class = ep.load()
plugin = plugin_class()
# FIXME(dhellmann): Currently assumes all plugins are
# enabled when they are discovered and
# importable. Need to add check against global
# configuration flag and check that asks the plugin if
# it should be enabled.
self.pollsters.append((ep.name, plugin))
LOG.info('loaded pollster %s:%s',
PLUGIN_NAMESPACE, ep.name)
except Exception as err:
LOG.warning('Failed to load pollster %s:%s',
ep.name, err)
LOG.exception(err)
if not self.pollsters:
LOG.warning('Failed to load any pollsters for %s',
PLUGIN_NAMESPACE)
return
def periodic_tasks(self, context, raise_on_error=False):
"""Tasks to be run at a periodic interval."""
for name, pollster in self.pollsters:
try:
LOG.info('polling %s', name)
for c in pollster.get_counters(self, context):
LOG.info('COUNTER: %s', c)
publish.publish_counter(context, c)
except Exception as err:
LOG.warning('Continuing after error from %s: %s', name, err)
LOG.exception(err)

View File

@ -0,0 +1,25 @@
# -*- encoding: utf-8 -*-
#
# Copyright © 2012 New Dream Network, LLC (DreamHost)
#
# Author: Doug Hellmann <doug.hellmann@dreamhost.com>
#
# 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.
"""Base class for plugins used by the central agent.
"""
from ceilometer import plugin
class CentralPollster(plugin.PollsterBase):
"""Base class for plugins that support the polling API."""

View File

@ -21,7 +21,7 @@ from lxml import etree
from nova import flags
from ceilometer import counter
from ceilometer import plugin
from ceilometer.compute import plugin
from ceilometer.compute import instance as compute_instance
from ceilometer.openstack.common import importutils
from ceilometer.openstack.common import log
@ -61,7 +61,7 @@ def make_counter_from_instance(instance, name, type, volume):
)
class DiskIOPollster(plugin.PollsterBase):
class DiskIOPollster(plugin.ComputePollster):
LOG = log.getLogger(__name__ + '.diskio')
@ -111,7 +111,7 @@ class DiskIOPollster(plugin.PollsterBase):
)
class CPUPollster(plugin.PollsterBase):
class CPUPollster(plugin.ComputePollster):
LOG = log.getLogger(__name__ + '.cpu')

View File

@ -0,0 +1,35 @@
# -*- encoding: utf-8 -*-
#
# Copyright © 2012 New Dream Network, LLC (DreamHost)
#
# Author: Doug Hellmann <doug.hellmann@dreamhost.com>
#
# 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.
"""Base class for plugins used by the compute agent.
"""
import abc
from ceilometer import plugin
class ComputePollster(plugin.PollsterBase):
"""Base class for plugins that support the polling API on the
compute node."""
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def get_counters(self, manager, context):
"""Return a sequence of Counter instances from polling the
resources."""

View File

View File

@ -21,16 +21,16 @@ from nova import exception
from ceilometer.openstack.common import log
from ceilometer import counter
from ceilometer import plugin
from ceilometer.central import plugin
class FloatingIPPollster(plugin.PollsterBase):
class FloatingIPPollster(plugin.CentralPollster):
LOG = log.getLogger(__name__ + '.floatingip')
def get_counters(self, manager, context):
try:
ips = manager.db.floating_ip_get_all_by_host(context, manager.host)
ips = manager.db.floating_ip_get_all(context)
except exception.FloatingIpNotFoundForHost:
pass
else:
@ -44,7 +44,7 @@ class FloatingIPPollster(plugin.PollsterBase):
user_id=None,
project_id=ip.project_id,
resource_id=ip.id,
timestamp=None,
timestamp=None, # FIXME(dhellmann): This needs to be now()
duration=None,
resource_metadata={
'address': ip.address,

View File

@ -15,24 +15,29 @@ High Level Description
double: database; architecture
double: API; architecture
There are 4 basic components to the system:
There are 5 basic components to the system:
1. An :term:`agent` runs on each compute node and polls for resource
utilization statistics. There may be other types of agents in the
future, but for now we will focus on creating the compute agent.
1. An :term:`compute agent` runs on each compute node and polls for
resource utilization statistics. There may be other types of agents
in the future, but for now we will focus on creating the compute
agent.
2. The :term:`collector` runs on one or more central management
2. An :term:`central agent` runs on a central management server to
poll for resource utilization statistics for resources not tied
to instances or compute nodes.
3. The :term:`collector` runs on one or more central management
servers to monitor the message queues (for notifications and for
metering data coming from the agent). Notification messages are
processed and turned into metering messages and sent back out onto
the message bus using the appropriate topic. Metering messages are
written to the data store without modification.
3. The :term:`data store` is a database capable of handling concurrent
4. The :term:`data store` is a database capable of handling concurrent
writes (from one or more collector instances) and reads (from the
API server).
4. The :term:`API server` runs on one or more central management
5. The :term:`API server` runs on one or more central management
servers to provide access to the data from the data store. See
EfficientMetering#API for details.
@ -116,20 +121,17 @@ Metering data comes from two sources: through notifications built into
the existing OpenStack components and by polling the infrastructure
(such as via libvirt). Polling for compute resources is handled by an
agent running on the compute node (where communication with the
hypervisor is more efficient).
hypervisor is more efficient). The compute agent daemon is configured
to run one or more *pollster* plugins using the
``ceilometer.poll.compute`` namespace. Polling for resources not tied
to the compute node is handled by the central agent. The central
agent daemon is configured to run one or more *pollster* plugins using
the ``ceilometer.poll.central`` namespace.
.. note::
We only poll compute resources for now, but when other types of
polling are implemented the pollsters are likely to run somewhere
other than the compute node.
The agent daemon is configured to run one or more *pollster*
plugins using the ``ceilometer.poll.compute`` namespace. The agent
periodically asks each pollster for instances of ``Counter``
objects. The agent framework converts the Counters to metering
messages, which it then signs and transmits on the metering message
bus.
The agents periodically asks each pollster for instances of
``Counter`` objects. The agent framework converts the Counters to
metering messages, which it then signs and transmits on the metering
message bus.
The pollster plugins do not communicate with the message bus directly,
unless it is necessary to do so in order to collect the information

View File

@ -17,33 +17,43 @@
Writing Agent Plugins
=======================
This documentation gives you some clues on how to write a
new agent or plugin for Ceilometer a to use if you wish to instrument a
functionality which has not yet been covered by an existing one.
This documentation gives you some clues on how to write a new agent or
plugin for Ceilometer if you wish to instrument a measurement which
has not yet been covered by an existing plugin.
An agent runs on each compute node to poll for resource usage. Each metric
collected is tagged with the resource ID (such as an instance) and the owner,
including tenant and user IDs.The metrics are then reported to the collector
via the message bus. More detailed information follows.
Agents
======
Agent
=====
There is currently only one agent defined for Ceilometer which can be found at: ``ceilometer/agent/``
As you will see in the ``manager.py`` file, this agent will automatically load any
plugin defined in the namespace ``ceilometer.poll.compute``.
The compute agent runs on each compute node to poll for resource
usage. Each metric collected is tagged with the resource ID (such as
an instance) and the owner, including tenant and user IDs. The metrics
are then reported to the collector via the message bus. More detailed
information follows.
Agents are added by implementing a new nova.manager.Manager class, in the same
way it was done for the AgentManager for the compute agent in the file
``ceilometer/agent/manager.py``.
The compute agent is implemented in ``bin/ceilometer-agent-compute``
and ``ceilometer/compute/manager.py``. As you will see in the manager,
the computeagent loads all plugins defined in the namespace
``ceilometer.poll.compute``, then periodically calls their
:func:`get_counters` method.
The central agent polls other types of resources from a management
server. The central agent is defined in
``bin/ceilometer-agent-central`` and
``ceilometer/central/manager.py``. It loads plugins from the
``ceilometer.poll.central`` namespace and polls them by calling their
:func:`get_counters` method.
Plugins
=======
An agent can support multiple plugins to retrieve different information and
send them to the collector. As stated above, an agent will automatically
activate all plugins of a given class. For example, the compute agent will
load all plugins of class ``ceilometer.poll.compute``. This will load, among
others, the ceilometer.compute.libvirt.CPUPollster, which is defined in the
file ``ceilometer/compute/libvirt.py`` as well as the ceilometer.compute.notifications.InstanceNotifications plugin
An agent can support multiple plugins to retrieve different
information and send them to the collector. As stated above, an agent
will automatically activate all plugins of a given class. For example,
the compute agent will load all plugins of class
``ceilometer.poll.compute``. This will load, among others, the
:class:`ceilometer.compute.libvirt.CPUPollster`, which is defined in
the file ``ceilometer/compute/libvirt.py`` as well as the
:class:`ceilometer.compute.notifications.InstanceNotifications` plugin
which is defined in the file ``ceilometer/compute/notifications.py``
We are using these two existing plugins as examples as the first one provides
@ -53,10 +63,13 @@ an existing event notification on the standard OpenStack queue to ceilometer.
Pollster
--------
Pollsters are defined as subclasses of the ``ceilometer.plugin.PollsterBase`` meta
class as defined in the ``ceilometer/plugin.py`` file. Pollsters must implement
one method: ``get_counters(self, manager, context)``, which returns a
a sequence of ``Counter`` objects as defined in the ``ceilometer/counter.py`` file.
Compute plugins are defined as subclasses of the
:class:`ceilometer.compute.plugin.ComputePollster` class as defined in
the ``ceilometer/compute/plugin.py`` file. Pollsters must implement one
method: ``get_counters(self, manager, context)``, which returns a
sequence of ``Counter`` objects as defined in the
``ceilometer/counter.py`` file.
In the ``CPUPollster`` plugin, the ``get_counters`` method is implemented as a loop
which, for each instances running on the local host, retrieves the cpu_time
@ -74,9 +87,11 @@ participate in the actual metering activity.
Notifications
-------------
Notifications are defined as subclass of the ``ceilometer.plugin.NotificationBase``
meta class as defined in the ``ceilometer/plugin.py`` file. Notifications must
implement two methods:
Notifications are defined as subclass of the
:class:`ceilometer.plugin.NotificationBase` meta class as defined in
the ``ceilometer/plugin.py`` file. Notifications must implement two
methods:
``get_event_types(self)`` which should return a sequence of strings defining the event types to be given to the plugin and

View File

@ -32,12 +32,22 @@
A ceilometer is a device that uses a laser or other light
source to determine the height of a cloud base.
central agent
Software service running on a central management node within the
OpenStack infrastructure measuring usage and sending the results
to the :term:`collector`.
collector
Software service running on the OpenStack infrastructure
monitoring notifications from other OpenStack components and
meter events from the ceilometer agent and recording the results
in the database.
compute agent
Software service running on a compute node within the OpenStack
infrastructure measuring usage and sending the results to the
:term:`collector`.
data store
Storage system for recording data collected by ceilometer.

View File

@ -19,12 +19,13 @@
Installing and Running the Development Version
================================================
Ceilometer has three daemons. The :term:`agent` runs on the Nova
compute node(s). The :term:`collector` and API server run on the
cloud's management node(s). In a development environment created by
devstack_, these two are typically the same server. They do not have
to be, though, so some of the instructions below are duplicated. Skip
the steps you have already done.
Ceilometer has three daemons. The :term:`compute agent` runs on the
Nova compute node(s) while the :term:`central agent` and
:term:`collector` run on the cloud's management node(s). In a
development environment created by devstack_, these two are typically
the same server. They do not have to be, though, so some of the
instructions below are duplicated. Skip the steps you have already
done.
.. _devstack: http://www.devstack.org/
@ -90,17 +91,15 @@ Installing the Collector
.. _MongoDB: http://www.mongodb.org/
Installing the Compute Agent
Installing the Central Agent
============================
.. index::
double: installing; compute agent
.. note:: The compute agent must be installed on each nova compute node.
double: installing; central agent
1. Install and configure nova.
The collector daemon imports code from ``nova``, so it needs to be
The agent daemon imports code from ``nova``, so it needs to be
run on a server where nova has already been installed.
.. note::
@ -124,11 +123,11 @@ Installing the Compute Agent
Ceilometer needs to know about some of the nova configuration
options, so the simplest way to start is copying
``/etc/nova/nova.conf`` to ``/etc/ceilometer-agent.conf``. Some
``/etc/nova/nova.conf`` to ``/etc/ceilometer-agent-central.conf``. Some
of the logging settings used in nova break ceilometer, so they need
to be removed. For example, as a user with ``root`` permissions::
$ grep -v format_string /etc/nova/nova.conf > /etc/ceilometer-agent.conf
$ grep -v format_string /etc/nova/nova.conf > /etc/ceilometer-agent-central.conf
Refer to :doc:`configuration` for details about any other options
you might want to modify before starting the service.
@ -137,7 +136,7 @@ Installing the Compute Agent
::
$ ./bin/ceilometer-agent
$ ./bin/ceilometer-agent-central
.. note::
@ -147,6 +146,63 @@ Installing the Compute Agent
background.
Installing the Compute Agent
============================
.. index::
double: installing; compute agent
.. note:: The compute agent must be installed on each nova compute node.
1. Install and configure nova.
The agent daemon imports code from ``nova``, so it needs to be
run on a server where nova has already been installed.
.. note::
Ceilometer makes extensive use of the messaging bus, but has not
yet been tested with ZeroMQ. We recommend using Rabbit or qpid
for now.
2. Clone the ceilometer git repository to the server::
$ cd /opt/stack
$ git clone https://github.com/stackforge/ceilometer.git
4. As a user with ``root`` permissions or ``sudo`` privileges, run the
ceilometer installer::
$ cd ceilometer
$ sudo python setup.py install
5. Configure ceilometer.
Ceilometer needs to know about some of the nova configuration
options, so the simplest way to start is copying
``/etc/nova/nova.conf`` to ``/etc/ceilometer-agent-compute.conf``. Some
of the logging settings used in nova break ceilometer, so they need
to be removed. For example, as a user with ``root`` permissions::
$ grep -v format_string /etc/nova/nova.conf > /etc/ceilometer-agent-compute.conf
Refer to :doc:`configuration` for details about any other options
you might want to modify before starting the service.
6. Start the agent.
::
$ ./bin/ceilometer-agent-compute
.. note::
The default development configuration of the agent logs to
stderr, so you may want to run this step using a screen session
or other tool for maintaining a long-running program in the
background.
Installing the API Server
=========================

View File

@ -31,7 +31,9 @@ setuptools.setup(
packages=setuptools.find_packages(exclude=['bin']),
include_package_data=True,
test_suite='nose.collector',
scripts=['bin/ceilometer-agent', 'bin/ceilometer-collector'],
scripts=['bin/ceilometer-agent-compute',
'bin/ceilometer-agent-central',
'bin/ceilometer-collector'],
py_modules=[],
entry_points=textwrap.dedent("""
[ceilometer.collector.compute]
@ -40,7 +42,9 @@ setuptools.setup(
[ceilometer.poll.compute]
libvirt_diskio = ceilometer.compute.libvirt:DiskIOPollster
libvirt_cpu = ceilometer.compute.libvirt:CPUPollster
network_floatingip = ceilometer.compute.network:FloatingIPPollster
[ceilometer.poll.central]
network_floatingip = ceilometer.network.floatingip:FloatingIPPollster
[ceilometer.storage]
log = ceilometer.storage.impl_log:LogStorage

View File

@ -0,0 +1 @@
from nova.tests import *

View File

@ -19,12 +19,11 @@
"""
from nova import context
from nova import flags
from nova import test
from nova import db
from ceilometer.compute import instance
from ceilometer.agent import manager
from ceilometer.compute import manager
class TestLocationMetadata(test.TestCase):
@ -49,7 +48,8 @@ class TestLocationMetadata(test.TestCase):
self.context = context.RequestContext('admin', 'admin', is_admin=True)
self.manager = manager.AgentManager()
super(TestLocationMetadata, self).setUp()
self.instance = db.instance_create(self.context, self.INSTANCE_PROPERTIES)
self.instance = db.instance_create(self.context,
self.INSTANCE_PROPERTIES)
def test_metadata(self):
md = instance.get_metadata_from_dbobject(self.instance)

View File

@ -20,7 +20,7 @@
"""
try:
import libvirt
import libvirt as ignored_libvirt
except ImportError:
libvirt_missing = True
else:
@ -32,7 +32,7 @@ from nova import test
from nova import db
from ceilometer.compute import libvirt
from ceilometer.agent import manager
from ceilometer.compute import manager
class TestDiskIOPollster(test.TestCase):

View File

@ -23,7 +23,7 @@ import datetime
from nova import context
from nova import test
from ceilometer.agent import manager
from ceilometer.compute import manager
from ceilometer import counter
from ceilometer import publish

View File

@ -18,11 +18,12 @@
# under the License.
from nova import context
from nova import test
from nova import db
from nova import exception
from nova import test
from ceilometer.compute import network
from ceilometer.agent import manager
from ceilometer.network import floatingip
from ceilometer.central import manager
class TestFloatingIPPollster(test.TestCase):
@ -30,13 +31,18 @@ class TestFloatingIPPollster(test.TestCase):
def setUp(self):
self.context = context.RequestContext('admin', 'admin', is_admin=True)
self.manager = manager.AgentManager()
self.pollster = network.FloatingIPPollster()
self.pollster = floatingip.FloatingIPPollster()
super(TestFloatingIPPollster, self).setUp()
def test_get_counters(self):
self.assertEqual(list(self.pollster.get_counters(self.manager,
self.context)),
[])
try:
list(self.pollster.get_counters(self.manager,
self.context)
)
except exception.NoFloatingIpsDefined:
pass
else:
assert False, 'Should have seen an error'
def test_get_counters_not_empty(self):
db.floating_ip_create(self.context,
@ -52,5 +58,11 @@ class TestFloatingIPPollster(test.TestCase):
'host': self.manager.host + "randomstring",
})
counters = list(self.pollster.get_counters(self.manager, self.context))
self.assertEqual(len(counters), 1)
self.assertEqual(counters[0].resource_metadata['address'], '1.1.1.1')
self.assertEqual(len(counters), 3)
addresses = [c.resource_metadata['address']
for c in counters
]
self.assertEqual(addresses, ['1.1.1.1',
'1.1.1.2',
'1.1.1.3',
])

View File

@ -18,7 +18,7 @@ commands = {toxinidir}/run_tests.sh --no-path-adjustment --with-coverage --cover
[testenv:pep8]
deps = pep8==1.1
commands = pep8 --repeat --show-source ceilometer setup.py bin/ceilometer-agent bin/ceilometer-collector
commands = pep8 --repeat --show-source ceilometer setup.py bin/ceilometer-agent-central bin/ceilometer-agent-compute bin/ceilometer-collector
[testenv:py26-essex]
deps = -r{toxinidir}/tools/pip-requires_essex