nerve/cli/commands/
status.rs1use clap::Args;
6use crate::cli::commands::CliCommand;
7use crate::cli::{CliConfig, CliError};
8use crate::integration::core::NerveSystem;
9
10#[derive(Args, Debug)]
12pub struct StatusCommand {
13 #[arg(short, long)]
15 pub detailed: bool,
16
17 #[arg(short, long)]
19 pub refresh: Option<u64>,
20
21 #[arg(short = 'C', long)]
23 pub critical: bool,
24}
25
26impl CliCommand for StatusCommand {
27 fn execute(&self, config: &CliConfig) -> Result<(), CliError> {
28 if config.verbose {
29 println!("๐ Executing status command...");
30 }
31
32 let system = NerveSystem::new()
34 .map_err(|e| CliError::SystemError(format!("Failed to create system: {}", e)))?;
35
36 let system_status = system.get_system_status();
38 let stats = system.get_statistics();
39
40 println!("๐ง Nerve Framework System Status");
42 println!("================================");
43 println!();
44
45 println!("๐ Overall Health: {}", system_status.overall_health);
47 println!();
48
49 println!("๐ Performance Statistics:");
51 println!(" Messages Processed: {}", stats.messages_processed);
52 println!(" Errors Encountered: {}", stats.errors_encountered);
53 println!(" Error Rate: {:.2}%", stats.error_rate_percent);
54 println!(" Memory Usage: {} bytes", stats.memory_usage_bytes);
55 println!(" Thread Utilization: {}%", stats.thread_utilization_percent);
56 println!();
57
58 println!("๐ง Component Health:");
60 println!(" Memory System: {}", system_status.memory_health);
61 println!(" Thread System: {}", system_status.thread_health);
62 println!(" Node System: {}", system_status.node_health);
63 println!(" Communication System: {}", system_status.communication_health);
64 println!();
65
66 if self.detailed {
67 self.show_detailed_status(&system, config)?;
68 }
69
70 if self.critical {
71 self.show_critical_issues(&system_status, &stats);
72 }
73
74 Ok(())
75 }
76}
77
78impl StatusCommand {
79 fn show_detailed_status(&self, system: &NerveSystem, _config: &CliConfig) -> Result<(), CliError> {
81 println!("๐ Detailed Component Status:");
82 println!("================================");
83 println!();
84
85 let memory_pool = system.memory_pool();
87 let message_buffer = system.message_buffer();
88
89 println!("๐พ Memory System:");
90 println!(" Memory Pool: {} strong references", std::sync::Arc::strong_count(memory_pool));
91 println!(" Message Buffer: {} strong references", std::sync::Arc::strong_count(message_buffer));
92 println!();
93
94 let thread_coordinator = system.thread_coordinator();
96 let thread_watchdog = system.thread_watchdog();
97
98 println!("๐งต Thread System:");
99 println!(" Thread Coordinator: {} strong references", std::sync::Arc::strong_count(thread_coordinator));
100 println!(" Thread Watchdog: {} strong references", std::sync::Arc::strong_count(thread_watchdog));
101 println!();
102
103 let node_registry = system.node_registry();
105
106 println!("๐ท๏ธ Node System:");
107 println!(" Node Registry: {} strong references", std::sync::Arc::strong_count(node_registry));
108 println!();
109
110 let message_router = system.message_router();
112 let subscription_manager = system.subscription_manager();
113 let publisher = system.publisher();
114
115 println!("๐ก Communication System:");
116 println!(" Message Router: {} strong references", std::sync::Arc::strong_count(message_router));
117 println!(" Subscription Manager: {} strong references", std::sync::Arc::strong_count(subscription_manager));
118 println!(" Publisher: {} strong references", std::sync::Arc::strong_count(publisher));
119 println!();
120
121 Ok(())
122 }
123
124 fn show_critical_issues(&self, system_status: &crate::integration::core::SystemStatus, stats: &crate::integration::performance::SystemStatistics) {
126 let mut has_critical_issues = false;
127
128 println!("๐จ Critical Issues:");
129 println!("===================");
130 println!();
131
132 if stats.error_rate_percent > 5.0 {
134 println!("โ High error rate: {:.2}%", stats.error_rate_percent);
135 has_critical_issues = true;
136 }
137
138 if stats.memory_usage_bytes > 100_000_000 { println!("โ High memory usage: {} bytes", stats.memory_usage_bytes);
141 has_critical_issues = true;
142 }
143
144 if system_status.overall_health.contains("Critical") {
146 println!("โ System in critical state: {}", system_status.overall_health);
147 has_critical_issues = true;
148 }
149
150 if !has_critical_issues {
151 println!("โ
No critical issues detected");
152 }
153 println!();
154 }
155}