geno_lewm.metrics¶
metrics
¶
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.
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.
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
snapshot_all
¶
Return a structured snapshot of every live metric.
Source code in geno_lewm/metrics.py
metrics_path
¶
Return the default exporter path.
Source code in geno_lewm/metrics.py
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
sync_redaction_counter
¶
Pull the in-process redaction counters into the metric.
The redaction filter from #24 keeps its own thread-local counters (so it can run without the metrics package being imported); this function reconciles the two views right before exposition.