From 4483aa9575b0a4b213a005ed84913d3ce57187a5 Mon Sep 17 00:00:00 2001 From: dancoombs Date: Thu, 9 Nov 2023 11:24:30 -0600 Subject: [PATCH] feat(cli): add metrics sample interval cli arg --- bin/rundler/src/cli/metrics.rs | 7 ++++--- bin/rundler/src/cli/mod.rs | 17 ++++++++++++++++- docs/cli.md | 2 ++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/bin/rundler/src/cli/metrics.rs b/bin/rundler/src/cli/metrics.rs index 05b976b27..1b5c04866 100644 --- a/bin/rundler/src/cli/metrics.rs +++ b/bin/rundler/src/cli/metrics.rs @@ -20,6 +20,7 @@ use metrics_process::Collector; use metrics_util::layers::{PrefixLayer, Stack}; pub fn initialize<'a>( + sample_interval_millis: u64, listen_addr: SocketAddr, tags: impl IntoIterator, ) -> anyhow::Result<()> { @@ -39,16 +40,16 @@ pub fn initialize<'a>( .push(PrefixLayer::new("rundler")) .install()?; - tokio::spawn(async { + tokio::spawn(async move { let collector = Collector::default(); loop { collector.collect(); - tokio::time::sleep(Duration::from_secs(1)).await; + tokio::time::sleep(Duration::from_millis(sample_interval_millis)).await; } }); let handle = tokio::runtime::Handle::current(); - let frequency = std::time::Duration::from_millis(500); + let frequency = std::time::Duration::from_millis(sample_interval_millis); let runtime_metrics = handle.metrics(); let runtime_monitor = tokio_metrics::RuntimeMonitor::new(&handle); tokio::spawn(async move { diff --git a/bin/rundler/src/cli/mod.rs b/bin/rundler/src/cli/mod.rs index b2b31ed64..a3608d4fc 100644 --- a/bin/rundler/src/cli/mod.rs +++ b/bin/rundler/src/cli/mod.rs @@ -41,7 +41,12 @@ pub async fn run() -> anyhow::Result<()> { tracing::info!("Parsed CLI options: {:#?}", opt); let metrics_addr = format!("{}:{}", opt.metrics.host, opt.metrics.port).parse()?; - metrics::initialize(metrics_addr, &opt.metrics.tags).context("metrics server should start")?; + metrics::initialize( + opt.metrics.sample_interval_millis, + metrics_addr, + &opt.metrics.tags, + ) + .context("metrics server should start")?; match opt.command { Command::Node(args) => node::run(args, opt.common).await?, @@ -340,6 +345,16 @@ pub struct MetricsArgs { global = true )] tags: Vec, + + /// Sample interval for sampling metrics + #[arg( + long = "metrics.sample_interval_millis", + name = "metrics.sample_interval_millis", + env = "METRICS_HOST", + default_value = "1000", + global = true + )] + sample_interval_millis: u64, } /// CLI options for logging diff --git a/docs/cli.md b/docs/cli.md index fa3596684..a6349787a 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -67,6 +67,8 @@ Options for the metrics server: - env: *METRICS_HOST* - `--metrics.tags`: Tags for metrics in the format `key1=value1,key2=value2,...`. - env: *METRICS_TAGS* +- `--metrics.sample_interval_millis`: Sample interval to use for sampling metrics. default: `1000`. + - env: *METRICS_SAMPLE_INTERVAL_MILLIS* ## Logging Options