polkadot_node_core_av_store/
metrics.rs1use polkadot_node_subsystem_util::metrics::{self, prometheus};
18
19#[derive(Clone)]
20pub(crate) struct MetricsInner {
21 received_availability_chunks_total: prometheus::Counter<prometheus::U64>,
22 pruning: prometheus::Histogram,
23 process_block_finalized: prometheus::Histogram,
24 block_activated: prometheus::Histogram,
25 process_message: prometheus::Histogram,
26 store_available_data: prometheus::Histogram,
27 store_chunk: prometheus::Histogram,
28 get_chunk: prometheus::Histogram,
29}
30
31#[derive(Default, Clone)]
33pub struct Metrics(Option<MetricsInner>);
34
35impl Metrics {
36 pub(crate) fn on_chunks_received(&self, count: usize) {
37 if let Some(metrics) = &self.0 {
38 let by = u64::try_from(count).unwrap_or_default();
40 metrics.received_availability_chunks_total.inc_by(by);
41 }
42 }
43
44 pub(crate) fn time_pruning(&self) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
46 self.0.as_ref().map(|metrics| metrics.pruning.start_timer())
47 }
48
49 pub(crate) fn time_process_block_finalized(
51 &self,
52 ) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
53 self.0.as_ref().map(|metrics| metrics.process_block_finalized.start_timer())
54 }
55
56 pub(crate) fn time_block_activated(
58 &self,
59 ) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
60 self.0.as_ref().map(|metrics| metrics.block_activated.start_timer())
61 }
62
63 pub(crate) fn time_process_message(
65 &self,
66 ) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
67 self.0.as_ref().map(|metrics| metrics.process_message.start_timer())
68 }
69
70 pub(crate) fn time_store_available_data(
72 &self,
73 ) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
74 self.0.as_ref().map(|metrics| metrics.store_available_data.start_timer())
75 }
76
77 pub(crate) fn time_store_chunk(
79 &self,
80 ) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
81 self.0.as_ref().map(|metrics| metrics.store_chunk.start_timer())
82 }
83
84 pub(crate) fn time_get_chunk(&self) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
86 self.0.as_ref().map(|metrics| metrics.get_chunk.start_timer())
87 }
88}
89
90impl metrics::Metrics for Metrics {
91 fn try_register(registry: &prometheus::Registry) -> Result<Self, prometheus::PrometheusError> {
92 let metrics = MetricsInner {
93 received_availability_chunks_total: prometheus::register(
94 prometheus::Counter::new(
95 "polkadot_parachain_received_availability_chunks_total",
96 "Number of availability chunks received.",
97 )?,
98 registry,
99 )?,
100 pruning: prometheus::register(
101 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
102 "polkadot_parachain_av_store_pruning",
103 "Time spent within `av_store::prune_all`",
104 ))?,
105 registry,
106 )?,
107 process_block_finalized: prometheus::register(
108 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
109 "polkadot_parachain_av_store_process_block_finalized",
110 "Time spent within `av_store::process_block_finalized`",
111 ))?,
112 registry,
113 )?,
114 block_activated: prometheus::register(
115 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
116 "polkadot_parachain_av_store_block_activated",
117 "Time spent within `av_store::process_block_activated`",
118 ))?,
119 registry,
120 )?,
121 process_message: prometheus::register(
122 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
123 "polkadot_parachain_av_store_process_message",
124 "Time spent within `av_store::process_message`",
125 ))?,
126 registry,
127 )?,
128 store_available_data: prometheus::register(
129 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
130 "polkadot_parachain_av_store_store_available_data",
131 "Time spent within `av_store::store_available_data`",
132 ))?,
133 registry,
134 )?,
135 store_chunk: prometheus::register(
136 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
137 "polkadot_parachain_av_store_store_chunk",
138 "Time spent within `av_store::store_chunk`",
139 ))?,
140 registry,
141 )?,
142 get_chunk: prometheus::register(
143 prometheus::Histogram::with_opts(
144 prometheus::HistogramOpts::new(
145 "polkadot_parachain_av_store_get_chunk",
146 "Time spent fetching requested chunks.`",
147 )
148 .buckets(vec![
149 0.000625, 0.00125, 0.0025, 0.005, 0.0075, 0.01, 0.025, 0.05, 0.1, 0.25,
150 0.5, 1.0, 2.5, 5.0, 10.0,
151 ]),
152 )?,
153 registry,
154 )?,
155 };
156 Ok(Metrics(Some(metrics)))
157 }
158}