Crate metrics_lib

Crate metrics_lib 

Source
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§

AdaptiveSampler
Adaptive sampler for load shedding
AsyncMetricBatch
Batched metric updates for async contexts
AsyncTimerGuard
Async timer guard that records on drop
BackpressureController
Backpressure controller
Counter
Ultra-fast atomic counter
CounterStats
Counter statistics
Gauge
Ultra-fast atomic gauge for f64 values
GaugeStats
Gauge statistics
MetricCircuitBreaker
Circuit breaker for metric recording
MetricsCore
Main metrics interface - the core of everything
ProcessStats
Process-specific resource usage
RateMeter
Ultra-fast rate meter with sliding window calculations
RateStats
Rate statistics
Registry
A thread-safe registry for storing metrics by name.
RunningTimer
Running timer instance (RAII)
SystemHealth
System health monitor with process introspection
SystemSnapshot
System resource usage snapshot
Timer
High-precision timer with automatic statistics
TimerStats
Timer statistics

Enums§

HealthStatus
System health status
MetricsError
Metrics errors
SamplingStrategy
Adaptive sampling strategy

Statics§

METRICS
Global metrics instance - initialize once, use everywhere

Traits§

AsyncTimerExt
Extension trait for async timer operations

Functions§

init
Initialize the global metrics instance
metrics
Get the global metrics instance

Type Aliases§

Result
Common result type for metrics operations