tokio unstable

This commit is contained in:
aniketfuryrocks 2023-03-10 03:00:26 +05:30
parent 227de97fd7
commit 3b64a65893
No known key found for this signature in database
GPG Key ID: FA6BFCFAA7D4B764
1 changed files with 28 additions and 0 deletions

View File

@ -12,6 +12,18 @@ lazy_static::lazy_static! {
static ref TXS_IN_STORE: GenericGauge<prometheus::core::AtomicI64> = 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<prometheus::core::AtomicI64> = register_int_gauge!(opts!("literpc_tokio_tasks", "Tokio tasks in lite rpc")).unwrap();
static ref TOKIO_QUEUEDEPTH: GenericGauge<prometheus::core::AtomicI64> = register_int_gauge!(opts!("literpc_tokio_blocking_queue_depth", "Tokio tasks in blocking queue in lite rpc")).unwrap();
static ref TOKIO_INJQUEUEDEPTH: GenericGauge<prometheus::core::AtomicI64> = 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<prometheus::core::AtomicI64> = register_int_gauge!(opts!("literpc_tokio_blocking_threads", "Tokio blocking threads in lite rpc")).unwrap();
static ref TOKIO_NB_IDLE_THREADS: GenericGauge<prometheus::core::AtomicI64> = register_int_gauge!(opts!("literpc_tokio_idle_threads", "Tokio idle threads in lite rpc")).unwrap();
static ref TOKIO_REMOTE_SCHEDULED_COUNT: GenericGauge<prometheus::core::AtomicI64> = register_int_gauge!(opts!("literpc_tokio_remote_scheduled", "Tokio remote scheduled tasks")).unwrap();
static ref STD_THREADS: GenericGauge<prometheus::core::AtomicI64> = 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);
}
}
})
}