klio.metrics.shumway

Klio supports emitting metrics for sending metrics to a FFWD agent via the shumway library.

This client is enabled by default when running with Klio’s DirectGKERunner. This must be actively turned off in klio-job.yaml if not wanted:

job_config:
  metrics:
    shumway: False

Configuration is supported for the key used to report metrics, as well as unit of measure for timers objects in klio-job.yaml:

job_config:
  metrics:
    shumway:
      # The default value for `key` is the job's name.
      key: my-job-key
      # Default timer unit is ns/nanoseconds; available
      # options include `s` or `seconds`, `ms` or `milliseconds`,
      # `us` or `microseconds`, and `ns` or `nanoseconds`.
      timer_unit: seconds

To configure a different unit of measure than the default for specific timers, pass in the desired unit when instantiating. For example:

class MyTransform(KlioBaseTransform):
    def __init__(self):
        self.my_timer = self._klio.metrics.timer(
            name="my-timer", timer_unit="ns"
        )
klio.metrics.shumway.TIMER_UNIT_MAP = {'microseconds': 'us', 'milliseconds': 'ms', 'ms': 'ms', 'nanoseconds': 'ns', 'ns': 'ns', 's': 's', 'seconds': 's', 'us': 'us'}

Map of supported measurement units to shorthand for ShumwayTimer.

class klio.metrics.shumway.ShumwayMetricsClient(klio_config)

Metrics client for FFWD metrics reporting via the shumway library.

Intended to be instantiated by klio.metrics.client.MetricsRegistry and not by itself.

Parameters

klio_config (klio_core.config.KlioConfig) – the job’s configuration.

DEFAULT_FFWD_ADDR = '127.0.0.1'

Default unit of measurement for timer metrics.

unmarshal(metric)

Return a dict-representation of a given metric.

Parameters

metric (BaseShumwayMetric) – logger-specific metrics object

Returns

metric data

Return type

dict(str, str)

emit(metric)

Emit a metric to the FFWD agent.

Parameters

metric (BaseShumwayMetric) – logger-specific metrics object

counter(name, value=0, transform=None, tags=None, **kwargs)

Create a ShumwayCounter object.

Parameters
  • name (str) – name of counter

  • value (int) – starting value of counter; defaults to 0

  • transform (str) – transform the counter is associated with

  • tags (dict) – any tags of additional contextual information to associate with the counter

Returns

a shumway-based counter

Return type

ShumwayCounter

gauge(name, value=0, transform=None, tags=None, **kwargs)

Create a ShumwayGauge object.

Parameters
  • name (str) – name of gauge

  • value (int) – starting value of gauge; defaults to 0

  • transform (str) – transform the gauge is associated with

  • tags (dict) – any tags of additional contextual information to associate with the gauge

Returns

a shumway-based gauge

Return type

ShumwayGauge

timer(name, value=0, transform=None, timer_unit=None, tags=None, **kwargs)

Create a ShumwayTimer object.

Parameters
  • name (str) – name of timer

  • value (int) – starting value of timer; defaults to 0

  • transform (str) – transform the timer is associated with

  • tags (dict) – any tags of additional contextual information to associate with the timer

  • timer_unit (str) – timer unit; defaults to configured value in klio-job.yaml, or “ns”. Options: TIMER_UNIT_MAP.

Returns

a shumway-based timer

Return type

ShumwayTimer

class klio.metrics.shumway.BaseShumwayMetric(name, value=0, transform=None, tags=None, **kwargs)

Base metric type for shumway.

Parameters
  • name (str) – name of counter

  • value (int) – initial value. Default: 0.

  • transform (str) – Name of transform associated with metric, if any.

  • tags (dict) – Tags to associate with metric.

class klio.metrics.shumway.ShumwayCounter(name, value=0, transform=None, tags=None, **kwargs)

Shumway counter metric.

Parameters
  • name (str) – name of counter

  • value (int) – initial value. Default: 0.

  • transform (str) – Name of transform associated with counter, if any.

  • tags (dict) – Tags to associate with counter.

class klio.metrics.shumway.ShumwayGauge(name, value=0, transform=None, tags=None, **kwargs)

Shumway gauge metric.

Parameters
  • name (str) – name of counter

  • value (int) – initial value. Default: 0.

  • transform (str) – Name of transform associated with counter, if any.

  • tags (dict) – Tags to associate with counter.

class klio.metrics.shumway.ShumwayTimer(name, value=0, transform=None, timer_unit='ns', tags=None, **kwargs)

Shumway timer metric.

Parameters
  • name (str) – name of counter

  • value (int) – initial value. Default: 0.

  • transform (str) – Name of transform associated with counter, if any.

  • timer_unit (str) – Unit of measurement. Options: TIMER_UNIT_MAP. Default: ns (nanoseconds).

  • tags (list) – Tags to associate with counter.