Skip to content

Latest commit

 

History

History
257 lines (174 loc) · 5.67 KB

File metadata and controls

257 lines (174 loc) · 5.67 KB

Quick start

Build a new metrics driver

This section is a step-by-step walkthroughstep-by-step walkthrough to help you build a metrics driver.

In your python code

# Import path --> drivers.sample.metric_sample
from oslo_config import cfg
from watcher_metering.agent.measurement import Measurement
from watcher_metering.agent.puller import DataSourcePuller

class MetricSample(DataSourcePuller):

    def __init__(self, my_opt1):
        self.my_opt1 = my_opt1

    @classmethod
    def get_name(cls):
        return 'metric_sample'

    @classmethod
    def get_config_opts(cls):
        return [cfg.StrOpt('my_opt1')]

    @classmethod
    def get_external_opts_configs(cls):
        return []

    @classmethod
    def get_default_probe_id(cls):
        return 'metric.driver.sample.metric_sample'

    @classmethod
    def get_default_interval(cls):
        return 1  # In seconds

    def do_pull(self):
        # Do some work here...
        return [Measurement([...])]

    # [...]

def list_opts(self):
    return [
        (MetricSample.get_entry_name(), MetricSample.get_config_opts())
    ]

Entry point configuration

In the setup.cfg file (if using pbr)

[entry_points]
watcher_metering.drivers =
    metric_sample = drivers.sample.metric_sample:MetricSample
oslo.config.opts =
    metric_sample = drivers.sample.metric_sample:list_opts

In the setup.py file (if not using pbr)

setup(
    name='metric_sample',
    entry_points={
        'watcher_metering.drivers': [
            'metric_sample = drivers.sample.metric_sample:MetricSample'
        ],
        'oslo.config.opts': [
            'metric_sample = drivers.sample.metric_sample:list_opts'
        ]
    },
    # ...
)

In the configuration file

[metrics_driver.metric_sample]
my_opt1= value1
#...

Usage

By calling:

from oslo_config import cfg
from watcher_metering.agent.loader import MetricsDriverLoader

loader = MetricsDriverLoader(conf=cfg.CONF, name='metric_sample')
sample_instance = loader.load()

You get a sample_instance of type MetricSample as if it were instantiated like this:

sample_instance = MetricSample(my_opt1='value1')

The configuration parameters are injected into the constructor of the MetricSample class.

Build a new store client driver

This section is a step-by-step walkthrough to help you build a metrics store client driver.

In your python code

# Import path --> store.sample.sample_store
from oslo_config import cfg
from watcher_metering.store.base import MetricsStoreClientBase

class SampleStoreClient(MetricsStoreClientBase):

    def __init__(self, my_store_opt1):
        self.my_store_opt1 = my_store_opt1

    @classmethod
    def namespace(cls):
        return StoreClientLoader.namespace

    @classmethod
    def get_config_opts(cls):
        return [cfg.StrOpt('my_store_opt1')]

    @classmethod
    def get_external_opts_configs(cls):
        return []

    @property
    def store_endpoint(self):
        return "tcp://store-endpoint:1337"

    def connect(self):
        # Do some work here...
        pass

    def disconnect(self):
        # Do some work here...
        pass

    def send(self, metric):
        # Do some work here...
        pass

    # [...]

def list_opts(self):
    return [
        (SampleStoreClient.get_entry_name(),
         SampleStoreClient.get_config_opts())
    ]

Entry point configuration

In the setup.cfg file (if using pbr)

[entry_points]
watcher_metering.store =
    sample_store = store.sample.sample_store:SampleStoreClient
oslo.config.opts =
    sample_store = store.sample.sample_store:list_opts

In the setup.py file (if not using pbr)

setup(
    name='sample_store',
    entry_points={
        'watcher_metering.store': [
            'sample_store = store.sample.sample_store:SampleStoreClient'
        ],
        'oslo.config.opts': [
            'sample_store = store.sample.sample_store:list_opts'
        ]
    },
    # ...
)

In the configuration file

[metrics_driver.metric_sample]
my_store_opt1= value1
#...

Usage

By calling:

from oslo_config import cfg
from watcher_metering.store.loader import StoreClientLoader

loader = StoreClientLoader(conf=cfg.CONF, name='sample_store')
sample_store_instance = loader.load()

You get a sample_store_instance of type SampleStoreClient as if it were instantiated like this:

sample_store_instance = SampleStoreClient(my_store_opt1='value1')

The configuration parameters are injected into the __init__ constructor of the SampleStoreClient class.