polkadot_node_collation_generation/
metrics.rs1use polkadot_node_subsystem_util::metrics::{self, prometheus};
18
19#[derive(Clone)]
20pub(crate) struct MetricsInner {
21 pub(crate) collations_generated_total: prometheus::Counter<prometheus::U64>,
22 pub(crate) new_activation: prometheus::Histogram,
23 pub(crate) submit_collation: prometheus::Histogram,
24}
25
26#[derive(Default, Clone)]
28pub struct Metrics(pub(crate) Option<MetricsInner>);
29
30impl Metrics {
31 pub fn on_collation_generated(&self) {
32 if let Some(metrics) = &self.0 {
33 metrics.collations_generated_total.inc();
34 }
35 }
36
37 pub fn time_new_activation(&self) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
39 self.0.as_ref().map(|metrics| metrics.new_activation.start_timer())
40 }
41
42 pub fn time_submit_collation(&self) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
44 self.0.as_ref().map(|metrics| metrics.submit_collation.start_timer())
45 }
46}
47
48impl metrics::Metrics for Metrics {
49 fn try_register(registry: &prometheus::Registry) -> Result<Self, prometheus::PrometheusError> {
50 let metrics = MetricsInner {
51 collations_generated_total: prometheus::register(
52 prometheus::Counter::new(
53 "polkadot_parachain_collations_generated_total",
54 "Number of collations generated.",
55 )?,
56 registry,
57 )?,
58 new_activation: prometheus::register(
59 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
60 "polkadot_parachain_collation_generation_new_activations",
61 "Time spent within fn handle_new_activation",
62 ))?,
63 registry,
64 )?,
65 submit_collation: prometheus::register(
66 prometheus::Histogram::with_opts(prometheus::HistogramOpts::new(
67 "polkadot_parachain_collation_generation_submit_collation",
68 "Time spent preparing and submitting a collation to the network protocol",
69 ))?,
70 registry,
71 )?,
72 };
73 Ok(Metrics(Some(metrics)))
74 }
75}