Crate objectstore_metrics

Crate objectstore_metrics 

Source
Expand description

Metrics macros and DogStatsD initialization for Objectstore.

This crate provides three things:

  1. count!, gauge!, and record! macros with rustfmt-friendly expression-based syntax.
  2. MetricsConfig and init for wiring up a DogStatsD exporter.
  3. with_capturing_test_client for 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, i8i32, u8u32) via Into<f64>.
  • u64 and usize via an as f64 cast; values above 2^53 lose precision, which is acceptable for metric reporting.
  • Duration as 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§

MetricsConfig
Configuration for the DogStatsD metrics exporter.

Enums§

Error
Error type for metrics initialization.

Traits§

AsF64
Converts a value to f64 for metric recording.

Functions§

init
Initializes the global DogStatsD metrics exporter.
with_capturing_test_client
Runs f with a thread-local mock recorder installed, then returns all captured metrics as "name:value|type|#key:value,key:value" strings.