polkadot_node_core_bitfield_signing/
metrics.rs1use polkadot_node_subsystem_util::metrics::{self, prometheus};
18
19#[derive(Clone)]
20pub(crate) struct MetricsInner {
21 pub(crate) bitfields_signed_total: prometheus::Counter<prometheus::U64>,
22 pub(crate) run: prometheus::Histogram,
23}
24
25#[derive(Default, Clone)]
27pub struct Metrics(pub(crate) Option<MetricsInner>);
28
29impl Metrics {
30 pub fn on_bitfield_signed(&self) {
31 if let Some(metrics) = &self.0 {
32 metrics.bitfields_signed_total.inc();
33 }
34 }
35
36 pub fn time_run(&self) -> Option<metrics::prometheus::prometheus::HistogramTimer> {
38 self.0.as_ref().map(|metrics| metrics.run.start_timer())
39 }
40}
41
42impl metrics::Metrics for Metrics {
43 fn try_register(registry: &prometheus::Registry) -> Result<Self, prometheus::PrometheusError> {
44 let metrics = MetricsInner {
45 bitfields_signed_total: prometheus::register(
46 prometheus::Counter::new(
47 "polkadot_parachain_bitfields_signed_total",
48 "Number of bitfields signed.",
49 )?,
50 registry,
51 )?,
52 run: prometheus::register(
53 prometheus::Histogram::with_opts(
54 prometheus::HistogramOpts::new(
55 "polkadot_parachain_bitfield_signing_run",
56 "Time spent within `bitfield_signing::run`",
57 )
58 .buckets(vec![
59 0.000625, 0.00125, 0.0025, 0.005, 0.0075, 0.01, 0.025, 0.05, 0.1, 0.25,
60 0.5, 1.0, 2.5, 5.0, 10.0,
61 ]),
62 )?,
63 registry,
64 )?,
65 };
66 Ok(Metrics(Some(metrics)))
67 }
68}