Skip to content

Commit

Permalink
Use a database and JSON file for persistent, multi-day, live metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
cryptoquick committed Dec 18, 2023
1 parent 003ff90 commit d8b2fad
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 33 deletions.
101 changes: 96 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ esplora_block = { version = "0.5.0", package = "esplora-client", default-feature
"blocking",
] }
inflate = "0.4.5"
sled = "0.34.7"
tower-http = { version = "0.4.4", features = ["cors"], optional = true }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
Expand Down
12 changes: 7 additions & 5 deletions src/bin/bitmaskd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,8 @@ async fn send_coins(
}

async fn json_metrics() -> Result<impl IntoResponse, AppError> {
let metrics_json = metrics::json().await?;
let dir = env::var("CARBONADO_DIR").unwrap_or("/tmp/bitmaskd/carbonado".to_owned());
let metrics_json = fs::read_to_string(&format!("{dir}/metrics.json")).await?;

Ok((
StatusCode::OK,
Expand All @@ -734,14 +735,15 @@ async fn json_metrics() -> Result<impl IntoResponse, AppError> {
}

async fn csv_metrics() -> Result<impl IntoResponse, AppError> {
let metrics_csv = metrics::csv().await;
let dir = env::var("CARBONADO_DIR").unwrap_or("/tmp/bitmaskd/carbonado".to_owned());
let metrics_csv = fs::read_to_string(&format!("{dir}/metrics.csv")).await?;

Ok((StatusCode::OK, [("content-type", "text/csv")], metrics_csv))
}

async fn init_metrics() -> Result<()> {
let path = env::var("CARBONADO_DIR").unwrap_or("/tmp/bitmaskd/carbonado".to_owned());
let dir = path::Path::new(&path);
let dir = env::var("CARBONADO_DIR").unwrap_or("/tmp/bitmaskd/carbonado".to_owned());
let dir = path::Path::new(&dir);

info!("Starting metrics collection...");
let duration = Instant::now();
Expand Down Expand Up @@ -822,7 +824,7 @@ async fn main() -> Result<()> {
} else {
tokio::spawn(async {
if let Err(e) = init_metrics().await {
error!("Error in periodic metrics: {e}");
error!("Error in init metrics: {e}");
}
});
}
Expand Down
Loading

0 comments on commit d8b2fad

Please sign in to comment.