Expand description
Metrics macros and DogStatsD initialization for Objectstore.
This crate provides three things:
count!,gauge!, andrecord!macros with rustfmt-friendly expression-based syntax.MetricsConfigandinitfor wiring up a DogStatsD exporter.with_capturing_test_clientfor asserting on emitted metrics in tests.
§Usage
use std::time::Duration;
use objectstore_metrics::{count, gauge, record};
let stored_size: u64 = 1024;
let elapsed = Duration::from_secs(1);
let route = "api/v1";
count!("server.start");
gauge!("server.requests.in_flight" = 42usize);
record!("server.requests.duration" = elapsed, route = route);§Tag syntax
Tags use ident = expr syntax. Tag values must implement Into<SharedString>
(i.e., &str, String, or similar). For integer or Display types, call
.to_string(). Use .as_str() methods whenever available to avoid allocation.
§AsF64 trait
AsF64 converts gauge and histogram values to f64:
- Standard numeric primitives (
f32,f64,i8–i32,u8–u32) viaInto<f64>. u64andusizevia anas f64cast; values above 2^53 lose precision, which is acceptable for metric reporting.Durationas fractional seconds via.as_secs_f64().
Macros§
- count
- Increments a counter metric.
- gauge
- Sets, increments, or decrements a gauge metric.
- record
- Records a distribution (histogram) metric.
Structs§
- Metrics
Config - Configuration for the DogStatsD metrics exporter.
Enums§
- Error
- Error type for metrics initialization.
Traits§
- AsF64
- Converts a value to
f64for metric recording.
Functions§
- init
- Initializes the global DogStatsD metrics exporter.
- with_
capturing_ test_ client - Runs
fwith a thread-local mock recorder installed, then returns all captured metrics as"name:value|type|#key:value,key:value"strings.