use polkadot_primitives::metric_definitions::{
PARACHAIN_CREATE_INHERENT_BITFIELDS_SIGNATURE_CHECKS,
PARACHAIN_INHERENT_DATA_BITFIELDS_PROCESSED, PARACHAIN_INHERENT_DATA_CANDIDATES_PROCESSED,
PARACHAIN_INHERENT_DATA_DISPUTE_SETS_PROCESSED, PARACHAIN_INHERENT_DATA_WEIGHT,
PARACHAIN_VERIFY_DISPUTE_SIGNATURE,
};
use polkadot_runtime_metrics::{Counter, CounterVec, Histogram};
pub struct Metrics {
inherent_data_weight: CounterVec,
bitfields_processed: Counter,
candidates_processed: CounterVec,
dispute_sets_processed: CounterVec,
bitfields_signature_checks: CounterVec,
signature_timings: Histogram,
}
impl Metrics {
pub fn on_before_filter(&self, value: u64) {
self.inherent_data_weight.with_label_values(&["before-filter"]).inc_by(value);
}
pub fn on_after_filter(&self, value: u64) {
self.inherent_data_weight.with_label_values(&["after-filter"]).inc_by(value);
}
pub fn on_bitfields_processed(&self, value: u64) {
self.bitfields_processed.inc_by(value);
}
pub fn on_candidates_included(&self, value: u64) {
self.candidates_processed.with_label_values(&["included"]).inc_by(value);
}
pub fn on_candidates_sanitized(&self, value: u64) {
self.candidates_processed.with_label_values(&["sanitized"]).inc_by(value);
}
pub fn on_candidates_processed_total(&self, value: u64) {
self.candidates_processed.with_label_values(&["total"]).inc_by(value);
}
pub fn on_relay_chain_freeze(&self) {
self.dispute_sets_processed.with_label_values(&["frozen"]).inc();
}
pub fn on_disputes_concluded_invalid(&self, value: u64) {
self.dispute_sets_processed
.with_label_values(&["concluded_invalid"])
.inc_by(value);
}
pub fn on_disputes_imported(&self, value: u64) {
self.dispute_sets_processed.with_label_values(&["imported"]).inc_by(value);
}
pub fn on_valid_bitfield_signature(&self) {
self.bitfields_signature_checks.with_label_values(&["valid"]).inc_by(1);
}
pub fn on_invalid_bitfield_signature(&self) {
self.bitfields_signature_checks.with_label_values(&["invalid"]).inc_by(1);
}
pub fn on_signature_check_complete(&self, val: u128) {
self.signature_timings.observe(val);
}
}
pub const METRICS: Metrics = Metrics {
inherent_data_weight: CounterVec::new(PARACHAIN_INHERENT_DATA_WEIGHT),
bitfields_processed: Counter::new(PARACHAIN_INHERENT_DATA_BITFIELDS_PROCESSED),
candidates_processed: CounterVec::new(PARACHAIN_INHERENT_DATA_CANDIDATES_PROCESSED),
dispute_sets_processed: CounterVec::new(PARACHAIN_INHERENT_DATA_DISPUTE_SETS_PROCESSED),
bitfields_signature_checks: CounterVec::new(
PARACHAIN_CREATE_INHERENT_BITFIELDS_SIGNATURE_CHECKS,
),
signature_timings: Histogram::new(PARACHAIN_VERIFY_DISPUTE_SIGNATURE),
};