fedimint_api_client/
metrics.rs

1use std::sync::LazyLock;
2
3use fedimint_metrics::prometheus::{
4    HistogramVec, IntCounterVec, register_histogram_vec_with_registry,
5};
6use fedimint_metrics::{REGISTRY, histogram_opts, opts, register_int_counter_vec_with_registry};
7
8/// Histogram of API request durations in seconds, labeled by method
9pub static CLIENT_API_REQUEST_DURATION_SECONDS: LazyLock<HistogramVec> = LazyLock::new(|| {
10    register_histogram_vec_with_registry!(
11        histogram_opts!(
12            "client_api_request_duration_seconds",
13            "Duration of client API requests to federation peers",
14        ),
15        &["method", "peer_id"],
16        REGISTRY
17    )
18    .expect("metric registration should not fail")
19});
20
21/// Counter of API requests made, labeled by method and peer
22pub static CLIENT_API_REQUESTS_TOTAL: LazyLock<IntCounterVec> = LazyLock::new(|| {
23    register_int_counter_vec_with_registry!(
24        opts!(
25            "client_api_requests_total",
26            "Total number of client API requests to federation peers",
27        ),
28        &["method", "peer_id", "result"],
29        REGISTRY
30    )
31    .expect("metric registration should not fail")
32});