openstack监控扩展

openstack监控扩展

简介

openstack监控扩展

  • 在compute节点通过polister轮询获取instance的监控数据,并通过publisher调用了RPC发送监控数据到消息队列;
  • collect从消息队列中匹配接受数据,并调用storage接口进行存储;

扩展

添加一个ceilometer-agent-compute监控项
mem.max

/usr/lib/python2.7/site-packages/ceilometer-2014.2-py2.7.egg-info/entry_points.txt

[ceilometer.poll.compute]
...
mem.max = ceilometer.compute.pollsters.mem:MaxMemPollster

ceilometer/compute/pollsters/mem.py

import ceilometer
from ceilometer.compute import plugin
from ceilometer.compute.pollsters import util
from ceilometer.compute.virt import inspector as virt_inspector
from ceilometer.openstack.common.gettextutils import _
from ceilometer.openstack.common import log
from ceilometer import sample

LOG = log.getLogger(__name__)

class MaxMemPollster(plugin.ComputePollster):
    def get_samples(self, manager, cache, resources):
        for instance in resources:
            LOG.debug(_('checking instance %s'), instance.id)
            instance_name = util.instance_name(instance)
            try:
                mem_info = manager.inspector.inspect_mems(instance_name)
                LOG.debug(_("mem.max: %(instance)s %(max)d"),
                          {'instance': instance.__dict__,
                           'max': mem_info.max})
                yield util.make_sample_from_instance(
                    instance,
                    name='mem.max',
                    type=sample.TYPE_GAUGE,
                    unit='MB',
                    volume=mem_info.max,
                )
            except virt_inspector.InstanceNotFoundException as err:
                # Instance was deleted while getting samples. Ignore it.
                LOG.debug(_('Exception while getting samples %s'), err)
            except ceilometer.NotImplementedError:
                # Selected inspector does not implement this pollster.
                LOG.debug(_('Obtaining mem is not implemented for %s'
                            ), manager.inspector.__class__.__name__)
            except Exception as err:
                LOG.exception(_('could not get mem for %(id)s: %(e)s'),
                              {'id': instance.id, 'e': err})

ceilometer/compute/virt/inspector.py

class Inspector(object):
	...
    def inspect_mems(self,instance,duration=None):
        raise ceilometer.NotImplementedError
MaxMem = collections.namedtuple('MaxMem', ['max'])

ceilometer/compute/virt/libvirt/inspector.py

class LibvirtInspector(virt_inspector.Inspector):
    def inspect_mems(self, instance_name):
        domain = self._lookup_by_name(instance_name)
        maxMem = domain.maxMemory()
        return virt_inspector.MaxMem(max=maxMem,)

重启服务即有新的收集数据了
ceilometer sample-list -m maxMem -q resource_id=9af11e66-30ef-42cf-8f48-bc4bfb03cc03

你可能感兴趣的:(openstack)