sui_storage/
key_value_store_metrics.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0

use prometheus::{
    register_histogram_vec_with_registry, register_int_counter_vec_with_registry, HistogramVec,
    IntCounterVec, Registry,
};
use std::sync::Arc;

pub struct KeyValueStoreMetrics {
    pub key_value_store_num_fetches_success: IntCounterVec,
    pub key_value_store_num_fetches_not_found: IntCounterVec,
    pub key_value_store_num_fetches_error: IntCounterVec,

    pub key_value_store_num_fetches_latency_ms: HistogramVec,
    pub key_value_store_num_fetches_batch_size: HistogramVec,
}

impl KeyValueStoreMetrics {
    pub fn new(registry: &Registry) -> Arc<Self> {
        Arc::new(Self {
            key_value_store_num_fetches_success: register_int_counter_vec_with_registry!(
                "key_value_store_num_fetches_success",
                "Number of successful fetches from key value store",
                &["store", "type"],
                registry,
            )
            .unwrap(),
            key_value_store_num_fetches_not_found: register_int_counter_vec_with_registry!(
                "key_value_store_num_fetches_not_found",
                "Number of fetches from key value store that returned not found",
                &["store", "type"],
                registry,
            )
            .unwrap(),
            key_value_store_num_fetches_error: register_int_counter_vec_with_registry!(
                "key_value_store_num_fetches_error",
                "Number of fetches from key value store that returned an error",
                &["store", "type"],
                registry,
            )
            .unwrap(),

            key_value_store_num_fetches_latency_ms: register_histogram_vec_with_registry!(
                "key_value_store_num_fetches_latency_ms",
                "Latency of fetches from key value store",
                &["store", "type"],
                prometheus::exponential_buckets(1.0, 1.6, 24)
                    .unwrap()
                    .to_vec(),
                registry,
            )
            .unwrap(),

            key_value_store_num_fetches_batch_size: register_histogram_vec_with_registry!(
                "key_value_store_num_fetches_batch_size",
                "Number of keys fetched per batch",
                &["store", "type"],
                prometheus::exponential_buckets(1.0, 1.6, 20)
                    .unwrap()
                    .to_vec(),
                registry,
            )
            .unwrap(),
        })
    }

    pub fn new_for_tests() -> Arc<Self> {
        Self::new(&Registry::new())
    }
}