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