From d6cefddd63f718bc85c64a0c683326d1b46eaf2a Mon Sep 17 00:00:00 2001 From: Mariusz Klochowicz Date: Tue, 29 Aug 2023 17:29:36 -0700 Subject: [PATCH] chore: Add tokio metrics to the app --- Cargo.lock | 1 + mobile/native/Cargo.toml | 3 ++- mobile/native/src/api.rs | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index be87a0772..33bffa2bf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2107,6 +2107,7 @@ dependencies = [ "thiserror", "time 0.3.20", "tokio", + "tokio-metrics", "tracing", "tracing-subscriber", "trade", diff --git a/mobile/native/Cargo.toml b/mobile/native/Cargo.toml index e6c7dfdd6..0ccd57bcf 100644 --- a/mobile/native/Cargo.toml +++ b/mobile/native/Cargo.toml @@ -34,7 +34,8 @@ serde_json = "1" state = "0.5.3" thiserror = "1" time = { version = "0.3.20", features = ["formatting"] } -tokio = { version = "1.25.0", features = ["macros", "rt", "rt-multi-thread", "sync", "time"] } +tokio = { version = "1.25.0", features = ["macros", "rt", "rt-multi-thread", "sync", "time", "tracing"] } +tokio-metrics = "0.2.2" tracing = "0.1.37" tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "env-filter", "time", "json"] } trade = { path = "../../crates/trade" } diff --git a/mobile/native/src/api.rs b/mobile/native/src/api.rs index 5c263f9d8..bce687966 100644 --- a/mobile/native/src/api.rs +++ b/mobile/native/src/api.rs @@ -248,6 +248,19 @@ pub fn run( config::set(config.clone()); db::init_db(&app_dir, get_network())?; let runtime = ln_dlc::get_or_create_tokio_runtime()?; + + // TODO: Hide this behind some debug flag, it shouldn't run in production + // (or maybe log once a minute in release build?) + let handle = runtime.handle(); + let runtime_monitor = tokio_metrics::RuntimeMonitor::new(handle); + let frequency = Duration::from_secs(5); + runtime.spawn(async move { + for metrics in runtime_monitor.intervals() { + tracing::debug!(?metrics, "tokio metrics"); + tokio::time::sleep(frequency).await; + } + }); + ln_dlc::run(app_dir, seed_dir, runtime)?; let (_health, tx) = health::Health::new(config, runtime);