diff --git a/README.md b/README.md index 69cc800..a103d71 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ sudo apt-get install libdrm-dev libdrm-amdgpu1 Two components: -1) Agent (remote): small Rust WS server using sysinfo + /proc. It collects on demand when the client asks (fast metrics ~500 ms, processes ~2 s, disks ~5 s). No background loop when nobody is connected. +1) Agent (remote): small Rust WS server using sysinfo + /proc. It collects metrics only when the client requests them over the WebSocket (request-driven). No background sampling loop. 2) Client (local): TUI that connects to ws://HOST:PORT/ws (or wss://HOST:PORT/ws when TLS is enabled) and renders updates. diff --git a/socktop_agent/src/main.rs b/socktop_agent/src/main.rs index 2f82b3f..e68146c 100644 --- a/socktop_agent/src/main.rs +++ b/socktop_agent/src/main.rs @@ -1,10 +1,9 @@ -//! socktop agent entrypoint: sets up sysinfo handles, launches a sampler, -//! and serves a WebSocket endpoint at /ws. +//! socktop agent entrypoint: sets up sysinfo handles and serves a WebSocket endpoint at /ws. mod gpu; mod metrics; mod proto; -mod sampler; +// sampler module removed (metrics now purely request-driven) mod state; mod types; mod ws; @@ -15,7 +14,6 @@ use std::str::FromStr; mod tls; -use crate::sampler::{spawn_disks_sampler, spawn_process_sampler, spawn_sampler}; use state::AppState; fn arg_flag(name: &str) -> bool { @@ -45,13 +43,7 @@ async fn main() -> anyhow::Result<()> { let state = AppState::new(); - // Start background sampler (adjust cadence as needed) - // 500ms fast metrics - let _h_fast = spawn_sampler(state.clone(), std::time::Duration::from_millis(500)); - // 2s processes (top 50) - let _h_procs = spawn_process_sampler(state.clone(), std::time::Duration::from_secs(2), 50); - // 5s disks - let _h_disks = spawn_disks_sampler(state.clone(), std::time::Duration::from_secs(5)); + // No background samplers: metrics collected on-demand per websocket request. // Web app: route /ws to the websocket handler async fn healthz() -> StatusCode { diff --git a/socktop_agent/src/sampler.rs b/socktop_agent/src/sampler.rs deleted file mode 100644 index 4088ef4..0000000 --- a/socktop_agent/src/sampler.rs +++ /dev/null @@ -1,34 +0,0 @@ -//! Background sampler: periodically collects metrics and updates precompressed caches, -//! so WS replies just read and send cached bytes. - -use crate::state::AppState; -use tokio::task::JoinHandle; -use tokio::time::{sleep, Duration}; - -// 500ms: fast path (cpu/mem/net/temp/gpu) -pub fn spawn_sampler(_state: AppState, _period: Duration) -> JoinHandle<()> { - tokio::spawn(async move { - // no-op background sampler (request-driven collection elsewhere) - loop { - sleep(Duration::from_secs(3600)).await; - } - }) -} - -// 2s: processes top-k -pub fn spawn_process_sampler(_state: AppState, _period: Duration, _top_k: usize) -> JoinHandle<()> { - tokio::spawn(async move { - loop { - sleep(Duration::from_secs(3600)).await; - } - }) -} - -// 5s: disks -pub fn spawn_disks_sampler(_state: AppState, _period: Duration) -> JoinHandle<()> { - tokio::spawn(async move { - loop { - sleep(Duration::from_secs(3600)).await; - } - }) -}