Report tracing_unbounded channel size to prometheus (#1489)

This commit is contained in:
Dmitry Markin
2023-09-12 14:38:31 +03:00
committed by GitHub
parent 391591b6a4
commit f5ca403af9
2 changed files with 42 additions and 12 deletions
+22 -5
View File
@@ -24,7 +24,10 @@ use prometheus::{
Error as PrometheusError, Registry,
};
use prometheus::{core::GenericCounterVec, Opts};
use prometheus::{
core::{GenericCounterVec, GenericGaugeVec},
Opts,
};
lazy_static! {
pub static ref TOKIO_THREADS_TOTAL: GenericCounter<AtomicU64> =
@@ -36,18 +39,32 @@ lazy_static! {
}
lazy_static! {
pub static ref UNBOUNDED_CHANNELS_COUNTER : GenericCounterVec<AtomicU64> = GenericCounterVec::new(
Opts::new("substrate_unbounded_channel_len", "Items in each mpsc::unbounded instance"),
&["entity", "action"] // 'name of channel, send|received|dropped
pub static ref UNBOUNDED_CHANNELS_COUNTER: GenericCounterVec<AtomicU64> = GenericCounterVec::new(
Opts::new(
"substrate_unbounded_channel_len",
"Items sent/received/dropped on each mpsc::unbounded instance"
),
&["entity", "action"], // name of channel, send|received|dropped
).expect("Creating of statics doesn't fail. qed");
pub static ref UNBOUNDED_CHANNELS_SIZE: GenericGaugeVec<AtomicU64> = GenericGaugeVec::new(
Opts::new(
"substrate_unbounded_channel_size",
"Size (number of messages to be processed) of each mpsc::unbounded instance",
),
&["entity"], // name of channel
).expect("Creating of statics doesn't fail. qed");
}
pub static SENT_LABEL: &'static str = "send";
pub static RECEIVED_LABEL: &'static str = "received";
pub static DROPPED_LABEL: &'static str = "dropped";
/// Register the statics to report to registry
pub fn register_globals(registry: &Registry) -> Result<(), PrometheusError> {
registry.register(Box::new(TOKIO_THREADS_ALIVE.clone()))?;
registry.register(Box::new(TOKIO_THREADS_TOTAL.clone()))?;
registry.register(Box::new(UNBOUNDED_CHANNELS_COUNTER.clone()))?;
registry.register(Box::new(UNBOUNDED_CHANNELS_SIZE.clone()))?;
Ok(())
}