diff --git a/src/workers/metrics_capture.rs b/src/workers/metrics_capture.rs index aa642395..a4979c27 100644 --- a/src/workers/metrics_capture.rs +++ b/src/workers/metrics_capture.rs @@ -12,6 +12,18 @@ lazy_static::lazy_static! { static ref TXS_IN_STORE: GenericGauge = register_int_gauge!(opts!("literpc_txs_in_store", "Transactions in store")).unwrap(); } +#[cfg(all(tokio_unstable, not(loom)))] +#[cfg_attr(docsrs, doc(cfg(tokio_unstable)))] +lazy_static::lazy_static! { + static ref TOKIO_TASKS: GenericGauge = register_int_gauge!(opts!("literpc_tokio_tasks", "Tokio tasks in lite rpc")).unwrap(); + static ref TOKIO_QUEUEDEPTH: GenericGauge = register_int_gauge!(opts!("literpc_tokio_blocking_queue_depth", "Tokio tasks in blocking queue in lite rpc")).unwrap(); + static ref TOKIO_INJQUEUEDEPTH: GenericGauge = register_int_gauge!(opts!("literpc_tokio_injection_queue_depth", "Tokio tasks in injection queue in lite rpc")).unwrap(); + static ref TOKIO_NB_BLOCKING_THREADS: GenericGauge = register_int_gauge!(opts!("literpc_tokio_blocking_threads", "Tokio blocking threads in lite rpc")).unwrap(); + static ref TOKIO_NB_IDLE_THREADS: GenericGauge = register_int_gauge!(opts!("literpc_tokio_idle_threads", "Tokio idle threads in lite rpc")).unwrap(); + static ref TOKIO_REMOTE_SCHEDULED_COUNT: GenericGauge = register_int_gauge!(opts!("literpc_tokio_remote_scheduled", "Tokio remote scheduled tasks")).unwrap(); + static ref STD_THREADS: GenericGauge = register_int_gauge!(opts!("literpc_threads", "Nb of threads used by literpc")).unwrap(); +} + /// Background worker which captures metrics #[derive(Clone)] pub struct MetricsCapture { @@ -47,6 +59,10 @@ impl MetricsCapture { tokio::spawn(async move { info!("Capturing Metrics"); + #[cfg(all(tokio_unstable, not(loom)))] + #[cfg_attr(docsrs, doc(cfg(tokio_unstable)))] + info!("Metrics Tokio Unstable enabled"); + loop { one_second.tick().await; @@ -81,6 +97,18 @@ impl MetricsCapture { metrics.txs_confirmed = txs_confirmed; metrics.txs_finalized = txs_finalized; TXS_IN_STORE.set(txs_sent as i64); + + #[cfg(all(tokio_unstable, not(loom)))] + #[cfg_attr(docsrs, doc(cfg(tokio_unstable)))] + { + let metrics = tokio::runtime::Handle::current().metrics(); + TOKIO_TASKS.set(metrics.num_workers() as i64); + TOKIO_QUEUEDEPTH.set(metrics.blocking_queue_depth() as i64); + TOKIO_NB_BLOCKING_THREADS.set(metrics.num_blocking_threads() as i64); + TOKIO_NB_IDLE_THREADS.set(metrics.num_idle_blocking_threads() as i64); + TOKIO_INJQUEUEDEPTH.set(metrics.injection_queue_depth() as i64); + TOKIO_REMOTE_SCHEDULED_COUNT.set(metrics.remote_schedule_count() as i64); + } } }) }