Release highlights Introduced split client/agent architecture with a ratatui-based TUI and a lightweight WebSocket agent. Added adaptive (idle-aware) sampler: agent samples fast only when clients are connected; sleeps when idle. Implemented metrics JSON caching for instant ws replies; cold-start does one-off collection. Port configuration: --port/-p, positional PORT, or SOCKTOP_PORT env (default 3000). Optional token auth: SOCKTOP_TOKEN on agent, ws://HOST:PORT/ws?token=VALUE in client. Logging via tracing with RUST_LOG control. CI workflow (fmt, clippy, build) for Linux and Windows. Systemd unit example for always-on agent. TUI features CPU: overall sparkline + per-core history with trend arrows and color thresholds. Memory/Swap gauges with humanized labels. Disks panel with per-device usage and icons. Network download/upload sparklines (KB/s) with peak tracking. Top processes table (PID, name, CPU%, mem, mem%). Header with hostname and CPU temperature indicator. Agent changes sysinfo 0.36.1 targeted refresh: refresh_cpu_all, refresh_memory, refresh_processes_specifics(ProcessesToUpdate::All, ProcessRefreshKind::new().with_cpu().with_memory(), true). WebSocket handler: client counting with wake notifications, cold-start handling, proper Response returns. Sampler uses MissedTickBehavior::Skip to avoid catch-up bursts. Docs README updates: running instructions, port configuration, optional token auth, platform notes, example JSON. Added socktop-agent.service systemd unit. Platform notes Linux (AMD/Intel) supported; tested on AMD, targeting Intel next. Raspberry Pi supported (availability of temps varies by model). Windows builds/run; CPU temperature may be unavailable (shows N/A). Known/next Roadmap includes configurable refresh interval, TUI filtering/sorting, TLS/WSS, and export to file. Add Context... README.md
36 lines
1.2 KiB
Rust
36 lines
1.2 KiB
Rust
//! Background sampler: periodically collects metrics and updates a JSON cache,
|
|
//! so WS replies are just a read of the cached string.
|
|
|
|
use crate::metrics::collect_metrics;
|
|
use crate::state::AppState;
|
|
//use serde_json::to_string;
|
|
use tokio::task::JoinHandle;
|
|
use tokio::time::{Duration, interval, MissedTickBehavior};
|
|
|
|
pub fn spawn_sampler(state: AppState, period: Duration) -> JoinHandle<()> {
|
|
tokio::spawn(async move {
|
|
let idle_period = Duration::from_secs(10);
|
|
loop {
|
|
let active = state.client_count.load(std::sync::atomic::Ordering::Relaxed) > 0;
|
|
let mut ticker = interval(if active { period } else { idle_period });
|
|
ticker.set_missed_tick_behavior(MissedTickBehavior::Skip);
|
|
ticker.tick().await;
|
|
|
|
if !active {
|
|
tokio::select! {
|
|
_ = ticker.tick() => {},
|
|
_ = state.wake_sampler.notified() => continue,
|
|
}
|
|
}
|
|
|
|
if let Ok(json) = async {
|
|
let m = collect_metrics(&state).await;
|
|
serde_json::to_string(&m)
|
|
}
|
|
.await
|
|
{
|
|
*state.last_json.write().await = json;
|
|
}
|
|
}
|
|
})
|
|
} |