feat(trading_service): wire monitoring to real uptime and kill switch status
Replace hardcoded uptime (3600s) with real elapsed time tracked via Instant::now() in MonitoringServiceImpl constructor. Surface live kill switch state (active, emergency, unhealthy) as critical_issues strings in GetSystemStatusResponse. Set sysinfo-dependent CPU/memory/disk/network metrics to 0.0 with TODO comments pending sysinfo crate integration. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -12,18 +12,24 @@ use crate::proto::monitoring::{
|
||||
SystemStatusEvent, ThroughputMetric,
|
||||
};
|
||||
use crate::state::{HealthStatus, TradingServiceState};
|
||||
use std::time::Instant;
|
||||
use tonic::{Request, Response, Status};
|
||||
|
||||
/// Monitoring service implementation
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct MonitoringServiceImpl {
|
||||
state: TradingServiceState,
|
||||
/// Tracks when this service instance was started for real uptime reporting
|
||||
started_at: Instant,
|
||||
}
|
||||
|
||||
impl MonitoringServiceImpl {
|
||||
/// Create new monitoring service
|
||||
pub fn new(state: TradingServiceState) -> Self {
|
||||
Self { state }
|
||||
Self {
|
||||
state,
|
||||
started_at: Instant::now(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,17 +127,42 @@ impl MonitoringService for MonitoringServiceImpl {
|
||||
HealthStatus::Critical => SystemHealth::Critical,
|
||||
};
|
||||
|
||||
// Real uptime measured from service construction (cast to i64 to match proto int64 field)
|
||||
let uptime_seconds = self.started_at.elapsed().as_secs() as i64;
|
||||
|
||||
// Check kill switch status and surface any active triggers as critical issues
|
||||
let mut critical_issues: Vec<String> = vec![];
|
||||
if let Some(kill_switch) = &self.state.kill_switch_system {
|
||||
match kill_switch.get_status().await {
|
||||
Ok(ks_status) => {
|
||||
if ks_status.is_active {
|
||||
critical_issues
|
||||
.push("Kill switch is ACTIVE — trading halted".to_string());
|
||||
}
|
||||
if ks_status.is_emergency_active {
|
||||
critical_issues.push("Emergency shutdown is ACTIVE".to_string());
|
||||
}
|
||||
if !ks_status.is_healthy {
|
||||
critical_issues.push("Kill switch system is UNHEALTHY".to_string());
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
critical_issues.push("Kill switch status unavailable".to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let system_status = SystemStatus {
|
||||
overall_health: overall_health as i32,
|
||||
healthy_services: 3,
|
||||
total_services: 3,
|
||||
critical_issues: vec![],
|
||||
system_uptime_seconds: 3600, // Placeholder
|
||||
critical_issues,
|
||||
system_uptime_seconds: uptime_seconds,
|
||||
system_metrics: Some(SystemMetrics {
|
||||
cpu_usage_percent: 15.0,
|
||||
memory_usage_percent: 45.0,
|
||||
disk_usage_percent: 30.0,
|
||||
network_io_mbps: 10.0,
|
||||
cpu_usage_percent: 0.0, // TODO: wire to sysinfo crate
|
||||
memory_usage_percent: 0.0, // TODO: wire to sysinfo crate
|
||||
disk_usage_percent: 0.0, // TODO: wire to sysinfo crate
|
||||
network_io_mbps: 0.0, // TODO: wire to sysinfo crate
|
||||
active_connections: 25,
|
||||
total_requests: 1000,
|
||||
avg_response_time_ms: 2.5,
|
||||
@@ -145,7 +176,7 @@ impl MonitoringService for MonitoringServiceImpl {
|
||||
state: ServiceState::Running as i32,
|
||||
version: Some("1.0.0".to_string()),
|
||||
error_message: None,
|
||||
uptime_seconds: 3600,
|
||||
uptime_seconds,
|
||||
last_health_check: chrono::Utc::now().timestamp(),
|
||||
metadata: std::collections::HashMap::new(),
|
||||
dependencies: vec![],
|
||||
|
||||
Reference in New Issue
Block a user