satella.instrumentation.metrics.exporters package

Submodules

satella.instrumentation.metrics.exporters.prometheus module

class satella.instrumentation.metrics.exporters.prometheus.PrometheusHTTPExporterThread(interface, port, extra_labels=None, enable_metric=False)

Bases: TerminableThread

A daemon thread that listens on given interface as a HTTP server, ready to serve as a connection point for Prometheus to scrape metrics off this service.

This additionally (if user requests so) may export a metric called prometheus.exports_per_time which is a cps with time_unit_vectors=[1, 20, 60] counting the amount of exports in given time period.

Parameters:
  • interface (str) – a interface to bind to

  • port (int) – a port to bind to

  • extra_labels (Optional[dict]) – extra labels to add to each metric data point, such as the name of the service or the hostname

  • enable_metric (bool) – whether to enable the metric

Note that this is called in the constructor’s thread. Use .prepare() to run statements that should be ran in new thread.

Parameters:
  • terminate_on – if provided, and loop() throws one of it, swallow it and terminate the thread by calling terminate(). Note that the subclass check will be done via isinstance so you can use the metaclass magic :) Note that SystemExit will be automatically added to list of terminable exceptions.

  • interface (str) –

  • port (int) –

  • extra_labels (Optional[dict]) –

  • enable_metric (bool) –

get_metric_data()

Obtain metric data.

Overload to provide custom source of metric data.

Return type:

MetricDataCollection

run()

Calls self.loop() indefinitely, until terminating condition is met

Return type:

None

terminate(force=False)

Order this thread to terminate and return self.

You will need to .join() on this thread to ensure that it has quit.

Parameters:

force (bool) – whether to terminate this thread by injecting an exception into it

Return type:

PrometheusHTTPExporterThread

satella.instrumentation.metrics.exporters.prometheus.metric_data_collection_to_prometheus(mdc)

Render the data in the form understandable by Prometheus.

Values marked as internal will be skipped.

Parameters:
  • mdc (MetricDataCollection) – Metric data collection to render

  • tree – MetricDataCollection returned by the root metric (or any metric for that instance).

Returns:

a string output to present to Prometheus

Return type:

str

Module contents

class satella.instrumentation.metrics.exporters.PrometheusHTTPExporterThread(interface, port, extra_labels=None, enable_metric=False)

Bases: TerminableThread

A daemon thread that listens on given interface as a HTTP server, ready to serve as a connection point for Prometheus to scrape metrics off this service.

This additionally (if user requests so) may export a metric called prometheus.exports_per_time which is a cps with time_unit_vectors=[1, 20, 60] counting the amount of exports in given time period.

Parameters:
  • interface (str) – a interface to bind to

  • port (int) – a port to bind to

  • extra_labels (Optional[dict]) – extra labels to add to each metric data point, such as the name of the service or the hostname

  • enable_metric (bool) – whether to enable the metric

Note that this is called in the constructor’s thread. Use .prepare() to run statements that should be ran in new thread.

Parameters:
  • terminate_on – if provided, and loop() throws one of it, swallow it and terminate the thread by calling terminate(). Note that the subclass check will be done via isinstance so you can use the metaclass magic :) Note that SystemExit will be automatically added to list of terminable exceptions.

  • interface (str) –

  • port (int) –

  • extra_labels (Optional[dict]) –

  • enable_metric (bool) –

get_metric_data()

Obtain metric data.

Overload to provide custom source of metric data.

Return type:

MetricDataCollection

run()

Calls self.loop() indefinitely, until terminating condition is met

Return type:

None

terminate(force=False)

Order this thread to terminate and return self.

You will need to .join() on this thread to ensure that it has quit.

Parameters:

force (bool) – whether to terminate this thread by injecting an exception into it

Return type:

PrometheusHTTPExporterThread

satella.instrumentation.metrics.exporters.metric_data_collection_to_prometheus(mdc)

Render the data in the form understandable by Prometheus.

Values marked as internal will be skipped.

Parameters:
  • mdc (MetricDataCollection) – Metric data collection to render

  • tree – MetricDataCollection returned by the root metric (or any metric for that instance).

Returns:

a string output to present to Prometheus

Return type:

str