Metrics¶
GenoLeWM ships a registered metrics registry with a Prometheus
textfile exporter, defined by
RFC-0013 §4. The registry is the
single source of truth: new metrics MUST be added to
geno_lewm.metrics.METRICS and the AST linter
(check_event_names.py)
prevents call-site drift.
Registry¶
Primitives¶
GenoLeWM metrics registry and minimal Prometheus textfile exporter.
Defined by RFC-0013 §3.3 / 4 and docs/spec/05-observability.md.
Provides:
- :data:
METRICS— immutable registry ofMetricSpec(name, kind, unit, summary)rows. Renaming a metric name is a MAJOR change. - :class:
Counter, :class:Gauge, :class:Histogram— minimal, thread-safe primitives with no external dependency. - :func:
get_counter/ :func:get_gauge/ :func:get_histogram— validated accessors. The accessor verifies the metric is registered and has the expected kind, then returns a cached instance. - :func:
export_prometheus_textfile— writes a Prometheus textfile exposition to${GENO_LEWM_LOG_DIR}/metrics.prom(or a path of the caller's choosing). Honours the standard# HELP/# TYPElines and the histogram bucket / sum / count expansion.
DEFAULT_HISTOGRAM_BUCKETS_MS
module-attribute
¶
DEFAULT_HISTOGRAM_BUCKETS_MS: tuple[float, ...] = (0.5, 1, 2, 5, 10, 25, 50, 100, 250, 500, 1000, 2500, 5000, 10000, float('inf'))
DEFAULT_HISTOGRAM_BUCKETS_BYTES
module-attribute
¶
DEFAULT_HISTOGRAM_BUCKETS_BYTES: tuple[float, ...] = (1000000.0, 10000000.0, 100000000.0, 500000000.0, 1000000000.0, 5000000000.0, 10000000000.0, 50000000000.0, 100000000000.0, float('inf'))
Counter
¶
Gauge
¶
Histogram
¶
Bases: _Metric
Bucketed observation distribution.
Prometheus-compatible: the exposition emits <name>_bucket{le=…}
rows, <name>_sum, and <name>_count. Buckets are cumulative
by spec — the last bucket is always +Inf.
Source code in geno_lewm/metrics.py
HistogramSnapshot
¶
Bases: TypedDict
Structured snapshot returned by :meth:Histogram.snapshot.
Buckets are cumulative upper bounds (the last bucket is always
+Inf). counts[i] is the cumulative count of observations
<= buckets[i] since the last :meth:Histogram.reset.
MetricSpec
dataclass
¶
A single row in the :data:METRICS registry.
Accessors¶
GenoLeWM metrics registry and minimal Prometheus textfile exporter.
Defined by RFC-0013 §3.3 / 4 and docs/spec/05-observability.md.
Provides:
- :data:
METRICS— immutable registry ofMetricSpec(name, kind, unit, summary)rows. Renaming a metric name is a MAJOR change. - :class:
Counter, :class:Gauge, :class:Histogram— minimal, thread-safe primitives with no external dependency. - :func:
get_counter/ :func:get_gauge/ :func:get_histogram— validated accessors. The accessor verifies the metric is registered and has the expected kind, then returns a cached instance. - :func:
export_prometheus_textfile— writes a Prometheus textfile exposition to${GENO_LEWM_LOG_DIR}/metrics.prom(or a path of the caller's choosing). Honours the standard# HELP/# TYPElines and the histogram bucket / sum / count expansion.
get_counter
¶
Source code in geno_lewm/metrics.py
get_gauge
¶
Source code in geno_lewm/metrics.py
get_histogram
¶
Source code in geno_lewm/metrics.py
snapshot_all
¶
Return a structured snapshot of every live metric.
Source code in geno_lewm/metrics.py
Prometheus exporter¶
export_prometheus_textfile
¶
Write the current metric snapshot to a Prometheus textfile.
The write is atomic: contents go to <path>.tmp and are renamed
over <path> once flushed. Scrapers that read the file mid-flush
therefore see either the previous or the new value, never a partial
record. Returns the destination path.
Source code in geno_lewm/metrics.py
metrics_path
¶
Return the default exporter path.
Source code in geno_lewm/metrics.py
Atomicity guarantee: the exporter writes to a *.tmp file and renames
on top of the destination, so scrapers always observe either the
previous or the new value, never a torn record.