diff --git a/ceilometer/compute/libvirt.py b/ceilometer/compute/libvirt.py index 0defdcaf3..fd198844b 100644 --- a/ceilometer/compute/libvirt.py +++ b/ceilometer/compute/libvirt.py @@ -79,6 +79,16 @@ def make_vnic_counter(instance, name, type, volume, vnic_data): ) +class InstancePollster(plugin.ComputePollster): + + def get_counters(self, manager, instance): + yield make_counter_from_instance(instance, + name='instance', + type=counter.TYPE_CUMULATIVE, + volume=1, + ) + + class DiskIOPollster(plugin.ComputePollster): LOG = log.getLogger(__name__ + '.diskio') @@ -150,11 +160,6 @@ class CPUPollster(plugin.ComputePollster): type=counter.TYPE_CUMULATIVE, volume=cpu_info['cpu_time'], ) - yield make_counter_from_instance(instance, - name='instance', - type=counter.TYPE_CUMULATIVE, - volume=1, - ) except Exception as err: self.LOG.error('could not get CPU time for %s: %s', instance.uuid, err) diff --git a/setup.py b/setup.py index 92881f33a..b918d8c72 100755 --- a/setup.py +++ b/setup.py @@ -65,6 +65,7 @@ setuptools.setup( libvirt_diskio = ceilometer.compute.libvirt:DiskIOPollster libvirt_cpu = ceilometer.compute.libvirt:CPUPollster libvirt_net = ceilometer.compute.libvirt:NetPollster + libvirt_instance = ceilometer.compute.libvirt:InstancePollster [ceilometer.poll.central] network_floatingip = ceilometer.network.floatingip:FloatingIPPollster diff --git a/tests/compute/test_libvirt.py b/tests/compute/test_libvirt.py index 1205c0f9f..d91f6705c 100644 --- a/tests/compute/test_libvirt.py +++ b/tests/compute/test_libvirt.py @@ -41,6 +41,23 @@ import mox import re +class TestInstancePollster(unittest.TestCase): + + @skip.skip_if(libvirt_missing, 'Test requires libvirt') + def setUp(self): + self.manager = manager.AgentManager() + self.pollster = libvirt.InstancePollster() + super(TestInstancePollster, self).setUp() + self.instance = mock.MagicMock() + self.instance.name = 'instance-00000001' + self.instance.id = 1 + flags.FLAGS.compute_driver = 'libvirt.LibvirtDriver' + flags.FLAGS.connection_type = 'libvirt' + + def test_get_counter(self): + list(self.pollster.get_counters(self.manager, self.instance)) + + class TestDiskIOPollster(unittest.TestCase): def setUp(self):