polkadot_node_core_prospective_parachains/
metrics.rs1use polkadot_node_subsystem::prometheus::Opts;
18use polkadot_node_subsystem_util::metrics::{
19 self,
20 prometheus::{self, Gauge, GaugeVec, U64},
21};
22
23#[derive(Clone)]
24pub(crate) struct MetricsInner {
25 time_active_leaves_update: prometheus::Histogram,
26 time_introduce_seconded_candidate: prometheus::Histogram,
27 time_candidate_backed: prometheus::Histogram,
28 time_hypothetical_membership: prometheus::Histogram,
29 candidate_count: prometheus::GaugeVec<U64>,
30 active_leaves_count: prometheus::GaugeVec<U64>,
31 implicit_view_candidate_count: prometheus::Gauge<U64>,
32}
33
34#[derive(Default, Clone)]
36pub struct Metrics(pub(crate) Option<MetricsInner>);
37
38impl Metrics {
39 pub fn time_handle_active_leaves_update(
41 &self,
42 ) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
43 self.0.as_ref().map(|metrics| metrics.time_active_leaves_update.start_timer())
44 }
45
46 pub fn time_introduce_seconded_candidate(
48 &self,
49 ) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
50 self.0
51 .as_ref()
52 .map(|metrics| metrics.time_introduce_seconded_candidate.start_timer())
53 }
54
55 pub fn time_candidate_backed(&self) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
57 self.0.as_ref().map(|metrics| metrics.time_candidate_backed.start_timer())
58 }
59
60 pub fn time_hypothetical_membership_request(
62 &self,
63 ) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
64 self.0
65 .as_ref()
66 .map(|metrics| metrics.time_hypothetical_membership.start_timer())
67 }
68
69 pub fn record_candidate_count(&self, connected_count: u64, unconnected_count: u64) {
72 self.0.as_ref().map(|metrics| {
73 metrics.candidate_count.with_label_values(&["connected"]).set(connected_count);
74 metrics
75 .candidate_count
76 .with_label_values(&["unconnected"])
77 .set(unconnected_count);
78 });
79 }
80
81 pub fn record_candidate_count_in_implicit_view(&self, count: u64) {
83 self.0.as_ref().map(|metrics| {
84 metrics.implicit_view_candidate_count.set(count);
85 });
86 }
87
88 pub fn record_leaves_count(&self, active_count: u64, inactive_count: u64) {
90 self.0.as_ref().map(|metrics| {
91 metrics.active_leaves_count.with_label_values(&["active"]).set(active_count);
92 metrics.active_leaves_count.with_label_values(&["inactive"]).set(inactive_count);
93 });
94 }
95}
96
97impl metrics::Metrics for Metrics {
98 fn try_register(registry: &prometheus::Registry) -> Result<Self, prometheus::PrometheusError> {
99 let metrics = MetricsInner {
100 time_active_leaves_update: prometheus::register(
101 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
102 "polkadot_parachain_prospective_parachains_time_active_leaves_update",
103 "Time spent within `prospective_parachains::handle_active_leaves_update`",
104 ))?,
105 registry,
106 )?,
107 time_introduce_seconded_candidate: prometheus::register(
108 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
109 "polkadot_parachain_prospective_parachains_time_introduce_seconded_candidate",
110 "Time spent within `prospective_parachains::handle_introduce_seconded_candidate`",
111 ))?,
112 registry,
113 )?,
114 time_candidate_backed: prometheus::register(
115 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
116 "polkadot_parachain_prospective_parachains_time_candidate_backed",
117 "Time spent within `prospective_parachains::handle_candidate_backed`",
118 ))?,
119 registry,
120 )?,
121 time_hypothetical_membership: prometheus::register(
122 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
123 "polkadot_parachain_prospective_parachains_time_hypothetical_membership",
124 "Time spent responding to `GetHypotheticalMembership`",
125 ))?,
126 registry,
127 )?,
128 candidate_count: prometheus::register(
129 GaugeVec::new(
130 Opts::new(
131 "polkadot_parachain_prospective_parachains_candidate_count",
132 "Number of candidates present across all fragment chains, split by connected and unconnected"
133 ),
134 &["type"],
135 )?,
136 registry,
137 )?,
138 active_leaves_count: prometheus::register(
139 GaugeVec::new(
140 Opts::new(
141 "polkadot_parachain_prospective_parachains_active_leaves_count",
142 "Number of leaves kept by the subsystem, split by active/inactive"
143 ),
144 &["type"],
145 )?,
146 registry,
147 )?,
148 implicit_view_candidate_count: prometheus::register(
149 Gauge::new(
150 "polkadot_parachain_prospective_parachains_implicit_view_candidate_count",
151 "Number of candidates present in the implicit view"
152 )?,
153 registry
154 )?,
155 };
156 Ok(Metrics(Some(metrics)))
157 }
158}