Skip to main content

Module metrics_registry

Module metrics_registry 

Source
Expand description

Prometheus-compatible metrics registry (bd-xox.3).

Provides counters, gauges, and histograms that can be exported in Prometheus text exposition format via MetricsRegistry::render.

§Design

  • Zero-allocation on the hot path: All metric storage uses AtomicU64.
  • Lock-free reads: Snapshot is a single pass over atomic loads.
  • Label support: Metrics with labels use a fixed set of variants to avoid dynamic allocation and hash maps.
  • Histogram: Uses fixed log-scale buckets for O(1) observe.

§Usage

use ftui_runtime::metrics_registry::{METRICS, BuiltinCounter, BuiltinGauge, BuiltinHistogram};

// Increment a counter
METRICS.counter(BuiltinCounter::RenderFramesTotal).inc();

// Set a gauge
METRICS.gauge(BuiltinGauge::TerminalActive).set(1);

// Observe a histogram value
METRICS.histogram(BuiltinHistogram::RenderFrameDurationUs).observe(450);

// Export Prometheus text format
let output = METRICS.render();
println!("{output}");

Structs§

Counter
A monotonic counter (can only increase).
Gauge
A gauge (can go up or down).
Histogram
Fixed-bucket histogram for latency measurements.
MetricsRegistry
Central metrics registry with fixed-slot storage.

Enums§

BuiltinCounter
Builtin counter metrics.
BuiltinGauge
Builtin gauge metrics.
BuiltinHistogram
Builtin histogram metrics.

Statics§

METRICS
Global metrics registry instance.