From 7c9a8569184ed15b12514a3c6b8d4848ce10ec08 Mon Sep 17 00:00:00 2001 From: Alexander Chadin Date: Tue, 16 Oct 2018 13:33:24 +0300 Subject: [PATCH] Update documentation regarding DataSource for strategies Change-Id: Ifc82fc06858a4e5a2badef074cd6bb5ce4e216cb --- .gitignore | 3 + .../contributor/plugin/strategy-plugin.rst | 63 ++++++++----------- 2 files changed, 28 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index 91319b938..31f7c4f76 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,6 @@ releasenotes/build # Autogenerated sample config file etc/watcher/watcher.conf.sample + +# Atom +.remote-sync.json diff --git a/doc/source/contributor/plugin/strategy-plugin.rst b/doc/source/contributor/plugin/strategy-plugin.rst index 5188e7f5f..5f38af147 100644 --- a/doc/source/contributor/plugin/strategy-plugin.rst +++ b/doc/source/contributor/plugin/strategy-plugin.rst @@ -245,15 +245,16 @@ Querying metrics A large set of metrics, generated by OpenStack modules, can be used in your strategy implementation. To collect these metrics, Watcher provides a -`Helper`_ for two data sources which are `Ceilometer`_ and `Monasca`_. If you -wish to query metrics from a different data source, you can implement your own -and directly use it from within your new strategy. Indeed, strategies in -Watcher have the cluster data models decoupled from the data sources which -means that you may keep the former while changing the latter. -The recommended way for you to support a new data source is to implement a new -helper that would encapsulate within separate methods the queries you need to -perform. To then use it, you would just have to instantiate it within your -strategy. +`DataSourceManager`_ for two data sources which are `Ceilometer`_ +(with `Gnocchi`_ as API) and `Monasca`_. If you wish to query metrics from a +different data source, you can implement your own and use it via +DataSourceManager from within your new strategy. Indeed, strategies in Watcher +have the cluster data models decoupled from the data sources which means that +you may keep the former while changing the latter. The recommended way for you +to support a new data source is to implement a new helper that would +encapsulate within separate methods the queries you need to perform. To then +use it, you would just have to add it to appropriate watcher_strategies.* +section in config file. If you want to use Ceilometer but with your own metrics database backend, please refer to the `Ceilometer developer guide`_. The list of the available @@ -263,52 +264,38 @@ requires new metrics not covered by Ceilometer, you can add them through a `Ceilometer plugin`_. -.. _`Helper`: https://github.com/openstack/watcher/blob/master/watcher/datasource/ceilometer.py +.. _`DataSourceManager`: https://github.com/openstack/watcher/blob/master/watcher/datasource/manager.py .. _`Ceilometer developer guide`: https://docs.openstack.org/ceilometer/latest/contributor/architecture.html#storing-accessing-the-data .. _`Ceilometer`: https://docs.openstack.org/ceilometer/latest .. _`Monasca`: https://github.com/openstack/monasca-api/blob/master/docs/monasca-api-spec.md .. _`here`: https://docs.openstack.org/ceilometer/latest/contributor/install/dbreco.html#choosing-a-database-backend .. _`Ceilometer plugin`: https://docs.openstack.org/ceilometer/latest/contributor/plugins.html .. _`Ceilosca`: https://github.com/openstack/monasca-ceilometer/blob/master/ceilosca/ceilometer/storage/impl_monasca.py +.. _`Gnocchi`: https://gnocchi.xyz/ Read usage metrics using the Watcher Datasource Helper ------------------------------------------------------ -The following code snippet shows how to invoke a Datasource Helper class: +The following code snippet shows how datasource_backend is defined: .. code-block:: py - from watcher.datasource import ceilometer as ceil - from watcher.datasource import monasca as mon + from watcher.datasource import manager as ds_manager @property - def ceilometer(self): - if self._ceilometer is None: - self._ceilometer = ceil.CeilometerHelper(osc=self.osc) - return self._ceilometer - - @property - def monasca(self): - if self._monasca is None: - self._monasca = mon.MonascaHelper(osc=self.osc) - return self._monasca + def datasource_backend(self): + if not self._datasource_backend: + self._datasource_backend = ds_manager.DataSourceManager( + config=self.config, + osc=self.osc + ).get_backend(self.DATASOURCE_METRICS) + return self._datasource_backend Using that you can now query the values for that specific metric: .. code-block:: py - if self.config.datasource == "ceilometer": - resource_id = "%s_%s" % (node.uuid, node.hostname) - return self.ceilometer.statistic_aggregation( - resource_id=resource_id, - meter_name='compute.node.cpu.percent', - period="7200", - aggregate='avg', - ) - elif self.config.datasource == "monasca": - statistics = self.monasca.statistic_aggregation( - meter_name='compute.node.cpu.percent', - dimensions=dict(hostname=node.uuid), - period=7200, - aggregate='avg' - ) + avg_meter = self.datasource_backend.statistic_aggregation( + instance.uuid, 'cpu_util', self.periods['instance'], + self.granularity, + aggregation=self.aggregation_method['instance'])