klio.metrics.logger

Klio ships with a default klio.metrics.base.AbstractRelayClient implementation, which outputs metrics via the standard library logging module through the MetricsLoggerClient below.

This implementation is used by default if no other metrics consumers are configured. It must be explicitly turned off.

The default configuration in klio-info.yaml can be overwritten:

job_config:
    metrics:
        logger:
            # Logged metrics are emitted at the `debug` level by default.
            level: info
            # Default timer unit is ns/nanoseconds; available
            # options include `s` or `seconds`, `ms` or `milliseconds`,
            # `us` or `microseconds`, and `ns` or `nanoseconds`.
            timer_unit: s

To turn off logging-based metrics:

job_config
    metrics:
        logger: false
klio.metrics.logger.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 LoggerTimer.

class klio.metrics.logger.MetricsLoggerClient(klio_config, disabled=False)

Logging client for transform metrics.

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

Parameters
property logger

Python logger associated with the job which this client will use to emit metrics.

unmarshal(metric)

Return a dict-representation of a given metric.

Parameters

metric (LoggerMetric) – logger-specific metrics object

Returns

metric data

Return type

dict(str, str)

emit(metric)

Log a given metric.

Parameters

metric (LoggerMetric) – logger-specific metrics object

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

Create a LoggerCounter 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 log-based counter

Return type

LoggerCounter

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

Create a LoggerGauge 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 log-based gauge

Return type

LoggerGauge

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

Create a LoggerTimer 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”. See module-level docs of klio.metrics.logger for supported values.

Returns

a log-based timer

Return type

LoggerTimer

class klio.metrics.logger.LoggerMetric(name, value=0, transform=None, tags=None)

Base metric type for loggers.

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.logger.LoggerCounter(name, value=0, transform=None, tags=None)

Log-based 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. Note: {"metric_type": "counter"} will always be an included tag.

class klio.metrics.logger.LoggerGauge(name, value=0, transform=None, tags=None)

Log-based gauge metric.

Parameters
  • name (str) – name of gauge

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

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

  • tags (dict) – Tags to associate with gauge. Note: {"metric_type": "gauge"} will always be an included tag.

class klio.metrics.logger.LoggerTimer(name, value=0, transform=None, tags=None, timer_unit='ns')

Log-based timer metric.

Parameters
  • name (str) – name of timer

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

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

  • tags (dict) – Tags to associate with timer. Note: {"metric_type": "timer"} will always be an included tag.

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