diff --git a/src/bin/bitmaskd.rs b/src/bin/bitmaskd.rs index c5e121b9..4cc4faa9 100644 --- a/src/bin/bitmaskd.rs +++ b/src/bin/bitmaskd.rs @@ -741,7 +741,7 @@ async fn periodic_metrics() -> Result<()> { let dir = std::path::Path::new(&path); fs::create_dir_all(dir).await?; - let metrics = metrics(dir)?; + let metrics = metrics(dir).await?; let metrics_json = serde_json::to_string_pretty(&metrics)?; let metrics_csv = metrics_csv(metrics); diff --git a/src/carbonado/metrics.rs b/src/carbonado/metrics.rs index 4c712e85..833506ae 100644 --- a/src/carbonado/metrics.rs +++ b/src/carbonado/metrics.rs @@ -1,8 +1,13 @@ -use std::{collections::BTreeMap, path::Path, time::SystemTime}; +use std::{ + collections::BTreeMap, + path::Path, + time::{Duration as StdDuration, SystemTime}, +}; use anyhow::Result; use chrono::{DateTime, Duration, NaiveDate, Utc}; use serde::{Deserialize, Serialize}; +use tokio::time::sleep; use walkdir::WalkDir; #[derive(Serialize, Deserialize, Default)] @@ -37,7 +42,7 @@ const NETWORK_TOTAL: &str = "total"; const NETWORK_RGB_STOCKS: &str = "rgb_stocks"; const NETWORK_RGB_TRANSFER_FILES: &str = "rgb_transfer_files"; -pub fn metrics(dir: &Path) -> Result { +pub async fn metrics(dir: &Path) -> Result { let mut response = MetricsResponse::default(); response @@ -136,6 +141,8 @@ pub fn metrics(dir: &Path) -> Result { rgb_transfer_files += 1; } } + + sleep(StdDuration::from_millis(1)).await; } *response