From f335644b03433f297bfaa84a1f302f895b66f1cb Mon Sep 17 00:00:00 2001 From: _ <_@_> Date: Sun, 20 Dec 2020 17:17:31 -0600 Subject: [PATCH] :heavy_plus_sign: update: measuring CPU usage every minute --- Cargo.lock | 1 + crates/ptth_file_server_bin/Cargo.toml | 1 + crates/ptth_file_server_bin/src/main.rs | 38 ++++++-- crates/ptth_server/src/file_server/html.rs | 4 +- crates/ptth_server/src/file_server/metrics.rs | 92 ++++++++----------- crates/ptth_server/src/file_server/mod.rs | 2 +- crates/ptth_server/src/lib.rs | 4 +- handlebars/server/file_server_root.html | 2 +- 8 files changed, 78 insertions(+), 66 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 55a1d67..22360fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1653,6 +1653,7 @@ dependencies = [ "tokio", "tracing", "tracing-subscriber", + "uom", ] [[package]] diff --git a/crates/ptth_file_server_bin/Cargo.toml b/crates/ptth_file_server_bin/Cargo.toml index af3cf68..8d91c39 100644 --- a/crates/ptth_file_server_bin/Cargo.toml +++ b/crates/ptth_file_server_bin/Cargo.toml @@ -18,6 +18,7 @@ structopt = "0.3.20" tokio = { version = "0.2.22", features = ["full"] } tracing = "0.1.21" tracing-subscriber = "0.2.15" +uom = "0.30.0" ptth_core = { path = "../ptth_core" } ptth_server = { path = "../ptth_server" } diff --git a/crates/ptth_file_server_bin/src/main.rs b/crates/ptth_file_server_bin/src/main.rs index 9ae3f47..b92d6e9 100644 --- a/crates/ptth_file_server_bin/src/main.rs +++ b/crates/ptth_file_server_bin/src/main.rs @@ -97,24 +97,46 @@ async fn main () -> Result <(), anyhow::Error> { config_file.name.unwrap_or_else (|| "PTTH File Server".to_string ()) ); - let metrics_gauges = Arc::new (ArcSwap::default ()); + let metrics_interval = Arc::new (ArcSwap::default ()); - let gauge_writer = Arc::clone (&metrics_gauges); + let interval_writer = Arc::clone (&metrics_interval); tokio::spawn (async move { - let mut interval = tokio::time::interval (std::time::Duration::from_secs (2)); + use std::time::Duration; + + use uom::si::ratio::percent; + + let mut interval = tokio::time::interval (Duration::from_secs (60)); + + let mut counter = 0_u64; + let mut next_10_time = counter; + let mut metrics_at_last_10: Arc