Fix path issue for devstack

Add collectd_ceilometer_plugin.py so collectd doesn't get confused
between module and file.

Change-Id: Icd63feafebc3e057e4e0cf9392237464b7c7a5f1
Co-Authored-By: Jaroslav Safka <jaroslavx.safka@intel.com>
This commit is contained in:
Emma Foley 2016-02-22 13:29:00 +00:00
parent 92331ba067
commit fe6d579a28
4 changed files with 91 additions and 3 deletions

View File

@ -14,6 +14,5 @@
"""Collectd Ceilometer plugin implementation"""
import pbr.version
__version__ = pbr.version.VersionInfo(
'collectd_ceilometer_plugin').version_string()

View File

@ -0,0 +1,88 @@
# -*- coding: utf-8 -*-
# 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.
"""Ceilometer collectd plugin"""
from __future__ import absolute_import
from __future__ import unicode_literals
# pylint: disable=import-error
import collectd
# pylint: enable=import-error
from collectd_ceilometer.logger import CollectdLogHandler
from collectd_ceilometer.meters import MeterStorage
from collectd_ceilometer.settings import Config
from collectd_ceilometer.writer import Writer
import logging
logging.getLogger().addHandler(CollectdLogHandler())
logging.getLogger().setLevel(logging.NOTSET)
LOGGER = logging.getLogger(__name__)
class Plugin(object):
"""Ceilometer plugin with collectd callbacks"""
# NOTE: this is multithreaded class
def __init__(self):
self._meters = None
self._writer = None
logging.getLogger("requests").setLevel(logging.WARNING)
def config(self, cfg):
"""Configuration callback
@param cfg configuration node provided by collectd
"""
# pylint: disable=no-self-use
Config.instance().read(cfg)
def init(self):
"""Initialization callback"""
collectd.info('Initializing the collectd OpenStack python plugin')
self._meters = MeterStorage()
self._writer = Writer(self._meters)
def write(self, vl, data=None):
"""Collectd write callback"""
# pylint: disable=broad-except
# pass arguments to the writer
try:
self._writer.write(vl, data)
except Exception as exc:
if collectd is not None:
collectd.error('Exception during write: %s' % exc)
def shutdown(self):
"""Shutdown callback"""
# pylint: disable=broad-except
collectd.info("SHUTDOWN")
try:
self._writer.flush()
except Exception as exc:
if collectd is not None:
collectd.error('Exception during shutdown: %s' % exc)
# The collectd plugin instance
# pylint: disable=invalid-name
instance = Plugin()
# pylint: enable=invalid-name
# Register plugin callbacks
collectd.register_init(instance.init)
collectd.register_config(instance.config)
collectd.register_write(instance.write)
collectd.register_shutdown(instance.shutdown)

View File

@ -35,9 +35,9 @@ cat << EOF | sudo tee /etc/collectd.d/collectd-ceilometer-plugin.conf
ModulePath "$COLLECTD_DIR"
LogTraces true
Interactive false
Import "collectd_ceilometer"
Import "collectd_ceilometer_plugin"
<Module collectd_ceilometer>
<Module collectd_ceilometer_plugin>
# Batch size
BATCH_SIZE 3

View File

@ -6,3 +6,4 @@ requests
libvirt-python
pbr>=1.6
Babel>=1.3
future