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