Expand description
§Ultimate Metrics Library
The most powerful, lightweight, and efficient metrics library ever built.
§Features
- Sub-nanosecond operations - Counter increments in ~2-3ns
- Lock-free everything - No locks anywhere in hot paths
- System health monitoring - Built-in CPU/memory tracking
- Dynamic configuration - Runtime tuning without restarts
- Circuit breakers - Fault tolerance with auto-recovery
- Dead simple API -
METRICS.counter("requests").inc()
§Quick Start
use metrics_lib::{init, metrics};
// Initialize metrics (do this once at startup)
init();
// Counters (sub-nanosecond)
metrics().counter("requests").inc();
metrics().counter("errors").add(5);
// Gauges (atomic)
metrics().gauge("cpu_usage").set(87.3);
metrics().gauge("memory_mb").set(1024.5);
// Timers (high precision)
let timer_metric = metrics().timer("api_call");
let timer = timer_metric.start();
// ... do work ...
timer.stop(); // Auto-records
// Or even simpler
let result = metrics().time("db_query", || {
// Simulated database query
"user data"
});
// System health
let cpu_pct = metrics().system().cpu_used();
let mem_mb = metrics().system().mem_used_mb();
// Rate limiting
metrics().rate("api_calls").tick();
let rate_per_sec = metrics().rate("api_calls").rate();
Modules§
- gauge_
specialized - Specialized gauge types for common use cases
- prelude
- Prelude for convenient imports
- rate_
meter_ specialized - Specialized rate meters for common use cases
- utils
- Utility functions for timing
Macros§
- time_
block - Convenience macros
- time_fn
- Macro to time a function call and record the result
Structs§
- Adaptive
Sampler - Adaptive sampler for load shedding
- Async
Metric Batch - Batched metric updates for async contexts
- Async
Timer Guard - Async timer guard that records on drop
- Backpressure
Controller - Backpressure controller
- Counter
- Ultra-fast atomic counter
- Counter
Stats - Counter statistics
- Gauge
- Ultra-fast atomic gauge for f64 values
- Gauge
Stats - Gauge statistics
- Metric
Circuit Breaker - Circuit breaker for metric recording
- Metrics
Core - Main metrics interface - the core of everything
- Process
Stats - Process-specific resource usage
- Rate
Meter - Ultra-fast rate meter with sliding window calculations
- Rate
Stats - Rate statistics
- Registry
- A thread-safe registry for storing metrics by name.
- Running
Timer - Running timer instance (RAII)
- System
Health - System health monitor with process introspection
- System
Snapshot - System resource usage snapshot
- Timer
- High-precision timer with automatic statistics
- Timer
Stats - Timer statistics
Enums§
- Health
Status - System health status
- Metrics
Error - Metrics errors
- Sampling
Strategy - Adaptive sampling strategy
Statics§
- METRICS
- Global metrics instance - initialize once, use everywhere
Traits§
- Async
Timer Ext - Extension trait for async timer operations
Functions§
Type Aliases§
- Result
- Common result type for metrics operations