aioprometheus.formats package

Submodules

aioprometheus.formats.base module

class aioprometheus.formats.base.IFormatter

Bases: abc.ABC

Formatter interface

get_headers()

Returns a dict of headers for this response format

marshall(registry) → bytes

Marshalls a registry (containing many collectors) into a specific format.

Returns:bytes

aioprometheus.formats.binary module

This module implements a formatter that emits metrics in a binary (Google Protocol Buffers) format.

class aioprometheus.formats.binary.BinaryFormatter(timestamp: bool = False)

Bases: aioprometheus.formats.base.IFormatter

This formatter encodes into the Protocol Buffers binary format

get_headers() → Dict[str, str]

Returns a dict of headers for this response format

marshall(registry: aioprometheus.registry.CollectorRegistry) → bytes

Marshall the collectors in the registry into binary protocol buffer format.

The Prometheus metrics parser expects each metric (MetricFamily) to be prefixed with a varint containing the size of the encoded metric.

Returns:bytes
marshall_collector(collector: Union[aioprometheus.collectors.Counter, aioprometheus.collectors.Gauge, aioprometheus.collectors.Histogram, aioprometheus.collectors.Summary]) → prometheus_metrics_pb2.MetricFamily

Marshalls a collector into a MetricFamily object representing the metrics in the collector.

Returns:a MetricFamily object

aioprometheus.formats.text module

This module implements a Prometheus metrics text formatter

class aioprometheus.formats.text.TextFormatter(timestamp: bool = False)

Bases: aioprometheus.formats.base.IFormatter

This formatter encodes into the Text format.

The histogram and summary types are difficult to represent in the text format. The following conventions apply:

  • The sample sum for a summary or histogram named x is given as a separate sample named x_sum.
  • The sample count for a summary or histogram named x is given as a separate sample named x_count.
  • Each quantile of a summary named x is given as a separate sample line with the same name x and a label {quantile=”y”}.
  • Each bucket count of a histogram named x is given as a separate sample line with the name x_bucket and a label {le=”y”} (where y is the upper bound of the bucket).
  • A histogram must have a bucket with {le=”+Inf”}. Its value must be identical to the value of x_count.
  • The buckets of a histogram and the quantiles of a summary must appear in increasing numerical order of their label values (for the le or the quantile label, respectively).
get_headers() → Dict[str, str]

Returns a dict of headers for this response format

marshall(registry: aioprometheus.registry.CollectorRegistry) → bytes

Marshalls a registry (containing collectors) into a bytes object

marshall_collector(collector: Union[aioprometheus.collectors.Counter, aioprometheus.collectors.Gauge, aioprometheus.collectors.Histogram, aioprometheus.collectors.Summary]) → str

Marshalls a collector into a string containing one or more lines

marshall_lines(collector: Union[aioprometheus.collectors.Counter, aioprometheus.collectors.Gauge, aioprometheus.collectors.Histogram, aioprometheus.collectors.Summary]) → List[str]

Marshalls a collector into a sequence of strings representing the metrics in the collector.

Returns:a list of strings.

Module contents