1use prometheus::{
21 core::{AtomicU64, GenericCounter, GenericGauge},
22 Error as PrometheusError, Registry,
23};
24use std::sync::LazyLock;
25
26use prometheus::{
27 core::{GenericCounterVec, GenericGaugeVec},
28 Opts,
29};
30
31pub static TOKIO_THREADS_TOTAL: LazyLock<GenericCounter<AtomicU64>> = LazyLock::new(|| {
32 GenericCounter::new("substrate_tokio_threads_total", "Total number of threads created")
33 .expect("Creating of statics doesn't fail. qed")
34});
35
36pub static TOKIO_THREADS_ALIVE: LazyLock<GenericGauge<AtomicU64>> = LazyLock::new(|| {
37 GenericGauge::new("substrate_tokio_threads_alive", "Number of threads alive right now")
38 .expect("Creating of statics doesn't fail. qed")
39});
40
41pub static UNBOUNDED_CHANNELS_COUNTER: LazyLock<GenericCounterVec<AtomicU64>> =
42 LazyLock::new(|| {
43 GenericCounterVec::new(
44 Opts::new(
45 "substrate_unbounded_channel_len",
46 "Items sent/received/dropped on each mpsc::unbounded instance",
47 ),
48 &["entity", "action"], )
50 .expect("Creating of statics doesn't fail. qed")
51 });
52
53pub static UNBOUNDED_CHANNELS_SIZE: LazyLock<GenericGaugeVec<AtomicU64>> = LazyLock::new(|| {
54 GenericGaugeVec::new(
55 Opts::new(
56 "substrate_unbounded_channel_size",
57 "Size (number of messages to be processed) of each mpsc::unbounded instance",
58 ),
59 &["entity"], )
61 .expect("Creating of statics doesn't fail. qed")
62});
63
64pub static SENT_LABEL: &'static str = "send";
65pub static RECEIVED_LABEL: &'static str = "received";
66pub static DROPPED_LABEL: &'static str = "dropped";
67
68pub fn register_globals(registry: &Registry) -> Result<(), PrometheusError> {
70 registry.register(Box::new(TOKIO_THREADS_ALIVE.clone()))?;
71 registry.register(Box::new(TOKIO_THREADS_TOTAL.clone()))?;
72 registry.register(Box::new(UNBOUNDED_CHANNELS_COUNTER.clone()))?;
73 registry.register(Box::new(UNBOUNDED_CHANNELS_SIZE.clone()))?;
74
75 Ok(())
76}