klio.metrics.dispatcher

Metric dispatchers for each metric type.

A dispatcher provides one single metric instance that will then interface with all configured relay clients for that particular metric time. For example:

relay_clients = [
    klio.metrics.logger.MetricsLoggerClient(config),
    some_other_relay_client,
]
my_counter = CounterDispatcher(relay_clients, name="my-counter")
my_counter.inc()

Creating the my_counter instance will create two relay counter instances, each specific to each of the relay clients configured. Calling inc() on my_counter will then call emit on each relay counter instance where each relay client will take care of its own emit logic.

class klio.metrics.dispatcher.BaseMetricDispatcher(relay_clients, name, value=0, transform=None, **kwargs)

Base class for metric-specific dispatching.

Each type of metric (counter, gauge, timer) requires a dispatcher implementation.

property logger

Python logger associated with metric dispatcher.

submit(emit, metric)

Emit metrics via a threadpool.

class klio.metrics.dispatcher.CounterDispatcher(relay_clients, name, value=0, transform=None, **kwargs)

Counter-like object that will emit via all configured clients.

inc(value=1)

Increment counter.

Calling this method will emit the metric via configured clients.

Parameters

value (int) – value with which to increment the counter; default is 1.

class klio.metrics.dispatcher.GaugeDispatcher(relay_clients, name, value=0, transform=None, **kwargs)

Gauge-like object that will emit via all configured clients.

set(value)

Set gauge to a given value.

Calling this method will emit the metric via configured clients.

Parameters

value (int) – value with which to set the gauge.

class klio.metrics.dispatcher.TimerDispatcher(relay_clients, name, value=0, transform=None, timer_unit='ns', **kwargs)

Timer-like object that will emit via all configured clients.

This may be used by instantiating and manually calling start & stop:

timer = TimerDispatcher(relay_clients, name)
timer.start()
# code to time
timer.stop()

Or as a context manager:

with TimerDispatcher(relay_clients, name):
    # code to time
start()

Start the timer.

stop()

Stop the timer.

Calling this method will emit the metric via configured clients.