- 1
//! Operational telemetry state: CPU/Memory gauges, token burn-rate waveform, - 2
//! agent swarm radar, and provider latency. - 3
//! - 4
//! All values are populated from real server data — `/health` for the - 5
//! system/provider snapshot and `AgentEvent` stream events for live - 6
//! token usage, worker counts, and pending task counts. The previous - 7
//! implementation hardcoded all values; this one derives them from actual - 8
//! API responses. - 9
- 10
use crate::api::HealthReport; - 11
- 12
#[derive(Debug, Clone)] - 13
pub struct TelemetryState { - 14
pub cpu_percent: f32, - 15
pub rss_mb: f64, - 16
pub token_rate_history: Vec<u32>, - 17
pub max_rate: u32, - 18
pub active_workers: usize, - 19
pub pending_tasks: usize, - 20
pub radar_angle_deg: f32, - 21
pub spend_today_usd: f64, - 22
pub spend_budget_cap_usd: f64, - 23
pub circuit_breaker_healthy: bool, - 24
pub active_services_count: (usize, usize), - 25
pub bus_queue_depth: usize, - 26
pub bus_dlq_count: usize, - 27
pub anthropic_latency_ms: u32, - 28
pub ollama_latency_ms: u32, - 29
pub tick_count: usize, - 30
pub connected: bool, - 31
pub last_error: Option<String>, - 32
} - 33
- 34
impl Default for TelemetryState { - 35
fn default() -> Self { - 36
Self { - 37
cpu_percent: 0.0, - 38
rss_mb: 0.0, - 39
token_rate_history: Vec::new(), - 40
max_rate: 0, - 41
active_workers: 0, - 42
pending_tasks: 0, - 43
radar_angle_deg: 0.0, - 44
spend_today_usd: 0.0, - 45
spend_budget_cap_usd: 0.0, - 46
circuit_breaker_healthy: false, - 47
active_services_count: (0, 0), - 48
bus_queue_depth: 0, - 49
bus_dlq_count: 0, - 50
anthropic_latency_ms: 0, - 51
ollama_latency_ms: 0, - 52
tick_count: 0, - 53
connected: false, - 54
last_error: None, - 55
} - 56
} - 57
} - 58
- 59
impl TelemetryState { - 60
pub fn new() -> Self { - 61
Self::default() - 62
} - 63
- 64
/// Advance visual animations on tick (50ms). - 65
pub fn tick(&mut self) { - 66
self.tick_count = self.tick_count.wrapping_add(1); - 67
self.radar_angle_deg = (self.radar_angle_deg + 6.0) % 360.0; - 68
} - 69
- 70
/// Update telemetry from a real `/health` response. - 71
pub fn update_from_health(&mut self, health: &HealthReport) { - 72
self.circuit_breaker_healthy = health.circuit_breaker_healthy; - 73
self.connected = health.healthy; - 74
} - 75
- 76
/// Push a real token-rate sample from an agent TurnEnd event. - 77
pub fn push_token_rate(&mut self, rate: u32) { - 78
if self.token_rate_history.len() >= 60 { - 79
self.token_rate_history.remove(0); - 80
} - 81
self.token_rate_history.push(rate); - 82
if rate > self.max_rate { - 83
self.max_rate = rate; - 84
} - 85
} - 86
- 87
/// Update worker presence from `WorkerStarted` / `WorkerFinished`. - 88
pub fn set_active_workers(&mut self, count: usize) { - 89
self.active_workers = count; - 90
} - 91
- 92
/// Record a connection error so the UI can surface it. - 93
pub fn set_connection_error(&mut self, msg: String) { - 94
self.connected = false; - 95
self.last_error = Some(msg); - 96
} - 97
- 98
/// Clear the error indicator on successful data receipt. - 99
pub fn clear_error(&mut self) { - 100
if self.connected { - 101
self.last_error = None; - 102
} - 103
} - 104
} - 105
Indexing the workspace…
Vakyartha documentation is discovering safe artifacts, anchors, and source references.