a49e59b115
Change-Id: Iba7df922a7d6b3eec7db427b4135e6fa2ad2d416 Signed-off-by: Julien Danjou <julien.danjou@enovance.com>
86 lines
3.1 KiB
Python
86 lines
3.1 KiB
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 pkg_resources
|
|
|
|
from nova import log as logging
|
|
from nova import manager
|
|
from nova import rpc
|
|
|
|
from ceilometer import meter
|
|
from ceilometer import cfg
|
|
|
|
|
|
# FIXME(dhellmann): We need to have the main program set up logging
|
|
# correctly so messages from modules outside of the nova package
|
|
# appear in the output.
|
|
LOG = logging.getLogger('nova.' + __name__)
|
|
|
|
COMPUTE_PLUGIN_NAMESPACE = 'ceilometer.poll.compute'
|
|
|
|
|
|
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(COMPUTE_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',
|
|
COMPUTE_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',
|
|
COMPUTE_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)
|
|
msg = {
|
|
'method': 'record_metering_data',
|
|
'version': '1.0',
|
|
'args': {'data': meter.meter_message_from_counter(c),
|
|
},
|
|
}
|
|
rpc.cast(context, cfg.CONF.metering_topic, msg)
|
|
rpc.cast(context,
|
|
cfg.CONF.metering_topic + '.' + c.type,
|
|
msg)
|
|
except Exception as err:
|
|
LOG.warning('Continuing after error from %s: %s', name, err)
|
|
LOG.exception(err)
|