referrerpolicy=no-referrer-when-downgrade

polkadot_node_core_bitfield_signing/
metrics.rs

1// Copyright (C) Parity Technologies (UK) Ltd.
2// This file is part of Polkadot.
3
4// Polkadot is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8
9// Polkadot is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License
15// along with Polkadot.  If not, see <http://www.gnu.org/licenses/>.
16
17use 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/// Bitfield signing metrics.
26#[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	/// Provide a timer for `prune_povs` which observes on drop.
37	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}