Skip to content

Commit

Permalink
feat(cli): add metrics sample interval cli arg
Browse files Browse the repository at this point in the history
  • Loading branch information
dancoombs committed Nov 9, 2023
1 parent 809e6b7 commit 4483aa9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
7 changes: 4 additions & 3 deletions bin/rundler/src/cli/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Item = &'a String>,
) -> anyhow::Result<()> {
Expand All @@ -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 {
Expand Down
17 changes: 16 additions & 1 deletion bin/rundler/src/cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand Down Expand Up @@ -340,6 +345,16 @@ pub struct MetricsArgs {
global = true
)]
tags: Vec<String>,

/// 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
Expand Down
2 changes: 2 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4483aa9

Please sign in to comment.