sz-orm-observability 6.0.0

SZ-ORM 鍙娴嬫€фā鍧楋細Prometheus exporter (TcpListener) + SLO 鐕冪儳锟?+ Grafana 浠〃鐩樻ā鏉匡紱OTLP 瀵煎嚭璇蜂娇锟?sz-orm-tracing 锟?otlp feature
Documentation

SZ-ORM Observability Module

Provides Prometheus exporter, SLO burn rate monitoring, and other capabilities. OTLP export is provided by the otlp feature of sz-orm-tracing (this module does not include OTLP).

Core Capabilities

1. MetricsRegistry (enabled by default)

Unified metric registry, supporting Counter / Gauge / Histogram types, with built-in thread safety (RwLock), and can output Prometheus text format via render().

2. Prometheus exporter

Exposes the /metrics HTTP endpoint on the specified port via start_metrics_server, for Prometheus to scrape. Implemented based on tokio::net::TcpListener (does not depend on hyper).

3. SLO burn rate

Computes SLO burn rate based on 5m / 1h windows, supporting multi-window alerts.

Quick Start

use sz_orm_observability::{MetricsRegistry, MetricKind};
use std::time::Duration;

// Create metric registry
let registry = MetricsRegistry::new();

// Register metrics
let counter = registry.register_counter("sz_orm_pool_acquires_total", "Total pool acquire calls");
let gauge = registry.register_gauge("sz_orm_pool_active_connections", "Current active connections");
let histogram = registry.register_histogram(
    "sz_orm_query_duration_seconds",
    "Query duration in seconds",
    vec![0.001, 0.01, 0.1, 1.0, 10.0],
);

// Update metrics
counter.inc();
gauge.set(5.0);
histogram.observe(0.025);

// Output Prometheus text format
let output = registry.render();
println!("{}", output);