iota_storage/
key_value_store_metrics.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use std::sync::Arc;
6
7use prometheus::{
8    HistogramVec, IntCounterVec, Registry, register_histogram_vec_with_registry,
9    register_int_counter_vec_with_registry,
10};
11
12pub struct KeyValueStoreMetrics {
13    pub key_value_store_num_fetches_success: IntCounterVec,
14    pub key_value_store_num_fetches_not_found: IntCounterVec,
15    pub key_value_store_num_fetches_error: IntCounterVec,
16
17    pub key_value_store_num_fetches_latency_ms: HistogramVec,
18    pub key_value_store_num_fetches_batch_size: HistogramVec,
19}
20
21impl KeyValueStoreMetrics {
22    pub fn new(registry: &Registry) -> Arc<Self> {
23        Arc::new(Self {
24            key_value_store_num_fetches_success: register_int_counter_vec_with_registry!(
25                "key_value_store_num_fetches_success",
26                "Number of successful fetches from key value store",
27                &["store", "type"],
28                registry,
29            )
30            .unwrap(),
31            key_value_store_num_fetches_not_found: register_int_counter_vec_with_registry!(
32                "key_value_store_num_fetches_not_found",
33                "Number of fetches from key value store that returned not found",
34                &["store", "type"],
35                registry,
36            )
37            .unwrap(),
38            key_value_store_num_fetches_error: register_int_counter_vec_with_registry!(
39                "key_value_store_num_fetches_error",
40                "Number of fetches from key value store that returned an error",
41                &["store", "type"],
42                registry,
43            )
44            .unwrap(),
45
46            key_value_store_num_fetches_latency_ms: register_histogram_vec_with_registry!(
47                "key_value_store_num_fetches_latency_ms",
48                "Latency of fetches from key value store",
49                &["store", "type"],
50                prometheus::exponential_buckets(1.0, 1.6, 24)
51                    .unwrap()
52                    .to_vec(),
53                registry,
54            )
55            .unwrap(),
56
57            key_value_store_num_fetches_batch_size: register_histogram_vec_with_registry!(
58                "key_value_store_num_fetches_batch_size",
59                "Number of keys fetched per batch",
60                &["store", "type"],
61                prometheus::exponential_buckets(1.0, 1.6, 20)
62                    .unwrap()
63                    .to_vec(),
64                registry,
65            )
66            .unwrap(),
67        })
68    }
69
70    pub fn new_for_tests() -> Arc<Self> {
71        Self::new(&Registry::new())
72    }
73}