Update pollsters to return counter list

Have pollsters to return the counter list that will be potentially returned.

For bp publisher-counters-frequency

Change-Id: I103f8ed6ad314080d479d4a2053e0df4312c60a3
Signed-off-by: Yunhong, Jiang <yunhong.jiang@intel.com>
This commit is contained in:
Yunhong, Jiang 2013-01-29 19:00:40 +08:00
parent bc471f2bb6
commit 0425a42bfd
11 changed files with 74 additions and 0 deletions

View File

@ -51,6 +51,12 @@ def make_counter_from_instance(instance, name, type, unit, volume):
class InstancePollster(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', 'instance:*']
def get_counters(self, manager, instance):
yield make_counter_from_instance(instance,
name='instance',
@ -78,6 +84,13 @@ class DiskIOPollster(plugin.ComputePollster):
"errors=%d",
])
@staticmethod
def get_counter_names():
return ['disk.read.requests',
'disk.read.bytes',
'disk.write.requests',
'disk.write.bytes']
def get_counters(self, manager, instance):
instance_name = _instance_name(instance)
try:
@ -147,6 +160,10 @@ class CPUPollster(plugin.ComputePollster):
cpu_util = 100 * cores_fraction * time_used / elapsed
return cpu_util
@staticmethod
def get_counter_names():
return ['cpu', 'cpu_util']
def get_counters(self, manager, instance):
self.LOG.info('checking instance %s', instance.id)
instance_name = _instance_name(instance)
@ -207,6 +224,13 @@ class NetPollster(plugin.ComputePollster):
resource_metadata=resource_metadata
)
@staticmethod
def get_counter_names():
return ['network.incoming.bytes',
'network.incoming.packets',
'network.outgoing.bytes',
'network.outgoing.packets']
def get_counters(self, manager, instance):
instance_name = _instance_name(instance)
self.LOG.info('checking instance %s', instance.id)

View File

@ -72,6 +72,10 @@ class _Base(plugin.CentralPollster):
class KwapiPollster(_Base):
"""Kwapi pollster derived from the base class."""
@staticmethod
def get_counter_names():
return ['energy', 'power']
def get_counters(self, manager):
"""Returns all counters."""
for probe in self.iter_probes():

View File

@ -83,6 +83,10 @@ class _Base(plugin.PollsterBase):
class ImagePollster(_Base):
@staticmethod
def get_counter_names():
return ['image', 'image.size']
def get_counters(self, manager):
for image in self.iter_images():
yield counter.Counter(

View File

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

View File

@ -93,6 +93,12 @@ class SwiftPollster(_Base):
"""Iterate over all accounts, using keystone.
"""
@staticmethod
def get_counter_names():
return ['storage.objects',
'storage.objects.size',
'storage.objects.containers']
@staticmethod
def iter_accounts():
ks = ksclient.Client(username=cfg.CONF.os_username,

View File

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

View File

@ -82,6 +82,9 @@ class TestDiskIOPollster(TestPollsterBase):
counters = list(pollster.get_counters(mgr, self.instance))
assert counters
self.assertEqual(set([c.name for c in counters]),
set(pollster.get_counter_names()))
def _verify_disk_metering(name, expected_volume):
match = [c for c in counters if c.name == name]
self.assertEquals(len(match), 1, 'missing counter %s' % name)
@ -129,6 +132,8 @@ class TestNetPollster(TestPollsterBase):
pollster = pollsters.NetPollster()
counters = list(pollster.get_counters(mgr, self.instance))
assert counters
self.assertEqual(set([c.name for c in counters]),
set(pollster.get_counter_names()))
def _verify_vnic_metering(name, ip, expected_volume):
match = [c for c in counters if c.name == name and
@ -168,6 +173,8 @@ class TestCPUPollster(TestPollsterBase):
def _verify_cpu_metering(zero, expected_time):
counters = list(pollster.get_counters(mgr, self.instance))
self.assertEquals(len(counters), 2)
self.assertEqual(set([c.name for c in counters]),
set(pollster.get_counter_names()))
assert counters[0].name == 'cpu_util'
assert (counters[0].volume == 0.0 if zero else
counters[0].volume > 0.0)

View File

@ -78,3 +78,8 @@ class TestKwapiPollster(base.TestCase):
self.assert_(
any(map(lambda counter: counter.volume == probe['w'],
power_counters)))
def test_kwapi_counter_list(self):
counters = list(kwapi.KwapiPollster().get_counters(self.manager))
self.assertEqual(set([c.name for c in counters]),
set(kwapi.KwapiPollster().get_counter_names()))

View File

@ -105,3 +105,8 @@ class TestImagePollster(base.TestCase):
self.assert_(
any(map(lambda counter: counter.volume == image.size,
counters)))
def test_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()))

View File

@ -67,3 +67,8 @@ class TestFloatingIPPollster(base.TestCase):
'1.1.1.2',
'1.1.1.3',
])
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()))

View File

@ -48,3 +48,8 @@ class TestSwiftPollster(base.TestCase):
def test_objectstore_metering(self):
counters = list(self.pollster.get_counters(self.manager))
self.assertEqual(len(counters), 6)
def test_objectstore_get_counter_names(self):
counters = list(self.pollster.get_counters(None))
self.assertEqual(set([c.name for c in counters]),
set(self.pollster.get_counter_names()))