polkadot_availability_bitfield_distribution/
metrics.rs1use polkadot_node_subsystem_util::metrics::{prometheus, Metrics as MetricsTrait};
18
19#[derive(Clone)]
20struct MetricsInner {
21 sent_own_availability_bitfields: prometheus::Counter<prometheus::U64>,
22 received_availability_bitfields: prometheus::Counter<prometheus::U64>,
23 active_leaves_update: prometheus::Histogram,
24 handle_bitfield_distribution: prometheus::Histogram,
25 handle_network_msg: prometheus::Histogram,
26}
27
28#[derive(Default, Clone)]
30pub struct Metrics(Option<MetricsInner>);
31
32impl Metrics {
33 pub(crate) fn on_own_bitfield_sent(&self) {
34 if let Some(metrics) = &self.0 {
35 metrics.sent_own_availability_bitfields.inc();
36 }
37 }
38
39 pub(crate) fn on_bitfield_received(&self) {
40 if let Some(metrics) = &self.0 {
41 metrics.received_availability_bitfields.inc();
42 }
43 }
44
45 pub(crate) fn time_active_leaves_update(
47 &self,
48 ) -> Option<prometheus::prometheus::HistogramTimer> {
49 self.0.as_ref().map(|metrics| metrics.active_leaves_update.start_timer())
50 }
51
52 pub(crate) fn time_handle_bitfield_distribution(
54 &self,
55 ) -> Option<prometheus::prometheus::HistogramTimer> {
56 self.0
57 .as_ref()
58 .map(|metrics| metrics.handle_bitfield_distribution.start_timer())
59 }
60
61 pub(crate) fn time_handle_network_msg(&self) -> Option<prometheus::prometheus::HistogramTimer> {
63 self.0.as_ref().map(|metrics| metrics.handle_network_msg.start_timer())
64 }
65}
66
67impl MetricsTrait for Metrics {
68 fn try_register(registry: &prometheus::Registry) -> Result<Self, prometheus::PrometheusError> {
69 let metrics = MetricsInner {
70 sent_own_availability_bitfields: prometheus::register(
71 prometheus::Counter::new(
72 "polkadot_parachain_sent_own_availability_bitfields_total",
73 "Number of own availability bitfields sent to other peers.",
74 )?,
75 registry,
76 )?,
77 received_availability_bitfields: prometheus::register(
78 prometheus::Counter::new(
79 "polkadot_parachain_received_availability_bitfields_total",
80 "Number of valid availability bitfields received from other peers.",
81 )?,
82 registry,
83 )?,
84 active_leaves_update: prometheus::register(
85 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
86 "polkadot_parachain_bitfield_distribution_active_leaves_update",
87 "Time spent within `bitfield_distribution::active_leaves_update`",
88 ))?,
89 registry,
90 )?,
91 handle_bitfield_distribution: prometheus::register(
92 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
93 "polkadot_parachain_bitfield_distribution_handle_bitfield_distribution",
94 "Time spent within `bitfield_distribution::handle_bitfield_distribution`",
95 ))?,
96 registry,
97 )?,
98 handle_network_msg: prometheus::register(
99 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
100 "polkadot_parachain_bitfield_distribution_handle_network_msg",
101 "Time spent within `bitfield_distribution::handle_network_msg`",
102 ))?,
103 registry,
104 )?,
105 };
106 Ok(Metrics(Some(metrics)))
107 }
108}