Crate objectstore_metrics

Crate objectstore_metrics 

Source
Expand description

Metrics macros and DogStatsD initialization for Objectstore.

This crate provides three things:

  1. counter!, gauge!, and distribution! macros that preserve a concise call-site syntax ("name": value, "tag" => tag_value).
  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::{counter, distribution, gauge};

let count = 42_u64;
let elapsed = Duration::from_secs(1);
let route = "api/v1";

counter!("server.start": 1);
gauge!("server.requests.in_flight": count);
distribution!("server.requests.duration"@s: elapsed, "route" => route);

§Unit annotations

  • @s converts a Duration to seconds via .as_secs_f64().
  • @b converts the value via as f64 (identity for byte counts).
  • No annotation also converts via as f64.

Macros§

counter
Emits a counter metric.
distribution
Emits a distribution (histogram) metric.
gauge
Emits a gauge metric.

Structs§

MetricsConfig
Configuration for the DogStatsD metrics exporter.

Enums§

Error
Error type for metrics initialization.

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.