Skip to main content

Crate skeg_telemetry

Crate skeg_telemetry 

Source
Expand description

Zero-overhead telemetry for skeg.

All public API entry points are #[inline(always)]. When neither the stats nor http feature is enabled, every call collapses to a no-op the compiler eliminates (verified with cargo asm).

When stats is enabled (default), the static counters and histograms tick on the hot path with a single atomic fetch_add each. Reading the values is done by stats::dump_text (or the helper accessors on metrics / histograms); reading does not lock, and never blocks the hot path.

When http is also enabled, [http::serve_blocking] runs a tiny HTTP server on a dedicated thread that serves /metrics in Prometheus text format. The server is purely a reader — it never writes through the hot path.

§Hot-path cost budget

  • per-op counter tick: AtomicU64::fetch_add(1, Relaxed) ≈ 1–2 ns
  • per-op histogram tick: leading-zeros bucket pick + one fetch_add ≈ 3–5 ns

The crate’s benches/overhead.rs gates these with criterion; CI fails the build if any record path exceeds 50 ns.

Re-exports§

pub use dynamic::DynHistogram;
pub use dynamic::DynOp;
pub use dynamic::register_counter;
pub use dynamic::register_gauge;
pub use dynamic::register_histogram;
pub use metrics::MAX_SHARDS;

Modules§

dynamic
Dynamic metric registry — extensibility without giving up zero overhead.
histograms
Fixed-bucket exponential histograms.
metrics
Static atomic metric storage.
stats
In-process text dumper for the RESP3 STATS command.

Macros§

register_op
Register a DynOp (sharded counter + histogram) from a single base name. Expands at compile time to two calls into the dynamic registries with the canonical Prometheus suffixes.

Enums§

Counter
Counters that exist outside the per-op hot path.
Gauge
Gauges (current value, not monotonic).
Op
Enumeration of operations tracked on the hot path.

Functions§

add_counter
Add a delta to a counter (for batch / amortised paths).
decr_gauge
Decrement a gauge by one. Safe to call when the gauge is already zero (wraps; pair calls correctly with incr_gauge for symmetry).
incr_gauge
Increment a gauge by one. Pair with decr_gauge for “in flight” counters where the natural API is incr at the start of an operation and decr at the end.
record_op
Record completion of one operation, with its observed duration.
set_gauge
Set the current value of a gauge metric (overwrites; not a counter).
tick_counter
Increment a counter that is not tied to a specific operation.