Update documentation regarding DataSource for strategies

Change-Id: Ifc82fc06858a4e5a2badef074cd6bb5ce4e216cb
This commit is contained in:
Alexander Chadin 2018-10-16 13:33:24 +03:00
parent b69fc584d8
commit 7c9a856918
2 changed files with 28 additions and 38 deletions

3
.gitignore vendored
View File

@ -75,3 +75,6 @@ releasenotes/build
# Autogenerated sample config file # Autogenerated sample config file
etc/watcher/watcher.conf.sample etc/watcher/watcher.conf.sample
# Atom
.remote-sync.json

View File

@ -245,15 +245,16 @@ Querying metrics
A large set of metrics, generated by OpenStack modules, can be used in your A large set of metrics, generated by OpenStack modules, can be used in your
strategy implementation. To collect these metrics, Watcher provides a strategy implementation. To collect these metrics, Watcher provides a
`Helper`_ for two data sources which are `Ceilometer`_ and `Monasca`_. If you `DataSourceManager`_ for two data sources which are `Ceilometer`_
wish to query metrics from a different data source, you can implement your own (with `Gnocchi`_ as API) and `Monasca`_. If you wish to query metrics from a
and directly use it from within your new strategy. Indeed, strategies in different data source, you can implement your own and use it via
Watcher have the cluster data models decoupled from the data sources which DataSourceManager from within your new strategy. Indeed, strategies in Watcher
means that you may keep the former while changing the latter. have the cluster data models decoupled from the data sources which means that
The recommended way for you to support a new data source is to implement a new you may keep the former while changing the latter. The recommended way for you
helper that would encapsulate within separate methods the queries you need to to support a new data source is to implement a new helper that would
perform. To then use it, you would just have to instantiate it within your encapsulate within separate methods the queries you need to perform. To then
strategy. 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, 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 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`_. `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 developer guide`: https://docs.openstack.org/ceilometer/latest/contributor/architecture.html#storing-accessing-the-data
.. _`Ceilometer`: https://docs.openstack.org/ceilometer/latest .. _`Ceilometer`: https://docs.openstack.org/ceilometer/latest
.. _`Monasca`: https://github.com/openstack/monasca-api/blob/master/docs/monasca-api-spec.md .. _`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 .. _`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 .. _`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 .. _`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 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 .. code-block:: py
from watcher.datasource import ceilometer as ceil from watcher.datasource import manager as ds_manager
from watcher.datasource import monasca as mon
@property @property
def ceilometer(self): def datasource_backend(self):
if self._ceilometer is None: if not self._datasource_backend:
self._ceilometer = ceil.CeilometerHelper(osc=self.osc) self._datasource_backend = ds_manager.DataSourceManager(
return self._ceilometer config=self.config,
osc=self.osc
@property ).get_backend(self.DATASOURCE_METRICS)
def monasca(self): return self._datasource_backend
if self._monasca is None:
self._monasca = mon.MonascaHelper(osc=self.osc)
return self._monasca
Using that you can now query the values for that specific metric: Using that you can now query the values for that specific metric:
.. code-block:: py .. code-block:: py
if self.config.datasource == "ceilometer": avg_meter = self.datasource_backend.statistic_aggregation(
resource_id = "%s_%s" % (node.uuid, node.hostname) instance.uuid, 'cpu_util', self.periods['instance'],
return self.ceilometer.statistic_aggregation( self.granularity,
resource_id=resource_id, aggregation=self.aggregation_method['instance'])
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'
)