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.
my_counter
inc()
emit
klio.metrics.dispatcher.
BaseMetricDispatcher
Base class for metric-specific dispatching.
Each type of metric (counter, gauge, timer) requires a dispatcher implementation.
logger
Python logger associated with metric dispatcher.
submit
Emit metrics via a threadpool.
CounterDispatcher
Counter-like object that will emit via all configured clients.
inc
Increment counter.
Calling this method will emit the metric via configured clients.
value (int) – value with which to increment the counter; default is 1.
GaugeDispatcher
Gauge-like object that will emit via all configured clients.
set
Set gauge to a given value.
value (int) – value with which to set the gauge.
TimerDispatcher
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.