Skip to content

Adapters

Drop-in MetricsHook implementations for popular observability stacks. Each is a no-op until installed via the corresponding optional extra.

Prometheus

Install with mneme[prometheus].

PrometheusMetricsHook

PrometheusMetricsHook(registry: CollectorRegistry | None = None, namespace: str = 'mneme')

Callable hook that emits the documented Prometheus metric series.

Construct with an explicit CollectorRegistry to keep mneme's metrics isolated from the global default registry (recommended for tests and multi-tenant exposition).

update_gauges

update_gauges(stats: Stats) -> None

Refresh the entry-count and memory gauges from a cache.stats() snapshot. Call from a periodic task or readiness handler.

OpenTelemetry

Install with mneme[otel].

OTelMetricsHook

OTelMetricsHook(meter: Meter | None = None, namespace: str = 'mneme')

Callable hook that records OpenTelemetry metrics.

Pass an explicit Meter (e.g. from MeterProvider.get_meter(...)) to keep mneme's metrics under a known scope. If omitted, a meter is obtained from the global MeterProvider.

update_gauges

update_gauges(stats: Stats) -> None

Refresh entry-count + memory gauges from a cache.stats() snapshot.