risingwave_storage/monitor/
hummock_metrics.rs1use std::sync::LazyLock;
16
17use prometheus::core::{AtomicU64, GenericCounter};
18use prometheus::{
19 Histogram, Registry, exponential_buckets, histogram_opts, register_histogram_with_registry,
20 register_int_counter_with_registry,
21};
22use risingwave_common::monitor::GLOBAL_METRICS_REGISTRY;
23
24#[derive(Debug, Clone)]
26pub struct HummockMetrics {
27 pub get_new_sst_ids_counts: GenericCounter<AtomicU64>,
28 pub report_compaction_task_counts: GenericCounter<AtomicU64>,
29 pub get_new_sst_ids_latency: Histogram,
30 pub report_compaction_task_latency: Histogram,
31}
32
33pub static GLOBAL_HUMMOCK_METRICS: LazyLock<HummockMetrics> =
34 LazyLock::new(|| HummockMetrics::new(&GLOBAL_METRICS_REGISTRY));
35
36impl HummockMetrics {
37 fn new(registry: &Registry) -> Self {
38 let get_new_sst_ids_counts = register_int_counter_with_registry!(
40 "state_store_get_new_sst_ids_counts",
41 "Total number of get_new_table_id requests that have been issued to state store",
42 registry
43 )
44 .unwrap();
45 let report_compaction_task_counts = register_int_counter_with_registry!(
46 "state_store_report_compaction_task_counts",
47 "Total number of report_compaction_task requests that have been issued to state store",
48 registry
49 )
50 .unwrap();
51
52 let time_buckets = exponential_buckets(0.01, 10.0, 7).unwrap();
54 let get_new_sst_ids_latency_opts = histogram_opts!(
58 "state_store_get_new_sst_ids_latency",
59 "Total latency of get new table id that have been issued to state store",
60 time_buckets.clone()
61 );
62 let get_new_sst_ids_latency =
63 register_histogram_with_registry!(get_new_sst_ids_latency_opts, registry).unwrap();
64
65 let report_compaction_task_latency_opts = histogram_opts!(
67 "state_store_report_compaction_task_latency",
68 "Total latency of report compaction task that have been issued to state store",
69 time_buckets
70 );
71 let report_compaction_task_latency =
72 register_histogram_with_registry!(report_compaction_task_latency_opts, registry)
73 .unwrap();
74
75 Self {
76 get_new_sst_ids_counts,
77 report_compaction_task_counts,
78 get_new_sst_ids_latency,
79 report_compaction_task_latency,
80 }
81 }
82
83 pub fn unused() -> Self {
85 GLOBAL_HUMMOCK_METRICS.clone()
86 }
87}