Move datasources metric mappings out of base.py
Moved the metric mappings for Ceilormeter, Gnocchi & Monasca out of base.py. The datasources manager now uses classes extending base.py their NAME attribute as key in the dictionary of total available mappings and datasources. base.py still contains a template definition of all available mappings so that anyone extending the base class can identify all the possible endpoints they can map to. Change-Id: I6a826423031b5a6a60c4cd5fe24f74b8400f6b55 Closes-Bug: #1815769
This commit is contained in:
parent
f8dfdd405d
commit
73830387c6
|
@ -18,44 +18,18 @@ import abc
|
|||
|
||||
class DataSourceBase(object):
|
||||
|
||||
METRIC_MAP = dict(
|
||||
ceilometer=dict(host_cpu_usage='compute.node.cpu.percent',
|
||||
instance_cpu_usage='cpu_util',
|
||||
instance_l3_cache_usage='cpu_l3_cache',
|
||||
host_outlet_temp=(
|
||||
'hardware.ipmi.node.outlet_temperature'),
|
||||
host_airflow='hardware.ipmi.node.airflow',
|
||||
host_inlet_temp='hardware.ipmi.node.temperature',
|
||||
host_power='hardware.ipmi.node.power',
|
||||
instance_ram_usage='memory.resident',
|
||||
instance_ram_allocated='memory',
|
||||
instance_root_disk_size='disk.root.size',
|
||||
host_memory_usage='hardware.memory.used', ),
|
||||
gnocchi=dict(host_cpu_usage='compute.node.cpu.percent',
|
||||
instance_cpu_usage='cpu_util',
|
||||
instance_l3_cache_usage='cpu_l3_cache',
|
||||
host_outlet_temp='hardware.ipmi.node.outlet_temperature',
|
||||
host_airflow='hardware.ipmi.node.airflow',
|
||||
host_inlet_temp='hardware.ipmi.node.temperature',
|
||||
host_power='hardware.ipmi.node.power',
|
||||
instance_ram_usage='memory.resident',
|
||||
instance_ram_allocated='memory',
|
||||
instance_root_disk_size='disk.root.size',
|
||||
host_memory_usage='hardware.memory.used'
|
||||
),
|
||||
monasca=dict(host_cpu_usage='cpu.percent',
|
||||
instance_cpu_usage='vm.cpu.utilization_perc',
|
||||
instance_l3_cache_usage=None,
|
||||
host_outlet_temp=None,
|
||||
host_airflow=None,
|
||||
host_inlet_temp=None,
|
||||
host_power=None,
|
||||
instance_ram_usage=None,
|
||||
instance_ram_allocated=None,
|
||||
instance_root_disk_size=None,
|
||||
host_memory_usage=None
|
||||
),
|
||||
)
|
||||
METRIC_MAP = dict(host_cpu_usage=None,
|
||||
instance_cpu_usage=None,
|
||||
instance_l3_cache_usage=None,
|
||||
host_outlet_temp=None,
|
||||
host_airflow=None,
|
||||
host_inlet_temp=None,
|
||||
host_power=None,
|
||||
instance_ram_usage=None,
|
||||
instance_ram_allocated=None,
|
||||
instance_root_disk_size=None,
|
||||
host_memory_usage=None
|
||||
)
|
||||
|
||||
@abc.abstractmethod
|
||||
def statistic_aggregation(self, resource_id=None, meter_name=None,
|
||||
|
|
|
@ -34,7 +34,18 @@ LOG = log.getLogger(__name__)
|
|||
class CeilometerHelper(base.DataSourceBase):
|
||||
|
||||
NAME = 'ceilometer'
|
||||
METRIC_MAP = base.DataSourceBase.METRIC_MAP['ceilometer']
|
||||
METRIC_MAP = dict(host_cpu_usage='compute.node.cpu.percent',
|
||||
instance_cpu_usage='cpu_util',
|
||||
instance_l3_cache_usage='cpu_l3_cache',
|
||||
host_outlet_temp='hardware.ipmi.node.outlet_temperature',
|
||||
host_airflow='hardware.ipmi.node.airflow',
|
||||
host_inlet_temp='hardware.ipmi.node.temperature',
|
||||
host_power='hardware.ipmi.node.power',
|
||||
instance_ram_usage='memory.resident',
|
||||
instance_ram_allocated='memory',
|
||||
instance_root_disk_size='disk.root.size',
|
||||
host_memory_usage='hardware.memory.used',
|
||||
)
|
||||
|
||||
def __init__(self, osc=None):
|
||||
""":param osc: an OpenStackClients instance"""
|
||||
|
|
|
@ -35,7 +35,18 @@ LOG = log.getLogger(__name__)
|
|||
class GnocchiHelper(base.DataSourceBase):
|
||||
|
||||
NAME = 'gnocchi'
|
||||
METRIC_MAP = base.DataSourceBase.METRIC_MAP['gnocchi']
|
||||
METRIC_MAP = dict(host_cpu_usage='compute.node.cpu.percent',
|
||||
instance_cpu_usage='cpu_util',
|
||||
instance_l3_cache_usage='cpu_l3_cache',
|
||||
host_outlet_temp='hardware.ipmi.node.outlet_temperature',
|
||||
host_airflow='hardware.ipmi.node.airflow',
|
||||
host_inlet_temp='hardware.ipmi.node.temperature',
|
||||
host_power='hardware.ipmi.node.power',
|
||||
instance_ram_usage='memory.resident',
|
||||
instance_ram_allocated='memory',
|
||||
instance_root_disk_size='disk.root.size',
|
||||
host_memory_usage='hardware.memory.used',
|
||||
)
|
||||
|
||||
def __init__(self, osc=None):
|
||||
""":param osc: an OpenStackClients instance"""
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
# limitations under the License.
|
||||
|
||||
from watcher.common import exception
|
||||
from watcher.datasource import base
|
||||
from watcher.datasource import ceilometer as ceil
|
||||
from watcher.datasource import gnocchi as gnoc
|
||||
from watcher.datasource import monasca as mon
|
||||
|
@ -28,7 +27,11 @@ class DataSourceManager(object):
|
|||
self._ceilometer = None
|
||||
self._monasca = None
|
||||
self._gnocchi = None
|
||||
self.metric_map = base.DataSourceBase.METRIC_MAP
|
||||
self.metric_map = {
|
||||
mon.MonascaHelper.NAME: mon.MonascaHelper.METRIC_MAP,
|
||||
gnoc.GnocchiHelper.NAME: gnoc.GnocchiHelper.METRIC_MAP,
|
||||
ceil.CeilometerHelper.NAME: ceil.CeilometerHelper.METRIC_MAP
|
||||
}
|
||||
self.datasources = self.config.datasources
|
||||
|
||||
@property
|
||||
|
|
|
@ -28,7 +28,18 @@ from watcher.datasource import base
|
|||
class MonascaHelper(base.DataSourceBase):
|
||||
|
||||
NAME = 'monasca'
|
||||
METRIC_MAP = base.DataSourceBase.METRIC_MAP['monasca']
|
||||
METRIC_MAP = dict(host_cpu_usage='cpu.percent',
|
||||
instance_cpu_usage='vm.cpu.utilization_perc',
|
||||
instance_l3_cache_usage=None,
|
||||
host_outlet_temp=None,
|
||||
host_airflow=None,
|
||||
host_inlet_temp=None,
|
||||
host_power=None,
|
||||
instance_ram_usage=None,
|
||||
instance_ram_allocated=None,
|
||||
instance_root_disk_size=None,
|
||||
host_memory_usage=None,
|
||||
)
|
||||
|
||||
def __init__(self, osc=None):
|
||||
""":param osc: an OpenStackClients instance"""
|
||||
|
|
|
@ -17,23 +17,28 @@
|
|||
import mock
|
||||
|
||||
from watcher.common import exception
|
||||
from watcher.datasource import gnocchi as gnoc
|
||||
from watcher.datasource import manager as ds_manager
|
||||
from watcher.tests import base
|
||||
|
||||
|
||||
class TestDataSourceManager(base.BaseTestCase):
|
||||
|
||||
@mock.patch.object(gnoc, 'GnocchiHelper')
|
||||
def test_get_backend(self, mock_gnoc):
|
||||
def test_get_backend(self):
|
||||
manager = ds_manager.DataSourceManager(
|
||||
config=mock.MagicMock(
|
||||
datasources=['gnocchi', 'ceilometer', 'monasca']),
|
||||
osc=mock.MagicMock())
|
||||
backend = manager.get_backend(['host_cpu_usage',
|
||||
'instance_cpu_usage'])
|
||||
backend = manager.get_backend(['host_cpu_usage', 'instance_cpu_usage'])
|
||||
self.assertEqual(backend, manager.gnocchi)
|
||||
|
||||
def test_get_backend_order(self):
|
||||
manager = ds_manager.DataSourceManager(
|
||||
config=mock.MagicMock(
|
||||
datasources=['monasca', 'ceilometer', 'gnocchi']),
|
||||
osc=mock.MagicMock())
|
||||
backend = manager.get_backend(['host_cpu_usage', 'instance_cpu_usage'])
|
||||
self.assertEqual(backend, manager.monasca)
|
||||
|
||||
def test_get_backend_wrong_metric(self):
|
||||
manager = ds_manager.DataSourceManager(
|
||||
config=mock.MagicMock(
|
||||
|
|
Loading…
Reference in New Issue