summaryrefslogtreecommitdiff
path: root/ceilometer/energy
diff options
context:
space:
mode:
authorNejc Saje <nsaje@redhat.com>2014-08-27 17:14:15 -0400
committerNejc Saje <nsaje@redhat.com>2014-09-08 13:38:10 -0400
commitb6e1c7e5dcb405f01fd5160d94aecf0249d8ad59 (patch)
treeb9f7dec87af6fefac8a6137fff2c795823ce3d23 /ceilometer/energy
parentfcc6b0de4ef309a91dbf1ea94f475a8e5f168534 (diff)
downloadceilometer-b6e1c7e5dcb405f01fd5160d94aecf0249d8ad59.tar.gz
Migrate the rest of the central agent pollsters to use discoveries
Currently, not all the central agent pollsters use discoveries. In order to enable horizontal scaling, all pollsters must use discoveries so the resources can be partitioned across the pool of running central agents. For pollsters that don't poll specific resources, but only poll general info from services, we treat the service endpoints as resources. So in the case of Glance, there will be only one resource available for all the pollsters (a Glance endpoint). If there are multiple agents running, only one will be assigned that endpoint and only one will poll Glance API. DocImpact Co-Authored-By: Dina Belova <dbelova@mirantis.com> Closes-Bug: #1364352 Change-Id: I8f3b228db9aacf3a7cc4b719c50013cc30d5aa79
Diffstat (limited to 'ceilometer/energy')
-rw-r--r--ceilometer/energy/kwapi.py83
1 files changed, 42 insertions, 41 deletions
diff --git a/ceilometer/energy/kwapi.py b/ceilometer/energy/kwapi.py
index 21156b07..a77f3f49 100644
--- a/ceilometer/energy/kwapi.py
+++ b/ceilometer/energy/kwapi.py
@@ -17,7 +17,6 @@
import datetime
from keystoneclient import exceptions
-from oslo.config import cfg
import requests
import six
@@ -55,25 +54,27 @@ class KwapiClient(object):
class _Base(plugin.CentralPollster):
"""Base class for the Kwapi pollster, derived from CentralPollster."""
+ @property
+ def default_discovery(self):
+ return 'endpoint:energy'
+
@staticmethod
- def get_kwapi_client(ksclient):
+ def get_kwapi_client(ksclient, endpoint):
"""Returns a KwapiClient configured with the proper url and token."""
- endpoint = ksclient.service_catalog.url_for(
- service_type='energy',
- endpoint_type=cfg.CONF.service_credentials.os_endpoint_type)
return KwapiClient(endpoint, ksclient.auth_token)
CACHE_KEY_PROBE = 'kwapi.probes'
- def _iter_probes(self, ksclient, cache):
+ def _iter_probes(self, ksclient, cache, endpoint):
"""Iterate over all probes."""
- if self.CACHE_KEY_PROBE not in cache:
- cache[self.CACHE_KEY_PROBE] = self._get_probes(ksclient)
- return iter(cache[self.CACHE_KEY_PROBE])
+ key = '%s-%s' % (endpoint, self.CACHE_KEY_PROBE)
+ if key not in cache:
+ cache[key] = self._get_probes(ksclient, endpoint)
+ return iter(cache[key])
- def _get_probes(self, ksclient):
+ def _get_probes(self, ksclient, endpoint):
try:
- client = self.get_kwapi_client(ksclient)
+ client = self.get_kwapi_client(ksclient, endpoint)
except exceptions.EndpointNotFound:
LOG.debug(_("Kwapi endpoint not found"))
return []
@@ -82,39 +83,39 @@ class _Base(plugin.CentralPollster):
class EnergyPollster(_Base):
"""Measures energy consumption."""
- @plugin.check_keystone('energy')
- def get_samples(self, manager, cache, resources=None):
+ def get_samples(self, manager, cache, resources):
"""Returns all samples."""
- for probe in self._iter_probes(manager.keystone, cache):
- yield sample.Sample(
- name='energy',
- type=sample.TYPE_CUMULATIVE,
- unit='kWh',
- volume=probe['kwh'],
- user_id=None,
- project_id=None,
- resource_id=probe['id'],
- timestamp=datetime.datetime.fromtimestamp(
- probe['timestamp']).isoformat(),
- resource_metadata={}
- )
+ for endpoint in resources:
+ for probe in self._iter_probes(manager.keystone, cache, endpoint):
+ yield sample.Sample(
+ name='energy',
+ type=sample.TYPE_CUMULATIVE,
+ unit='kWh',
+ volume=probe['kwh'],
+ user_id=None,
+ project_id=None,
+ resource_id=probe['id'],
+ timestamp=datetime.datetime.fromtimestamp(
+ probe['timestamp']).isoformat(),
+ resource_metadata={}
+ )
class PowerPollster(_Base):
"""Measures power consumption."""
- @plugin.check_keystone('energy')
- def get_samples(self, manager, cache, resources=None):
+ def get_samples(self, manager, cache, resources):
"""Returns all samples."""
- for probe in self._iter_probes(manager.keystone, cache):
- yield sample.Sample(
- name='power',
- type=sample.TYPE_GAUGE,
- unit='W',
- volume=probe['w'],
- user_id=None,
- project_id=None,
- resource_id=probe['id'],
- timestamp=datetime.datetime.fromtimestamp(
- probe['timestamp']).isoformat(),
- resource_metadata={}
- )
+ for endpoint in resources:
+ for probe in self._iter_probes(manager.keystone, cache, endpoint):
+ yield sample.Sample(
+ name='power',
+ type=sample.TYPE_GAUGE,
+ unit='W',
+ volume=probe['w'],
+ user_id=None,
+ project_id=None,
+ resource_id=probe['id'],
+ timestamp=datetime.datetime.fromtimestamp(
+ probe['timestamp']).isoformat(),
+ resource_metadata={}
+ )