Remove get_counter_names from the pollster plugins

Now that there is only one meter-type coming out of
each plugin, we can use the plugin name instead of
asking the plugin which counters it produces.

blueprint one-meter-per-plugin

Change-Id: I63328b1bb2a2440771d9f1f007ff69e717d3090f
Signed-off-by: Doug Hellmann <doug.hellmann@dreamhost.com>
This commit is contained in:
Doug Hellmann 2013-07-04 16:31:04 -04:00 committed by Julien Danjou
parent fa73544645
commit bf2d460988
18 changed files with 31 additions and 125 deletions

View File

@ -73,14 +73,12 @@ class AgentManager(object):
for pipeline, pollster in itertools.product(
self.pipeline_manager.pipelines,
self.pollster_manager.extensions):
for counter in pollster.obj.get_counter_names():
if pipeline.support_counter(counter):
polling_task = polling_tasks.get(pipeline.interval, None)
if not polling_task:
polling_task = self.create_polling_task()
polling_tasks[pipeline.interval] = polling_task
polling_task.add(pollster, [pipeline])
break
if pipeline.support_counter(pollster.name):
polling_task = polling_tasks.get(pipeline.interval, None)
if not polling_task:
polling_task = self.create_polling_task()
polling_tasks[pipeline.interval] = polling_task
polling_task.add(pollster, [pipeline])
return polling_tasks

View File

@ -34,23 +34,22 @@ class PollingTask(agent.PollingTask):
def poll_and_publish_instances(self, instances):
with self.publish_context as publisher:
for instance in instances:
if getattr(instance, 'OS-EXT-STS:vm_state', None) != 'error':
# TODO(yjiang5) passing counters to get_counters to avoid
# polling all counters one by one
cache = {}
for pollster in self.pollsters:
try:
LOG.info("Polling pollster %s", pollster.name)
counters = list(pollster.obj.get_counters(
self.manager,
cache,
instance,
))
publisher(counters)
except Exception as err:
LOG.warning('Continue after error from %s: %s',
pollster.name, err)
LOG.exception(err)
if getattr(instance, 'OS-EXT-STS:vm_state', None) == 'error':
continue
cache = {}
for pollster in self.pollsters:
try:
LOG.info("Polling pollster %s", pollster.name)
counters = list(pollster.obj.get_counters(
self.manager,
cache,
instance,
))
publisher(counters)
except Exception as err:
LOG.warning('Continue after error from %s: %s',
pollster.name, err)
LOG.exception(err)
def poll_and_publish(self):
self.poll_and_publish_instances(

View File

@ -65,10 +65,6 @@ class _Base(plugin.ComputePollster):
class CPUPollster(_Base):
@staticmethod
def get_counter_names():
return ['cpu']
@staticmethod
def _get_counter(instance, instance_name, cpu_info):
LOG.info("CPUTIME USAGE: %s %d",
@ -91,10 +87,6 @@ class CPUUtilPollster(_Base):
utilization_map = {}
@staticmethod
def get_counter_names():
return ['cpu_util']
def _get_cpu_util(self, instance, cpu_info):
prev_times = self.utilization_map.get(instance.id)
self.utilization_map[instance.id] = (cpu_info.time,

View File

@ -94,10 +94,6 @@ class _Base(plugin.ComputePollster):
class ReadRequestsPollster(_Base):
@staticmethod
def get_counter_names():
return ['disk.read.requests']
@staticmethod
def _get_counter(instance, c_data):
return util.make_counter_from_instance(
@ -111,10 +107,6 @@ class ReadRequestsPollster(_Base):
class ReadBytesPollster(_Base):
@staticmethod
def get_counter_names():
return ['disk.read.bytes']
@staticmethod
def _get_counter(instance, c_data):
return util.make_counter_from_instance(
@ -128,10 +120,6 @@ class ReadBytesPollster(_Base):
class WriteRequestsPollster(_Base):
@staticmethod
def get_counter_names():
return ['disk.write.requests']
@staticmethod
def _get_counter(instance, c_data):
return util.make_counter_from_instance(
@ -145,10 +133,6 @@ class WriteRequestsPollster(_Base):
class WriteBytesPollster(_Base):
@staticmethod
def get_counter_names():
return ['disk.write.bytes']
@staticmethod
def _get_counter(instance, c_data):
return util.make_counter_from_instance(

View File

@ -25,10 +25,6 @@ from ceilometer.compute.pollsters import util
class InstancePollster(plugin.ComputePollster):
@staticmethod
def get_counter_names():
return ['instance']
@staticmethod
def get_counters(manager, cache, instance):
yield util.make_counter_from_instance(
@ -42,16 +38,11 @@ class InstancePollster(plugin.ComputePollster):
class InstanceFlavorPollster(plugin.ComputePollster):
@staticmethod
def get_counter_names():
# Instance type counter is specific because it includes
# variable. We don't need such format in future
return ['instance:*']
@staticmethod
def get_counters(manager, cache, instance):
yield util.make_counter_from_instance(
instance,
# Use the "meter name + variable" syntax
name='instance:%s' %
instance.flavor['name'],
type=counter.TYPE_GAUGE,

View File

@ -91,10 +91,6 @@ class _Base(plugin.ComputePollster):
class IncomingBytesPollster(_Base):
@staticmethod
def get_counter_names():
return ['network.incoming.bytes']
def _get_counter(self, instance, vnic, info):
return self.make_vnic_counter(
instance,
@ -108,10 +104,6 @@ class IncomingBytesPollster(_Base):
class IncomingPacketsPollster(_Base):
@staticmethod
def get_counter_names():
return ['network.incoming.packets']
def _get_counter(self, instance, vnic, info):
return self.make_vnic_counter(
instance,
@ -125,10 +117,6 @@ class IncomingPacketsPollster(_Base):
class OutgoingBytesPollster(_Base):
@staticmethod
def get_counter_names():
return ['network.outgoing.bytes']
def _get_counter(self, instance, vnic, info):
return self.make_vnic_counter(
instance,
@ -142,10 +130,6 @@ class OutgoingBytesPollster(_Base):
class OutgoingPacketsPollster(_Base):
@staticmethod
def get_counter_names():
return ['network.outgoing.packets']
def _get_counter(self, instance, vnic, info):
return self.make_vnic_counter(
instance,

View File

@ -81,10 +81,6 @@ class _Base(plugin.CentralPollster):
class EnergyPollster(_Base):
"""Measures energy consumption."""
@staticmethod
def get_counter_names():
return ['energy']
def get_counters(self, manager, cache):
"""Returns all counters."""
for probe in self._iter_probes(manager.keystone, cache):
@ -105,10 +101,6 @@ class EnergyPollster(_Base):
class PowerPollster(_Base):
"""Measures power consumption."""
@staticmethod
def get_counter_names():
return ['power']
def get_counters(self, manager, cache):
"""Returns all counters."""
for probe in self._iter_probes(manager.keystone, cache):

View File

@ -100,10 +100,6 @@ class _Base(plugin.PollsterBase):
class ImagePollster(_Base):
@staticmethod
def get_counter_names():
return ['image']
def get_counters(self, manager, cache):
for image in self._iter_images(manager.keystone, cache):
yield counter.Counter(
@ -121,10 +117,6 @@ class ImagePollster(_Base):
class ImageSizePollster(_Base):
@staticmethod
def get_counter_names():
return ['image.size']
def get_counters(self, manager, cache):
for image in self._iter_images(manager.keystone, cache):
yield counter.Counter(

View File

@ -31,10 +31,6 @@ class FloatingIPPollster(plugin.CentralPollster):
LOG = log.getLogger(__name__ + '.floatingip')
@staticmethod
def get_counter_names():
return ['ip.floating']
def _get_floating_ips(self):
nv = nova_client.Client()
return nv.floating_ip_get_all()

View File

@ -89,10 +89,6 @@ class ObjectsPollster(_Base):
"""Iterate over all accounts, using keystone.
"""
@staticmethod
def get_counter_names():
return ['storage.objects']
def get_counters(self, manager, cache):
for tenant, account in self._iter_accounts(manager.keystone, cache):
yield counter.Counter(
@ -112,10 +108,6 @@ class ObjectsSizePollster(_Base):
"""Iterate over all accounts, using keystone.
"""
@staticmethod
def get_counter_names():
return ['storage.objects.size']
def get_counters(self, manager, cache):
for tenant, account in self._iter_accounts(manager.keystone, cache):
yield counter.Counter(
@ -135,10 +127,6 @@ class ObjectsContainersPollster(_Base):
"""Iterate over all accounts, using keystone.
"""
@staticmethod
def get_counter_names():
return ['storage.objects.containers']
def get_counters(self, manager, cache):
for tenant, account in self._iter_accounts(manager.keystone, cache):
yield counter.Counter(

View File

@ -75,10 +75,6 @@ class PollsterBase(PluginBase):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def get_counter_names(self):
"""Return a sequence of Counter names supported by the pollster."""
@abc.abstractmethod
def get_counters(self, manager, cache):
"""Return a sequence of Counter instances from polling the resources.

View File

@ -48,10 +48,6 @@ default_test_data = counter.Counter(
class TestPollster:
test_data = default_test_data
@classmethod
def get_counter_names(self):
return [self.test_data.name]
def get_counters(self, manager, cache, instance=None):
self.counters.append((manager, instance))
return [self.test_data]

View File

@ -53,8 +53,7 @@ class TestCPUPollster(base.TestPollsterBase):
counters = list(pollster.get_counters(mgr, cache, self.instance))
self.assertEquals(len(counters), 1)
self.assertEqual(set([c.name for c in counters]),
set(pollster.get_counter_names()))
assert counters[0].name == 'cpu'
set(['cpu']))
assert counters[0].volume == expected_time
assert pollster.CACHE_KEY_CPU in cache
assert self.instance.name in cache[pollster.CACHE_KEY_CPU]
@ -110,8 +109,7 @@ class TestCPUUtilPollster(base.TestPollsterBase):
counters = list(pollster.get_counters(mgr, cache, self.instance))
self.assertEquals(len(counters), 1)
self.assertEqual(set([c.name for c in counters]),
set(pollster.get_counter_names()))
assert counters[0].name == 'cpu_util'
set(['cpu_util']))
assert (counters[0].volume == 0.0 if zero else
counters[0].volume > 0.0)
assert pollster.CACHE_KEY_CPU in cache

View File

@ -53,7 +53,7 @@ class TestDiskPollsters(base.TestPollsterBase):
assert self.instance.name in cache[pollster.CACHE_KEY_DISK]
self.assertEqual(set([c.name for c in counters]),
set(pollster.get_counter_names()))
set([name]))
match = [c for c in counters if c.name == name]
self.assertEquals(len(match), 1, 'missing counter %s' % name)

View File

@ -77,7 +77,7 @@ class TestNetPollster(base.TestPollsterBase):
counters = list(pollster.get_counters(mgr, {}, self.instance))
self.assertEqual(len(counters), 3) # one for each nic
self.assertEqual(set([c.name for c in counters]),
set(pollster.get_counter_names()))
set([counters[0].name]))
def _verify_vnic_metering(ip, expected_volume, expected_rid):
match = [c for c in counters

View File

@ -166,10 +166,10 @@ class TestImagePollster(base.TestCase):
def test_image_get_counter_names(self):
counters = list(glance.ImagePollster().get_counters(self.manager, {}))
self.assertEqual(set([c.name for c in counters]),
set(glance.ImagePollster().get_counter_names()))
set(['image']))
def test_image_size_get_counter_names(self):
counters = list(glance.ImageSizePollster().get_counters(self.manager,
{}))
self.assertEqual(set([c.name for c in counters]),
set(glance.ImageSizePollster().get_counter_names()))
set(['image.size']))

View File

@ -84,7 +84,7 @@ class TestFloatingIPPollster(base.TestCase):
def test_get_counter_names(self):
counters = list(self.pollster.get_counters(self.manager, {}))
self.assertEqual(set([c.name for c in counters]),
set(self.pollster.get_counter_names()))
set(['ip.floating']))
def test_get_counters_cached(self):
cache = {}

View File

@ -132,7 +132,7 @@ class TestSwiftPollster(base.TestCase):
self.fake_iter_accounts)
counters = list(self.pollster.get_counters(self.manager, {}))
self.assertEqual(set([c.name for c in counters]),
set(self.pollster.get_counter_names()))
set([counters[0].name]))
def test_endpoint_notfound(self):
self.stubs.Set(self.manager.keystone.service_catalog, 'url_for',