Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metrics delay #426

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"files.insertFinalNewline": true,
"files.trimTrailingWhitespace": true,
"rust-analyzer.cargo.features": "all", // Enable only for desktop
"rust-analyzer.check.allTargets": true,
// "rust-analyzer.cargo.target": "wasm32-unknown-unknown", // Enable only for web
// "rust-analyzer.check.noDefaultFeatures": true, // Enable for web
// "rust-analyzer.runnables.extraArgs": ["--release"], // Enable for web
Expand Down
22 changes: 20 additions & 2 deletions src/bin/bitmaskd.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
#![allow(unused_imports)]
#![cfg(feature = "server")]
#![cfg(not(target_arch = "wasm32"))]
use std::{env, fs::OpenOptions, io::ErrorKind, net::SocketAddr, str::FromStr, time::Duration};
use std::{
env,
fs::OpenOptions,
io::ErrorKind,
net::SocketAddr,
str::FromStr,
time::{Duration, Instant},
};

use amplify::hex::FromHex;
use anyhow::Result;
Expand Down Expand Up @@ -741,10 +748,21 @@ async fn periodic_metrics() -> Result<()> {
let dir = std::path::Path::new(&path);
fs::create_dir_all(dir).await?;

let metrics = metrics(dir)?;
info!("Starting metrics collection...");

let duration = Instant::now();

let metrics = metrics(dir).await?;
let metrics_json = serde_json::to_string_pretty(&metrics)?;
let metrics_csv = metrics_csv(metrics);

let duration = Instant::now() - duration;

info!(
"Finished metrics collection. Took: {} seconds",
duration.as_secs_f32()
);

fs::write(&format!("{path}/metrics.json"), &metrics_json).await?;
fs::write(&format!("{path}/metrics.csv"), &metrics_csv).await?;

Expand Down
2 changes: 2 additions & 0 deletions src/carbonado.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use bitcoin_30::secp256k1::{PublicKey, SecretKey};
use crate::{carbonado::error::CarbonadoError, constants::NETWORK, info, structs::FileMetadata};

pub mod error;

#[cfg(not(target_arch = "wasm32"))]
pub mod metrics;

#[cfg(not(target_arch = "wasm32"))]
Expand Down
12 changes: 10 additions & 2 deletions src/carbonado/metrics.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
use std::{collections::BTreeMap, path::Path, time::SystemTime};
#![cfg(not(target_arch = "wasm32"))]
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;
cryptoquick marked this conversation as resolved.
Show resolved Hide resolved

#[derive(Serialize, Deserialize, Default)]
Expand Down Expand Up @@ -37,7 +43,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<MetricsResponse> {
pub async fn metrics(dir: &Path) -> Result<MetricsResponse> {
let mut response = MetricsResponse::default();

response
Expand Down Expand Up @@ -136,6 +142,8 @@ pub fn metrics(dir: &Path) -> Result<MetricsResponse> {
rgb_transfer_files += 1;
}
}

sleep(StdDuration::from_millis(10)).await;
}

*response
Expand Down
Loading