Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6509a2b91a | |||
| 52f8c40b86 | |||
| a86b5ba8f9 | |||
| 1b964545be | |||
| 97aa1708c2 | |||
| d12689f3b5 | |||
| f22e3ee95e | |||
| e890c5e810 | |||
| 078c30a592 | |||
| a847674004 | |||
| 2618f6b62f | |||
| c3fc5a181d | |||
| 3f45a172b3 | |||
| 5b12c12228 | |||
| 651b801de3 | |||
| 71b9f93d7c | |||
| ae70946c61 | |||
| 2910b7d875 | |||
| 43242debce | |||
| a2519b2814 | |||
| 91f037aa3e |
71
CLAUDE.md
71
CLAUDE.md
@@ -18,22 +18,24 @@ All system panel features successfully implemented:
|
|||||||
- ✅ **Tmpfs Monitoring**: Added /tmp usage to RAM section
|
- ✅ **Tmpfs Monitoring**: Added /tmp usage to RAM section
|
||||||
- ✅ **Agent Deployment**: NixOS collector working in production
|
- ✅ **Agent Deployment**: NixOS collector working in production
|
||||||
|
|
||||||
**Keyboard Navigation and Service Management - COMPLETED** ✅
|
**Simplified Navigation and Service Management - COMPLETED** ✅
|
||||||
|
|
||||||
All keyboard navigation and service selection features successfully implemented:
|
All navigation and service management features successfully implemented:
|
||||||
- ✅ **Panel Navigation**: Shift+Tab cycles through visible panels only (System → Services → Backup)
|
- ✅ **Direct Service Control**: Up/Down (or j/k) arrows directly control service selection
|
||||||
- ✅ **Service Selection**: Up/Down arrows navigate through parent services with visual cursor
|
- ✅ **Always Visible Selection**: Service selection highlighting always visible (no panel focus needed)
|
||||||
- ✅ **Focus Management**: Selection highlighting only visible when Services panel focused
|
- ✅ **Complete Service Discovery**: All configured services visible regardless of state
|
||||||
- ✅ **Status Preservation**: Service health colors maintained during selection (green/red icons)
|
- ✅ **Transitional Visual Feedback**: Service operations show directional arrows (↑ ↓ ↻)
|
||||||
- ✅ **Smart Panel Switching**: Only cycles through panels with data (backup panel conditional)
|
- ✅ **Simplified Interface**: Removed panel switching complexity, uniform appearance
|
||||||
- ✅ **Scroll Support**: All panels support content scrolling with proper overflow indicators
|
- ✅ **Vi-style Navigation**: Added j/k keys for vim users alongside arrow keys
|
||||||
|
|
||||||
**Current Status - October 27, 2025:**
|
**Current Status - October 28, 2025:**
|
||||||
- All keyboard navigation features working correctly ✅
|
- All service discovery and display features working correctly ✅
|
||||||
- Service selection cursor implemented with focus-aware highlighting ✅
|
- Simplified navigation system implemented ✅
|
||||||
- Panel scrolling fixed for System, Services, and Backup panels ✅
|
- Service selection always visible with direct control ✅
|
||||||
|
- Complete service visibility (all configured services show regardless of state) ✅
|
||||||
|
- Transitional service icons working with proper color handling ✅
|
||||||
- Build display working: "Build: 25.05.20251004.3bcc93c" ✅
|
- Build display working: "Build: 25.05.20251004.3bcc93c" ✅
|
||||||
- Agent version display working: "Agent: v0.1.17" ✅
|
- Agent version display working: "Agent: v0.1.33" ✅
|
||||||
- Cross-host version comparison implemented ✅
|
- Cross-host version comparison implemented ✅
|
||||||
- Automated binary release system working ✅
|
- Automated binary release system working ✅
|
||||||
- SMART data consolidated into disk collector ✅
|
- SMART data consolidated into disk collector ✅
|
||||||
@@ -76,36 +78,35 @@ Storage:
|
|||||||
**Backup panel visibility fixed - only shows when meaningful data exists ✅**
|
**Backup panel visibility fixed - only shows when meaningful data exists ✅**
|
||||||
**SSH-based rebuild system fully implemented and working ✅**
|
**SSH-based rebuild system fully implemented and working ✅**
|
||||||
|
|
||||||
### Current Keyboard Navigation Implementation
|
### Current Simplified Navigation Implementation
|
||||||
|
|
||||||
**Navigation Controls:**
|
**Navigation Controls:**
|
||||||
- **Tab**: Switch between hosts (cmbox, srv01, srv02, steambox, etc.)
|
- **Tab**: Switch between hosts (cmbox, srv01, srv02, steambox, etc.)
|
||||||
- **Shift+Tab**: Cycle through visible panels (System → Services → Backup → System)
|
- **↑↓ or j/k**: Move service selection cursor (always works)
|
||||||
- **Up/Down (System/Backup)**: Scroll through panel content
|
|
||||||
- **Up/Down (Services)**: Move service selection cursor between parent services
|
|
||||||
- **q**: Quit dashboard
|
- **q**: Quit dashboard
|
||||||
|
|
||||||
**Panel-Specific Features:**
|
**Service Control:**
|
||||||
- **System Panel**: Scrollable content with CPU, RAM, Storage details
|
- **s**: Start selected service
|
||||||
- **Services Panel**: Service selection cursor for parent services only (docker, nginx, postgresql, etc.)
|
- **S**: Stop selected service
|
||||||
- **Backup Panel**: Scrollable repository list with proper overflow handling
|
- **R**: Rebuild current host (works from any context)
|
||||||
|
|
||||||
**Visual Feedback:**
|
**Visual Features:**
|
||||||
- **Focused Panel**: Blue border and title highlighting
|
- **Service Selection**: Always visible blue background highlighting current service
|
||||||
- **Service Selection**: Blue background with preserved status icon colors (green ● for active, red ● for failed)
|
- **Status Icons**: Green ● (active), Yellow ◐ (inactive), Red ◯ (failed), ? (unknown)
|
||||||
- **Focus-Aware Selection**: Selection highlighting only visible when Services panel focused
|
- **Transitional Icons**: Blue ↑ (starting), ↓ (stopping), ↻ (restarting) when not selected
|
||||||
- **Dynamic Statusbar**: Context-aware shortcuts based on focused panel
|
- **Transitional Icons**: Dark gray arrows when service is selected (for visibility)
|
||||||
|
- **Uniform Interface**: All panels have consistent appearance (no focus borders)
|
||||||
|
|
||||||
### Remote Command Execution - WORKING ✅
|
### Service Discovery and Display - WORKING ✅
|
||||||
|
|
||||||
**All Issues Resolved (as of 2025-10-24):**
|
**All Issues Resolved (as of 2025-10-28):**
|
||||||
- ✅ **ZMQ Command Protocol**: Extended with ServiceControl and SystemRebuild variants
|
- ✅ **Complete Service Discovery**: Uses `systemctl list-unit-files` + `list-units --all` for comprehensive service detection
|
||||||
- ✅ **Agent Handlers**: systemctl and nixos-rebuild execution with maintenance mode
|
- ✅ **All Services Visible**: Shows all configured services regardless of current state (active/inactive)
|
||||||
- ✅ **Dashboard Integration**: Keyboard shortcuts execute commands
|
- ✅ **Proper Status Display**: Active services show green ●, inactive show yellow ◐, failed show red ◯
|
||||||
- ✅ **Service Control**: Fixed toggle logic - replaced with separate 's' (start) and 'S' (stop)
|
- ✅ **Transitional Icons**: Visual feedback during service operations with proper color handling
|
||||||
- ✅ **System Rebuild**: Fixed permission issues and sandboxing problems
|
- ✅ **Simplified Navigation**: Removed panel complexity, direct service control always available
|
||||||
- ✅ **Git Clone Approach**: Implemented for nixos-rebuild to avoid directory permissions
|
- ✅ **Service Control**: Start (s) and Stop (S) commands work from anywhere
|
||||||
- ✅ **Visual Feedback**: Directional arrows for service status (↑ starting, ↓ stopping, ↻ restarting)
|
- ✅ **System Rebuild**: SSH + tmux popup approach for reliable remote rebuilds
|
||||||
|
|
||||||
### Terminal Popup for Real-time Output - IMPLEMENTED ✅
|
### Terminal Popup for Real-time Output - IMPLEMENTED ✅
|
||||||
|
|
||||||
|
|||||||
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -270,7 +270,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.18"
|
version = "0.1.37"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -291,7 +291,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.18"
|
version = "0.1.37"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -314,7 +314,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.18"
|
version = "0.1.37"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.18"
|
version = "0.1.38"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -71,11 +71,11 @@ impl Agent {
|
|||||||
info!("Initial metric collection completed - all data cached and ready");
|
info!("Initial metric collection completed - all data cached and ready");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Separate intervals for collection and transmission
|
// Separate intervals for collection, transmission, and email notifications
|
||||||
let mut collection_interval =
|
let mut collection_interval =
|
||||||
interval(Duration::from_secs(self.config.collection_interval_seconds));
|
interval(Duration::from_secs(self.config.collection_interval_seconds));
|
||||||
let mut transmission_interval = interval(Duration::from_secs(self.config.zmq.transmission_interval_seconds));
|
let mut transmission_interval = interval(Duration::from_secs(self.config.zmq.transmission_interval_seconds));
|
||||||
let mut notification_interval = interval(Duration::from_secs(self.config.status_aggregation.notification_interval_seconds));
|
let mut notification_interval = interval(Duration::from_secs(self.config.notifications.aggregation_interval_seconds));
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
tokio::select! {
|
tokio::select! {
|
||||||
@@ -86,13 +86,13 @@ impl Agent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = transmission_interval.tick() => {
|
_ = transmission_interval.tick() => {
|
||||||
// Send all metrics via ZMQ every 1 second
|
// Send all metrics via ZMQ (dashboard updates only)
|
||||||
if let Err(e) = self.broadcast_all_metrics().await {
|
if let Err(e) = self.broadcast_all_metrics().await {
|
||||||
error!("Failed to broadcast metrics: {}", e);
|
error!("Failed to broadcast metrics: {}", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = notification_interval.tick() => {
|
_ = notification_interval.tick() => {
|
||||||
// Process batched notifications
|
// Process batched email notifications (separate from dashboard updates)
|
||||||
if let Err(e) = self.host_status_manager.process_pending_notifications(&mut self.notification_manager).await {
|
if let Err(e) = self.host_status_manager.process_pending_notifications(&mut self.notification_manager).await {
|
||||||
error!("Failed to process pending notifications: {}", e);
|
error!("Failed to process pending notifications: {}", e);
|
||||||
}
|
}
|
||||||
@@ -127,8 +127,8 @@ impl Agent {
|
|||||||
|
|
||||||
info!("Force collected and cached {} metrics", metrics.len());
|
info!("Force collected and cached {} metrics", metrics.len());
|
||||||
|
|
||||||
// Process metrics through status manager
|
// Process metrics through status manager (collect status data at startup)
|
||||||
self.process_metrics(&metrics).await;
|
let _status_changed = self.process_metrics(&metrics).await;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -146,17 +146,24 @@ impl Agent {
|
|||||||
|
|
||||||
debug!("Collected and cached {} metrics", metrics.len());
|
debug!("Collected and cached {} metrics", metrics.len());
|
||||||
|
|
||||||
// Process metrics through status manager
|
// Process metrics through status manager and trigger immediate transmission if status changed
|
||||||
self.process_metrics(&metrics).await;
|
let status_changed = self.process_metrics(&metrics).await;
|
||||||
|
|
||||||
|
if status_changed {
|
||||||
|
info!("Status change detected - triggering immediate metric transmission");
|
||||||
|
if let Err(e) = self.broadcast_all_metrics().await {
|
||||||
|
error!("Failed to broadcast metrics after status change: {}", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn broadcast_all_metrics(&mut self) -> Result<()> {
|
async fn broadcast_all_metrics(&mut self) -> Result<()> {
|
||||||
debug!("Broadcasting all metrics via ZMQ");
|
debug!("Broadcasting cached metrics via ZMQ");
|
||||||
|
|
||||||
// Get all current metrics from collectors
|
// Get cached metrics (no fresh collection)
|
||||||
let mut metrics = self.metric_manager.collect_all_metrics().await?;
|
let mut metrics = self.metric_manager.get_cached_metrics();
|
||||||
|
|
||||||
// Add the host status summary metric from status manager
|
// Add the host status summary metric from status manager
|
||||||
let host_status_metric = self.host_status_manager.get_host_status_metric();
|
let host_status_metric = self.host_status_manager.get_host_status_metric();
|
||||||
@@ -171,7 +178,7 @@ impl Agent {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("Broadcasting {} metrics (including host status summary)", metrics.len());
|
debug!("Broadcasting {} cached metrics (including host status summary)", metrics.len());
|
||||||
|
|
||||||
// Create and send message with all current data
|
// Create and send message with all current data
|
||||||
let message = MetricMessage::new(self.hostname.clone(), metrics);
|
let message = MetricMessage::new(self.hostname.clone(), metrics);
|
||||||
@@ -181,11 +188,15 @@ impl Agent {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn process_metrics(&mut self, metrics: &[Metric]) {
|
async fn process_metrics(&mut self, metrics: &[Metric]) -> bool {
|
||||||
|
let mut status_changed = false;
|
||||||
for metric in metrics {
|
for metric in metrics {
|
||||||
self.host_status_manager.process_metric(metric, &mut self.notification_manager).await;
|
if self.host_status_manager.process_metric(metric, &mut self.notification_manager).await {
|
||||||
|
status_changed = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
status_changed
|
||||||
|
}
|
||||||
|
|
||||||
/// Create agent version metric for cross-host version comparison
|
/// Create agent version metric for cross-host version comparison
|
||||||
fn get_agent_version_metric(&self) -> Metric {
|
fn get_agent_version_metric(&self) -> Metric {
|
||||||
@@ -259,11 +270,10 @@ impl Agent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Handle systemd service control commands
|
/// Handle systemd service control commands
|
||||||
async fn handle_service_control(&self, service_name: &str, action: &ServiceAction) -> Result<()> {
|
async fn handle_service_control(&mut self, service_name: &str, action: &ServiceAction) -> Result<()> {
|
||||||
let action_str = match action {
|
let action_str = match action {
|
||||||
ServiceAction::Start => "start",
|
ServiceAction::Start => "start",
|
||||||
ServiceAction::Stop => "stop",
|
ServiceAction::Stop => "stop",
|
||||||
ServiceAction::Restart => "restart",
|
|
||||||
ServiceAction::Status => "status",
|
ServiceAction::Status => "status",
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -288,10 +298,13 @@ impl Agent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Force refresh metrics after service control to update service status
|
// Force refresh metrics after service control to update service status
|
||||||
if matches!(action, ServiceAction::Start | ServiceAction::Stop | ServiceAction::Restart) {
|
if matches!(action, ServiceAction::Start | ServiceAction::Stop) {
|
||||||
info!("Triggering metric refresh after service control");
|
info!("Triggering immediate metric refresh after service control");
|
||||||
// Note: We can't call self.collect_metrics_only() here due to borrowing issues
|
if let Err(e) = self.collect_metrics_only().await {
|
||||||
// The next metric collection cycle will pick up the changes
|
error!("Failed to refresh metrics after service control: {}", e);
|
||||||
|
} else {
|
||||||
|
info!("Service status refreshed immediately after {} {}", action_str, service_name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -556,8 +556,8 @@ impl Collector for DiskCollector {
|
|||||||
|
|
||||||
// Drive wear level (for SSDs)
|
// Drive wear level (for SSDs)
|
||||||
if let Some(wear) = drive.wear_level {
|
if let Some(wear) = drive.wear_level {
|
||||||
let wear_status = if wear >= 90.0 { Status::Critical }
|
let wear_status = if wear >= self.config.wear_critical_percent { Status::Critical }
|
||||||
else if wear >= 80.0 { Status::Warning }
|
else if wear >= self.config.wear_warning_percent { Status::Warning }
|
||||||
else { Status::Ok };
|
else { Status::Ok };
|
||||||
|
|
||||||
metrics.push(Metric {
|
metrics.push(Metric {
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ impl MemoryCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Monitor tmpfs (/tmp) usage
|
// Monitor tmpfs (/tmp) usage
|
||||||
if let Ok(tmpfs_metrics) = self.get_tmpfs_metrics() {
|
if let Ok(tmpfs_metrics) = self.get_tmpfs_metrics(status_tracker) {
|
||||||
metrics.extend(tmpfs_metrics);
|
metrics.extend(tmpfs_metrics);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,7 +195,7 @@ impl MemoryCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get tmpfs (/tmp) usage metrics
|
/// Get tmpfs (/tmp) usage metrics
|
||||||
fn get_tmpfs_metrics(&self) -> Result<Vec<Metric>, CollectorError> {
|
fn get_tmpfs_metrics(&self, status_tracker: &mut StatusTracker) -> Result<Vec<Metric>, CollectorError> {
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
let output = Command::new("df")
|
let output = Command::new("df")
|
||||||
@@ -249,12 +249,15 @@ impl MemoryCollector {
|
|||||||
let mut metrics = Vec::new();
|
let mut metrics = Vec::new();
|
||||||
let timestamp = chrono::Utc::now().timestamp() as u64;
|
let timestamp = chrono::Utc::now().timestamp() as u64;
|
||||||
|
|
||||||
|
// Calculate status using same thresholds as main memory
|
||||||
|
let tmp_status = self.calculate_usage_status("memory_tmp_usage_percent", usage_percent, status_tracker);
|
||||||
|
|
||||||
metrics.push(Metric {
|
metrics.push(Metric {
|
||||||
name: "memory_tmp_usage_percent".to_string(),
|
name: "memory_tmp_usage_percent".to_string(),
|
||||||
value: MetricValue::Float(usage_percent),
|
value: MetricValue::Float(usage_percent),
|
||||||
unit: Some("%".to_string()),
|
unit: Some("%".to_string()),
|
||||||
description: Some("tmpfs /tmp usage percentage".to_string()),
|
description: Some("tmpfs /tmp usage percentage".to_string()),
|
||||||
status: Status::Ok,
|
status: tmp_status,
|
||||||
timestamp,
|
timestamp,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ use crate::config::NixOSConfig;
|
|||||||
///
|
///
|
||||||
/// Collects NixOS-specific system information including:
|
/// Collects NixOS-specific system information including:
|
||||||
/// - NixOS version and build information
|
/// - NixOS version and build information
|
||||||
/// - Currently active/logged in users
|
|
||||||
pub struct NixOSCollector {
|
pub struct NixOSCollector {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,31 +18,6 @@ impl NixOSCollector {
|
|||||||
Self {}
|
Self {}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get NixOS build information
|
|
||||||
fn get_nixos_build_info(&self) -> Result<String, Box<dyn std::error::Error>> {
|
|
||||||
// Get nixos-version output directly
|
|
||||||
let output = Command::new("nixos-version").output()?;
|
|
||||||
|
|
||||||
if !output.status.success() {
|
|
||||||
return Err("nixos-version command failed".into());
|
|
||||||
}
|
|
||||||
|
|
||||||
let version_line = String::from_utf8_lossy(&output.stdout);
|
|
||||||
let version = version_line.trim();
|
|
||||||
|
|
||||||
if version.is_empty() {
|
|
||||||
return Err("Empty nixos-version output".into());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove codename part (e.g., "(Warbler)")
|
|
||||||
let clean_version = if let Some(pos) = version.find(" (") {
|
|
||||||
version[..pos].to_string()
|
|
||||||
} else {
|
|
||||||
version.to_string()
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(clean_version)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get agent hash from binary path
|
/// Get agent hash from binary path
|
||||||
fn get_agent_hash(&self) -> Result<String, Box<dyn std::error::Error>> {
|
fn get_agent_hash(&self) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
@@ -90,27 +64,6 @@ impl NixOSCollector {
|
|||||||
Err("Could not extract hash from nix store path".into())
|
Err("Could not extract hash from nix store path".into())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get currently active users
|
|
||||||
fn get_active_users(&self) -> Result<Vec<String>, Box<dyn std::error::Error>> {
|
|
||||||
let output = Command::new("who").output()?;
|
|
||||||
|
|
||||||
if !output.status.success() {
|
|
||||||
return Err("who command failed".into());
|
|
||||||
}
|
|
||||||
|
|
||||||
let who_output = String::from_utf8_lossy(&output.stdout);
|
|
||||||
let mut users = std::collections::HashSet::new();
|
|
||||||
|
|
||||||
for line in who_output.lines() {
|
|
||||||
if let Some(username) = line.split_whitespace().next() {
|
|
||||||
if !username.is_empty() {
|
|
||||||
users.insert(username.to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(users.into_iter().collect())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@@ -146,31 +99,6 @@ impl Collector for NixOSCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect active users
|
|
||||||
match self.get_active_users() {
|
|
||||||
Ok(users) => {
|
|
||||||
let users_str = users.join(", ");
|
|
||||||
metrics.push(Metric {
|
|
||||||
name: "system_active_users".to_string(),
|
|
||||||
value: MetricValue::String(users_str),
|
|
||||||
unit: None,
|
|
||||||
description: Some("Currently active users".to_string()),
|
|
||||||
status: Status::Ok,
|
|
||||||
timestamp,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
debug!("Failed to get active users: {}", e);
|
|
||||||
metrics.push(Metric {
|
|
||||||
name: "system_active_users".to_string(),
|
|
||||||
value: MetricValue::String("unknown".to_string()),
|
|
||||||
unit: None,
|
|
||||||
description: Some("Active users (failed to detect)".to_string()),
|
|
||||||
status: Status::Unknown,
|
|
||||||
timestamp,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Collect config hash
|
// Collect config hash
|
||||||
match self.get_config_hash() {
|
match self.get_config_hash() {
|
||||||
|
|||||||
@@ -136,8 +136,21 @@ impl SystemdCollector {
|
|||||||
/// Auto-discover interesting services to monitor (internal version that doesn't update state)
|
/// Auto-discover interesting services to monitor (internal version that doesn't update state)
|
||||||
fn discover_services_internal(&self) -> Result<(Vec<String>, std::collections::HashMap<String, ServiceStatusInfo>)> {
|
fn discover_services_internal(&self) -> Result<(Vec<String>, std::collections::HashMap<String, ServiceStatusInfo>)> {
|
||||||
debug!("Starting systemd service discovery with status caching");
|
debug!("Starting systemd service discovery with status caching");
|
||||||
// Get all services (includes inactive, running, failed - everything)
|
|
||||||
let units_output = Command::new("systemctl")
|
// First: Get all service unit files (includes services that have never been started)
|
||||||
|
let unit_files_output = Command::new("systemctl")
|
||||||
|
.arg("list-unit-files")
|
||||||
|
.arg("--type=service")
|
||||||
|
.arg("--no-pager")
|
||||||
|
.arg("--plain")
|
||||||
|
.output()?;
|
||||||
|
|
||||||
|
if !unit_files_output.status.success() {
|
||||||
|
return Err(anyhow::anyhow!("systemctl list-unit-files command failed"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Second: Get runtime status of all units
|
||||||
|
let units_status_output = Command::new("systemctl")
|
||||||
.arg("list-units")
|
.arg("list-units")
|
||||||
.arg("--type=service")
|
.arg("--type=service")
|
||||||
.arg("--all")
|
.arg("--all")
|
||||||
@@ -145,22 +158,33 @@ impl SystemdCollector {
|
|||||||
.arg("--plain")
|
.arg("--plain")
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
if !units_output.status.success() {
|
if !units_status_output.status.success() {
|
||||||
return Err(anyhow::anyhow!("systemctl system command failed"));
|
return Err(anyhow::anyhow!("systemctl list-units command failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
let units_str = String::from_utf8(units_output.stdout)?;
|
let unit_files_str = String::from_utf8(unit_files_output.stdout)?;
|
||||||
|
let units_status_str = String::from_utf8(units_status_output.stdout)?;
|
||||||
let mut services = Vec::new();
|
let mut services = Vec::new();
|
||||||
|
|
||||||
// Use configuration instead of hardcoded values
|
// Use configuration instead of hardcoded values
|
||||||
let excluded_services = &self.config.excluded_services;
|
let excluded_services = &self.config.excluded_services;
|
||||||
let service_name_filters = &self.config.service_name_filters;
|
let service_name_filters = &self.config.service_name_filters;
|
||||||
|
|
||||||
// Parse all services and cache their status information
|
// Parse all service unit files to get complete service list
|
||||||
let mut all_service_names = std::collections::HashSet::new();
|
let mut all_service_names = std::collections::HashSet::new();
|
||||||
let mut status_cache = std::collections::HashMap::new();
|
|
||||||
|
|
||||||
for line in units_str.lines() {
|
for line in unit_files_str.lines() {
|
||||||
|
let fields: Vec<&str> = line.split_whitespace().collect();
|
||||||
|
if fields.len() >= 2 && fields[0].ends_with(".service") {
|
||||||
|
let service_name = fields[0].trim_end_matches(".service");
|
||||||
|
all_service_names.insert(service_name.to_string());
|
||||||
|
debug!("Found service unit file: {}", service_name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse runtime status for all units
|
||||||
|
let mut status_cache = std::collections::HashMap::new();
|
||||||
|
for line in units_status_str.lines() {
|
||||||
let fields: Vec<&str> = line.split_whitespace().collect();
|
let fields: Vec<&str> = line.split_whitespace().collect();
|
||||||
if fields.len() >= 4 && fields[0].ends_with(".service") {
|
if fields.len() >= 4 && fields[0].ends_with(".service") {
|
||||||
let service_name = fields[0].trim_end_matches(".service");
|
let service_name = fields[0].trim_end_matches(".service");
|
||||||
@@ -177,8 +201,19 @@ impl SystemdCollector {
|
|||||||
sub_state: sub_state.clone(),
|
sub_state: sub_state.clone(),
|
||||||
});
|
});
|
||||||
|
|
||||||
all_service_names.insert(service_name.to_string());
|
debug!("Got runtime status for service: {} (load:{}, active:{}, sub:{})", service_name, load_state, active_state, sub_state);
|
||||||
debug!("Parsed service: {} (load:{}, active:{}, sub:{})", service_name, load_state, active_state, sub_state);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For services found in unit files but not in runtime status, set default inactive status
|
||||||
|
for service_name in &all_service_names {
|
||||||
|
if !status_cache.contains_key(service_name) {
|
||||||
|
status_cache.insert(service_name.to_string(), ServiceStatusInfo {
|
||||||
|
load_state: "not-loaded".to_string(),
|
||||||
|
active_state: "inactive".to_string(),
|
||||||
|
sub_state: "dead".to_string(),
|
||||||
|
});
|
||||||
|
debug!("Service {} found in unit files but not runtime - marked as inactive", service_name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -520,10 +555,8 @@ impl SystemdCollector {
|
|||||||
for (site_name, url) in &sites {
|
for (site_name, url) in &sites {
|
||||||
match self.check_site_latency(url) {
|
match self.check_site_latency(url) {
|
||||||
Ok(latency_ms) => {
|
Ok(latency_ms) => {
|
||||||
let status = if latency_ms < 500.0 {
|
let status = if latency_ms < self.config.nginx_latency_critical_ms {
|
||||||
Status::Ok
|
Status::Ok
|
||||||
} else if latency_ms < 2000.0 {
|
|
||||||
Status::Warning
|
|
||||||
} else {
|
} else {
|
||||||
Status::Critical
|
Status::Critical
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -112,6 +112,5 @@ pub enum AgentCommand {
|
|||||||
pub enum ServiceAction {
|
pub enum ServiceAction {
|
||||||
Start,
|
Start,
|
||||||
Stop,
|
Stop,
|
||||||
Restart,
|
|
||||||
Status,
|
Status,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ pub struct SystemdConfig {
|
|||||||
pub nginx_check_interval_seconds: u64,
|
pub nginx_check_interval_seconds: u64,
|
||||||
pub http_timeout_seconds: u64,
|
pub http_timeout_seconds: u64,
|
||||||
pub http_connect_timeout_seconds: u64,
|
pub http_connect_timeout_seconds: u64,
|
||||||
|
pub nginx_latency_critical_ms: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -143,6 +144,8 @@ pub struct NotificationConfig {
|
|||||||
pub from_email: String,
|
pub from_email: String,
|
||||||
pub to_email: String,
|
pub to_email: String,
|
||||||
pub rate_limit_minutes: u64,
|
pub rate_limit_minutes: u64,
|
||||||
|
/// Email notification batching interval in seconds (default: 60)
|
||||||
|
pub aggregation_interval_seconds: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,13 @@ pub fn validate_config(config: &AgentConfig) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate systemd configuration
|
||||||
|
if config.collectors.systemd.enabled {
|
||||||
|
if config.collectors.systemd.nginx_latency_critical_ms <= 0.0 {
|
||||||
|
bail!("Nginx latency critical threshold must be positive");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Validate SMTP configuration
|
// Validate SMTP configuration
|
||||||
if config.notifications.enabled {
|
if config.notifications.enabled {
|
||||||
if config.notifications.smtp_host.is_empty() {
|
if config.notifications.smtp_host.is_empty() {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ struct TimedCollector {
|
|||||||
pub struct MetricCollectionManager {
|
pub struct MetricCollectionManager {
|
||||||
collectors: Vec<TimedCollector>,
|
collectors: Vec<TimedCollector>,
|
||||||
status_tracker: StatusTracker,
|
status_tracker: StatusTracker,
|
||||||
|
cached_metrics: Vec<Metric>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MetricCollectionManager {
|
impl MetricCollectionManager {
|
||||||
@@ -177,6 +178,7 @@ impl MetricCollectionManager {
|
|||||||
Ok(Self {
|
Ok(Self {
|
||||||
collectors,
|
collectors,
|
||||||
status_tracker: StatusTracker::new(),
|
status_tracker: StatusTracker::new(),
|
||||||
|
cached_metrics: Vec::new(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,6 +200,9 @@ impl MetricCollectionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Cache the collected metrics
|
||||||
|
self.cached_metrics = all_metrics.clone();
|
||||||
Ok(all_metrics)
|
Ok(all_metrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,6 +236,18 @@ impl MetricCollectionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update cache with newly collected metrics
|
||||||
|
if !all_metrics.is_empty() {
|
||||||
|
// Merge new metrics with cached metrics (replace by name)
|
||||||
|
for new_metric in &all_metrics {
|
||||||
|
// Remove any existing metric with the same name
|
||||||
|
self.cached_metrics.retain(|cached| cached.name != new_metric.name);
|
||||||
|
// Add the new metric
|
||||||
|
self.cached_metrics.push(new_metric.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Ok(all_metrics)
|
Ok(all_metrics)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,4 +256,9 @@ impl MetricCollectionManager {
|
|||||||
self.collect_metrics_timed().await
|
self.collect_metrics_timed().await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get cached metrics without triggering fresh collection
|
||||||
|
pub fn get_cached_metrics(&self) -> Vec<Metric> {
|
||||||
|
self.cached_metrics.clone()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ use chrono::Utc;
|
|||||||
pub struct HostStatusConfig {
|
pub struct HostStatusConfig {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub aggregation_method: String, // "worst_case"
|
pub aggregation_method: String, // "worst_case"
|
||||||
pub notification_interval_seconds: u64,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for HostStatusConfig {
|
impl Default for HostStatusConfig {
|
||||||
@@ -17,7 +16,6 @@ impl Default for HostStatusConfig {
|
|||||||
Self {
|
Self {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
aggregation_method: "worst_case".to_string(),
|
aggregation_method: "worst_case".to_string(),
|
||||||
notification_interval_seconds: 30,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -160,25 +158,62 @@ impl HostStatusManager {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Process a metric - updates status (notifications handled separately via batching)
|
/// Process a metric - updates status and queues for aggregated notifications if status changed
|
||||||
pub async fn process_metric(&mut self, metric: &Metric, _notification_manager: &mut crate::notifications::NotificationManager) {
|
pub async fn process_metric(&mut self, metric: &Metric, _notification_manager: &mut crate::notifications::NotificationManager) -> bool {
|
||||||
// Just update status - notifications are handled by process_pending_notifications
|
let old_service_status = self.service_statuses.get(&metric.name).copied();
|
||||||
self.update_service_status(metric.name.clone(), metric.status);
|
let old_host_status = self.current_host_status;
|
||||||
|
let new_service_status = metric.status;
|
||||||
|
|
||||||
|
// Update status (this recalculates host status internally)
|
||||||
|
self.update_service_status(metric.name.clone(), new_service_status);
|
||||||
|
|
||||||
|
let new_host_status = self.current_host_status;
|
||||||
|
let mut status_changed = false;
|
||||||
|
|
||||||
|
// Check if service status actually changed (ignore first-time status setting)
|
||||||
|
if let Some(old_service_status) = old_service_status {
|
||||||
|
if old_service_status != new_service_status {
|
||||||
|
debug!("Service status change detected for {}: {:?} -> {:?}", metric.name, old_service_status, new_service_status);
|
||||||
|
|
||||||
|
// Queue change for aggregated notification (not immediate)
|
||||||
|
self.queue_status_change(&metric.name, old_service_status, new_service_status);
|
||||||
|
|
||||||
|
status_changed = true;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
debug!("Initial status set for {}: {:?}", metric.name, new_service_status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Process pending notifications - call this at notification intervals
|
// Check if host status changed (this should trigger immediate transmission)
|
||||||
|
if old_host_status != new_host_status {
|
||||||
|
debug!("Host status change detected: {:?} -> {:?}", old_host_status, new_host_status);
|
||||||
|
status_changed = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
status_changed // Return true if either service or host status changed
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Queue status change for aggregated notification
|
||||||
|
fn queue_status_change(&mut self, metric_name: &str, old_status: Status, new_status: Status) {
|
||||||
|
// Add to pending changes for aggregated notification
|
||||||
|
let entry = self.pending_changes.entry(metric_name.to_string()).or_insert((old_status, old_status, 0));
|
||||||
|
entry.1 = new_status; // Update final status
|
||||||
|
entry.2 += 1; // Increment change count
|
||||||
|
|
||||||
|
// Set batch start time if this is the first change
|
||||||
|
if self.batch_start_time.is_none() {
|
||||||
|
self.batch_start_time = Some(Instant::now());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// Process pending notifications - legacy method, now rarely used
|
||||||
pub async fn process_pending_notifications(&mut self, notification_manager: &mut crate::notifications::NotificationManager) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
pub async fn process_pending_notifications(&mut self, notification_manager: &mut crate::notifications::NotificationManager) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
|
||||||
if !self.config.enabled || self.pending_changes.is_empty() {
|
if !self.config.enabled || self.pending_changes.is_empty() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
let batch_start = self.batch_start_time.unwrap_or_else(Instant::now);
|
// Process notifications immediately without interval batching
|
||||||
let batch_duration = batch_start.elapsed();
|
|
||||||
|
|
||||||
// Only process if enough time has passed
|
|
||||||
if batch_duration.as_secs() < self.config.notification_interval_seconds {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create aggregated status changes
|
// Create aggregated status changes
|
||||||
let aggregated = self.create_aggregated_changes();
|
let aggregated = self.create_aggregated_changes();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.18"
|
version = "0.1.38"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -263,12 +263,7 @@ impl Dashboard {
|
|||||||
cmd_output.output_line
|
cmd_output.output_line
|
||||||
);
|
);
|
||||||
|
|
||||||
// Forward to TUI if not headless
|
// Command output (terminal popup removed - output not displayed)
|
||||||
if let Some(ref mut tui_app) = self.tui_app {
|
|
||||||
tui_app.add_terminal_output(&cmd_output.hostname, cmd_output.output_line);
|
|
||||||
|
|
||||||
// Note: Popup stays open for manual review - close with ESC/Q
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
last_metrics_check = Instant::now();
|
last_metrics_check = Instant::now();
|
||||||
@@ -299,14 +294,6 @@ impl Dashboard {
|
|||||||
/// Execute a UI command by sending it to the appropriate agent
|
/// Execute a UI command by sending it to the appropriate agent
|
||||||
async fn execute_ui_command(&self, command: UiCommand) -> Result<()> {
|
async fn execute_ui_command(&self, command: UiCommand) -> Result<()> {
|
||||||
match command {
|
match command {
|
||||||
UiCommand::ServiceRestart { hostname, service_name } => {
|
|
||||||
info!("Sending restart command for service {} on {}", service_name, hostname);
|
|
||||||
let agent_command = AgentCommand::ServiceControl {
|
|
||||||
service_name,
|
|
||||||
action: ServiceAction::Restart,
|
|
||||||
};
|
|
||||||
self.zmq_command_sender.send_command(&hostname, agent_command).await?;
|
|
||||||
}
|
|
||||||
UiCommand::ServiceStart { hostname, service_name } => {
|
UiCommand::ServiceStart { hostname, service_name } => {
|
||||||
info!("Sending start command for service {} on {}", service_name, hostname);
|
info!("Sending start command for service {} on {}", service_name, hostname);
|
||||||
let agent_command = AgentCommand::ServiceControl {
|
let agent_command = AgentCommand::ServiceControl {
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ pub enum AgentCommand {
|
|||||||
pub enum ServiceAction {
|
pub enum ServiceAction {
|
||||||
Start,
|
Start,
|
||||||
Stop,
|
Stop,
|
||||||
Restart,
|
|
||||||
Status,
|
Status,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use app::Dashboard;
|
|||||||
|
|
||||||
/// Get hardcoded version
|
/// Get hardcoded version
|
||||||
fn get_version() -> &'static str {
|
fn get_version() -> &'static str {
|
||||||
"v0.1.18"
|
"v0.1.33"
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if running inside tmux session
|
/// Check if running inside tmux session
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use crossterm::event::{Event, KeyCode, KeyModifiers};
|
use crossterm::event::{Event, KeyCode};
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
layout::{Constraint, Direction, Layout, Rect},
|
layout::{Constraint, Direction, Layout, Rect},
|
||||||
style::Style,
|
style::Style,
|
||||||
@@ -7,7 +7,7 @@ use ratatui::{
|
|||||||
Frame,
|
Frame,
|
||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::Instant;
|
||||||
use tracing::info;
|
use tracing::info;
|
||||||
|
|
||||||
pub mod theme;
|
pub mod theme;
|
||||||
@@ -22,38 +22,21 @@ use widgets::{BackupWidget, ServicesWidget, SystemWidget, Widget};
|
|||||||
/// Commands that can be triggered from the UI
|
/// Commands that can be triggered from the UI
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum UiCommand {
|
pub enum UiCommand {
|
||||||
ServiceRestart { hostname: String, service_name: String },
|
|
||||||
ServiceStart { hostname: String, service_name: String },
|
ServiceStart { hostname: String, service_name: String },
|
||||||
ServiceStop { hostname: String, service_name: String },
|
ServiceStop { hostname: String, service_name: String },
|
||||||
TriggerBackup { hostname: String },
|
TriggerBackup { hostname: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Command execution status for visual feedback
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
pub enum CommandStatus {
|
|
||||||
/// Command is executing
|
|
||||||
InProgress { command_type: CommandType, target: String, start_time: std::time::Instant },
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Types of commands for status tracking
|
/// Types of commands for status tracking
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub enum CommandType {
|
pub enum CommandType {
|
||||||
ServiceRestart,
|
|
||||||
ServiceStart,
|
ServiceStart,
|
||||||
ServiceStop,
|
ServiceStop,
|
||||||
BackupTrigger,
|
BackupTrigger,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Panel types for focus management
|
/// Panel types for focus management
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
|
||||||
pub enum PanelType {
|
|
||||||
System,
|
|
||||||
Services,
|
|
||||||
Backup,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl PanelType {
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Widget states for a specific host
|
/// Widget states for a specific host
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
@@ -70,8 +53,8 @@ pub struct HostWidgets {
|
|||||||
pub backup_scroll_offset: usize,
|
pub backup_scroll_offset: usize,
|
||||||
/// Last update time for this host
|
/// Last update time for this host
|
||||||
pub last_update: Option<Instant>,
|
pub last_update: Option<Instant>,
|
||||||
/// Active command status for visual feedback
|
/// Pending service transitions for immediate visual feedback
|
||||||
pub command_status: Option<CommandStatus>,
|
pub pending_service_transitions: HashMap<String, (CommandType, String, Instant)>, // service_name -> (command_type, original_status, start_time)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HostWidgets {
|
impl HostWidgets {
|
||||||
@@ -84,55 +67,11 @@ impl HostWidgets {
|
|||||||
services_scroll_offset: 0,
|
services_scroll_offset: 0,
|
||||||
backup_scroll_offset: 0,
|
backup_scroll_offset: 0,
|
||||||
last_update: None,
|
last_update: None,
|
||||||
command_status: None,
|
pending_service_transitions: HashMap::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Terminal popup for streaming command output
|
|
||||||
#[derive(Clone)]
|
|
||||||
pub struct TerminalPopup {
|
|
||||||
/// Is the popup currently visible
|
|
||||||
pub visible: bool,
|
|
||||||
/// Command being executed
|
|
||||||
pub _command_type: CommandType,
|
|
||||||
/// Target hostname
|
|
||||||
pub hostname: String,
|
|
||||||
/// Target service/operation name
|
|
||||||
pub target: String,
|
|
||||||
/// Output lines collected so far
|
|
||||||
pub output_lines: Vec<String>,
|
|
||||||
/// Scroll offset for the output
|
|
||||||
pub scroll_offset: usize,
|
|
||||||
/// Start time of the operation
|
|
||||||
pub start_time: Instant,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TerminalPopup {
|
|
||||||
pub fn _new(command_type: CommandType, hostname: String, target: String) -> Self {
|
|
||||||
Self {
|
|
||||||
visible: true,
|
|
||||||
_command_type: command_type,
|
|
||||||
hostname,
|
|
||||||
target,
|
|
||||||
output_lines: Vec::new(),
|
|
||||||
scroll_offset: 0,
|
|
||||||
start_time: Instant::now(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn add_output_line(&mut self, line: String) {
|
|
||||||
self.output_lines.push(line);
|
|
||||||
// Auto-scroll to bottom when new content arrives
|
|
||||||
if self.output_lines.len() > 20 {
|
|
||||||
self.scroll_offset = self.output_lines.len().saturating_sub(20);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn close(&mut self) {
|
|
||||||
self.visible = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Main TUI application
|
/// Main TUI application
|
||||||
pub struct TuiApp {
|
pub struct TuiApp {
|
||||||
@@ -144,14 +83,10 @@ pub struct TuiApp {
|
|||||||
available_hosts: Vec<String>,
|
available_hosts: Vec<String>,
|
||||||
/// Host index for navigation
|
/// Host index for navigation
|
||||||
host_index: usize,
|
host_index: usize,
|
||||||
/// Currently focused panel
|
|
||||||
focused_panel: PanelType,
|
|
||||||
/// Should quit application
|
/// Should quit application
|
||||||
should_quit: bool,
|
should_quit: bool,
|
||||||
/// Track if user manually navigated away from localhost
|
/// Track if user manually navigated away from localhost
|
||||||
user_navigated_away: bool,
|
user_navigated_away: bool,
|
||||||
/// Terminal popup for streaming command output
|
|
||||||
terminal_popup: Option<TerminalPopup>,
|
|
||||||
/// Dashboard configuration
|
/// Dashboard configuration
|
||||||
config: DashboardConfig,
|
config: DashboardConfig,
|
||||||
}
|
}
|
||||||
@@ -163,10 +98,8 @@ impl TuiApp {
|
|||||||
current_host: None,
|
current_host: None,
|
||||||
available_hosts: Vec::new(),
|
available_hosts: Vec::new(),
|
||||||
host_index: 0,
|
host_index: 0,
|
||||||
focused_panel: PanelType::System, // Start with System panel focused
|
|
||||||
should_quit: false,
|
should_quit: false,
|
||||||
user_navigated_away: false,
|
user_navigated_away: false,
|
||||||
terminal_popup: None,
|
|
||||||
config,
|
config,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -180,8 +113,6 @@ impl TuiApp {
|
|||||||
|
|
||||||
/// Update widgets with metrics from store (only for current host)
|
/// Update widgets with metrics from store (only for current host)
|
||||||
pub fn update_metrics(&mut self, metric_store: &MetricStore) {
|
pub fn update_metrics(&mut self, metric_store: &MetricStore) {
|
||||||
// Check for command timeouts first
|
|
||||||
self.check_command_timeouts();
|
|
||||||
|
|
||||||
// Check for rebuild completion by agent hash change
|
// Check for rebuild completion by agent hash change
|
||||||
|
|
||||||
@@ -215,6 +146,9 @@ impl TuiApp {
|
|||||||
.copied()
|
.copied()
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
// Clear completed transitions first
|
||||||
|
self.clear_completed_transitions(&hostname, &service_metrics);
|
||||||
|
|
||||||
// Now get host widgets and update them
|
// Now get host widgets and update them
|
||||||
let host_widgets = self.get_or_create_host_widgets(&hostname);
|
let host_widgets = self.get_or_create_host_widgets(&hostname);
|
||||||
|
|
||||||
@@ -256,9 +190,9 @@ impl TuiApp {
|
|||||||
// Sort hosts alphabetically
|
// Sort hosts alphabetically
|
||||||
let mut sorted_hosts = hosts.clone();
|
let mut sorted_hosts = hosts.clone();
|
||||||
|
|
||||||
// Keep hosts that have ongoing commands even if they're offline
|
// Keep hosts that have pending transitions even if they're offline
|
||||||
for (hostname, host_widgets) in &self.host_widgets {
|
for (hostname, host_widgets) in &self.host_widgets {
|
||||||
if let Some(CommandStatus::InProgress { .. }) = &host_widgets.command_status {
|
if !host_widgets.pending_service_transitions.is_empty() {
|
||||||
if !sorted_hosts.contains(hostname) {
|
if !sorted_hosts.contains(hostname) {
|
||||||
sorted_hosts.push(hostname.clone());
|
sorted_hosts.push(hostname.clone());
|
||||||
}
|
}
|
||||||
@@ -297,38 +231,6 @@ impl TuiApp {
|
|||||||
/// Handle keyboard input
|
/// Handle keyboard input
|
||||||
pub fn handle_input(&mut self, event: Event) -> Result<Option<UiCommand>> {
|
pub fn handle_input(&mut self, event: Event) -> Result<Option<UiCommand>> {
|
||||||
if let Event::Key(key) = event {
|
if let Event::Key(key) = event {
|
||||||
// If terminal popup is visible, handle popup-specific keys first
|
|
||||||
if let Some(ref mut popup) = self.terminal_popup {
|
|
||||||
if popup.visible {
|
|
||||||
match key.code {
|
|
||||||
KeyCode::Esc => {
|
|
||||||
popup.close();
|
|
||||||
self.terminal_popup = None;
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
KeyCode::Up => {
|
|
||||||
popup.scroll_offset = popup.scroll_offset.saturating_sub(1);
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
KeyCode::Down => {
|
|
||||||
let max_scroll = if popup.output_lines.len() > 20 {
|
|
||||||
popup.output_lines.len() - 20
|
|
||||||
} else {
|
|
||||||
0
|
|
||||||
};
|
|
||||||
popup.scroll_offset = (popup.scroll_offset + 1).min(max_scroll);
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
KeyCode::Char('q') => {
|
|
||||||
popup.close();
|
|
||||||
self.terminal_popup = None;
|
|
||||||
return Ok(None);
|
|
||||||
}
|
|
||||||
_ => return Ok(None), // Consume all other keys when popup is open
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match key.code {
|
match key.code {
|
||||||
KeyCode::Char('q') => {
|
KeyCode::Char('q') => {
|
||||||
self.should_quit = true;
|
self.should_quit = true;
|
||||||
@@ -340,9 +242,7 @@ impl TuiApp {
|
|||||||
self.navigate_host(1);
|
self.navigate_host(1);
|
||||||
}
|
}
|
||||||
KeyCode::Char('r') => {
|
KeyCode::Char('r') => {
|
||||||
match self.focused_panel {
|
// System rebuild command - works on any panel for current host
|
||||||
PanelType::System => {
|
|
||||||
// Simple tmux popup with SSH rebuild using configured user and alias
|
|
||||||
if let Some(hostname) = self.current_host.clone() {
|
if let Some(hostname) = self.current_host.clone() {
|
||||||
// Launch tmux popup with SSH using config values
|
// Launch tmux popup with SSH using config values
|
||||||
let ssh_command = format!(
|
let ssh_command = format!(
|
||||||
@@ -358,65 +258,50 @@ impl TuiApp {
|
|||||||
.ok(); // Ignore errors, tmux will handle them
|
.ok(); // Ignore errors, tmux will handle them
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PanelType::Services => {
|
|
||||||
// Service restart command
|
|
||||||
if let (Some(service_name), Some(hostname)) = (self.get_selected_service(), self.current_host.clone()) {
|
|
||||||
self.start_command(&hostname, CommandType::ServiceRestart, service_name.clone());
|
|
||||||
return Ok(Some(UiCommand::ServiceRestart { hostname, service_name }));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
info!("Manual refresh requested");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
KeyCode::Char('s') => {
|
KeyCode::Char('s') => {
|
||||||
if self.focused_panel == PanelType::Services {
|
|
||||||
// Service start command
|
// Service start command
|
||||||
if let (Some(service_name), Some(hostname)) = (self.get_selected_service(), self.current_host.clone()) {
|
if let (Some(service_name), Some(hostname)) = (self.get_selected_service(), self.current_host.clone()) {
|
||||||
self.start_command(&hostname, CommandType::ServiceStart, service_name.clone());
|
if self.start_command(&hostname, CommandType::ServiceStart, service_name.clone()) {
|
||||||
return Ok(Some(UiCommand::ServiceStart { hostname, service_name }));
|
return Ok(Some(UiCommand::ServiceStart { hostname, service_name }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Char('S') => {
|
KeyCode::Char('S') => {
|
||||||
if self.focused_panel == PanelType::Services {
|
|
||||||
// Service stop command
|
// Service stop command
|
||||||
if let (Some(service_name), Some(hostname)) = (self.get_selected_service(), self.current_host.clone()) {
|
if let (Some(service_name), Some(hostname)) = (self.get_selected_service(), self.current_host.clone()) {
|
||||||
self.start_command(&hostname, CommandType::ServiceStop, service_name.clone());
|
if self.start_command(&hostname, CommandType::ServiceStop, service_name.clone()) {
|
||||||
return Ok(Some(UiCommand::ServiceStop { hostname, service_name }));
|
return Ok(Some(UiCommand::ServiceStop { hostname, service_name }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
KeyCode::Char('b') => {
|
KeyCode::Char('b') => {
|
||||||
if self.focused_panel == PanelType::Backup {
|
|
||||||
// Trigger backup
|
// Trigger backup
|
||||||
if let Some(hostname) = self.current_host.clone() {
|
if let Some(hostname) = self.current_host.clone() {
|
||||||
self.start_command(&hostname, CommandType::BackupTrigger, hostname.clone());
|
self.start_command(&hostname, CommandType::BackupTrigger, hostname.clone());
|
||||||
return Ok(Some(UiCommand::TriggerBackup { hostname }));
|
return Ok(Some(UiCommand::TriggerBackup { hostname }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
KeyCode::Tab => {
|
KeyCode::Tab => {
|
||||||
if key.modifiers.contains(KeyModifiers::SHIFT) {
|
|
||||||
// Shift+Tab cycles through panels
|
|
||||||
self.next_panel();
|
|
||||||
} else {
|
|
||||||
// Tab cycles to next host
|
// Tab cycles to next host
|
||||||
self.navigate_host(1);
|
self.navigate_host(1);
|
||||||
}
|
}
|
||||||
|
KeyCode::Up | KeyCode::Char('k') => {
|
||||||
|
// Move service selection up
|
||||||
|
if let Some(hostname) = self.current_host.clone() {
|
||||||
|
let host_widgets = self.get_or_create_host_widgets(&hostname);
|
||||||
|
host_widgets.services_widget.select_previous();
|
||||||
}
|
}
|
||||||
KeyCode::BackTab => {
|
|
||||||
// BackTab (Shift+Tab on some terminals) also cycles panels
|
|
||||||
self.next_panel();
|
|
||||||
}
|
}
|
||||||
KeyCode::Up => {
|
KeyCode::Down | KeyCode::Char('j') => {
|
||||||
// Scroll up in focused panel
|
// Move service selection down
|
||||||
self.scroll_focused_panel(-1);
|
if let Some(hostname) = self.current_host.clone() {
|
||||||
|
let total_services = {
|
||||||
|
let host_widgets = self.get_or_create_host_widgets(&hostname);
|
||||||
|
host_widgets.services_widget.get_total_services_count()
|
||||||
|
};
|
||||||
|
let host_widgets = self.get_or_create_host_widgets(&hostname);
|
||||||
|
host_widgets.services_widget.select_next(total_services);
|
||||||
}
|
}
|
||||||
KeyCode::Down => {
|
|
||||||
// Scroll down in focused panel
|
|
||||||
self.scroll_focused_panel(1);
|
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
@@ -457,25 +342,6 @@ impl TuiApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Switch to next panel (Shift+Tab) - only cycles through visible panels
|
|
||||||
pub fn next_panel(&mut self) {
|
|
||||||
let visible_panels = self.get_visible_panels();
|
|
||||||
if visible_panels.len() <= 1 {
|
|
||||||
return; // Can't switch if only one or no panels visible
|
|
||||||
}
|
|
||||||
|
|
||||||
// Find current panel index in visible panels
|
|
||||||
if let Some(current_index) = visible_panels.iter().position(|&p| p == self.focused_panel) {
|
|
||||||
// Move to next visible panel
|
|
||||||
let next_index = (current_index + 1) % visible_panels.len();
|
|
||||||
self.focused_panel = visible_panels[next_index];
|
|
||||||
} else {
|
|
||||||
// Current panel not visible, switch to first visible panel
|
|
||||||
self.focused_panel = visible_panels[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
info!("Switched to panel: {:?}", self.focused_panel);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -495,124 +361,89 @@ impl TuiApp {
|
|||||||
self.should_quit
|
self.should_quit
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Start command execution and track status for visual feedback
|
/// Get current service status for state-aware command validation
|
||||||
pub fn start_command(&mut self, hostname: &str, command_type: CommandType, target: String) {
|
fn get_current_service_status(&self, hostname: &str, service_name: &str) -> Option<String> {
|
||||||
if let Some(host_widgets) = self.host_widgets.get_mut(hostname) {
|
|
||||||
host_widgets.command_status = Some(CommandStatus::InProgress {
|
|
||||||
command_type,
|
|
||||||
target,
|
|
||||||
start_time: Instant::now(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Mark command as completed successfully
|
|
||||||
pub fn _complete_command(&mut self, hostname: &str) {
|
|
||||||
if let Some(host_widgets) = self.host_widgets.get_mut(hostname) {
|
|
||||||
// Simply clear the command status when completed
|
|
||||||
host_widgets.command_status = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Check for command timeouts and automatically clear them
|
|
||||||
pub fn check_command_timeouts(&mut self) {
|
|
||||||
let now = Instant::now();
|
|
||||||
let mut hosts_to_clear = Vec::new();
|
|
||||||
|
|
||||||
for (hostname, host_widgets) in &self.host_widgets {
|
|
||||||
if let Some(CommandStatus::InProgress { command_type: _, start_time, .. }) = &host_widgets.command_status {
|
|
||||||
let timeout_duration = Duration::from_secs(30); // 30 seconds for service commands
|
|
||||||
|
|
||||||
if now.duration_since(*start_time) > timeout_duration {
|
|
||||||
hosts_to_clear.push(hostname.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Clear timed out commands
|
|
||||||
for hostname in hosts_to_clear {
|
|
||||||
if let Some(host_widgets) = self.host_widgets.get_mut(&hostname) {
|
|
||||||
host_widgets.command_status = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Add output line to terminal popup
|
|
||||||
pub fn add_terminal_output(&mut self, hostname: &str, line: String) {
|
|
||||||
if let Some(ref mut popup) = self.terminal_popup {
|
|
||||||
if popup.hostname == hostname && popup.visible {
|
|
||||||
popup.add_output_line(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Close terminal popup for a specific hostname
|
|
||||||
pub fn _close_terminal_popup(&mut self, hostname: &str) {
|
|
||||||
if let Some(ref mut popup) = self.terminal_popup {
|
|
||||||
if popup.hostname == hostname {
|
|
||||||
popup.close();
|
|
||||||
self.terminal_popup = None;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Scroll the focused panel up or down
|
|
||||||
pub fn scroll_focused_panel(&mut self, direction: i32) {
|
|
||||||
if let Some(hostname) = self.current_host.clone() {
|
|
||||||
let focused_panel = self.focused_panel; // Get the value before borrowing
|
|
||||||
let host_widgets = self.get_or_create_host_widgets(&hostname);
|
|
||||||
|
|
||||||
match focused_panel {
|
|
||||||
PanelType::System => {
|
|
||||||
if direction > 0 {
|
|
||||||
host_widgets.system_scroll_offset = host_widgets.system_scroll_offset.saturating_add(1);
|
|
||||||
} else {
|
|
||||||
host_widgets.system_scroll_offset = host_widgets.system_scroll_offset.saturating_sub(1);
|
|
||||||
}
|
|
||||||
info!("System panel scroll offset: {}", host_widgets.system_scroll_offset);
|
|
||||||
}
|
|
||||||
PanelType::Services => {
|
|
||||||
// For services panel, Up/Down moves selection cursor, not scroll
|
|
||||||
let total_services = host_widgets.services_widget.get_total_services_count();
|
|
||||||
|
|
||||||
if direction > 0 {
|
|
||||||
host_widgets.services_widget.select_next(total_services);
|
|
||||||
info!("Services selection moved down");
|
|
||||||
} else {
|
|
||||||
host_widgets.services_widget.select_previous();
|
|
||||||
info!("Services selection moved up");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PanelType::Backup => {
|
|
||||||
if direction > 0 {
|
|
||||||
host_widgets.backup_scroll_offset = host_widgets.backup_scroll_offset.saturating_add(1);
|
|
||||||
} else {
|
|
||||||
host_widgets.backup_scroll_offset = host_widgets.backup_scroll_offset.saturating_sub(1);
|
|
||||||
}
|
|
||||||
info!("Backup panel scroll offset: {}", host_widgets.backup_scroll_offset);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Get list of currently visible panels
|
|
||||||
fn get_visible_panels(&self) -> Vec<PanelType> {
|
|
||||||
let mut visible_panels = vec![PanelType::System, PanelType::Services];
|
|
||||||
|
|
||||||
// Check if backup panel should be shown
|
|
||||||
if let Some(hostname) = &self.current_host {
|
|
||||||
if let Some(host_widgets) = self.host_widgets.get(hostname) {
|
if let Some(host_widgets) = self.host_widgets.get(hostname) {
|
||||||
if host_widgets.backup_widget.has_data() {
|
return host_widgets.services_widget.get_service_status(service_name);
|
||||||
visible_panels.push(PanelType::Backup);
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Start command execution with immediate visual feedback
|
||||||
|
pub fn start_command(&mut self, hostname: &str, command_type: CommandType, target: String) -> bool {
|
||||||
|
// Get current service status to validate command
|
||||||
|
let current_status = self.get_current_service_status(hostname, &target);
|
||||||
|
|
||||||
|
// Validate if command makes sense for current state
|
||||||
|
let should_execute = match (&command_type, current_status.as_deref()) {
|
||||||
|
(CommandType::ServiceStart, Some("inactive") | Some("failed") | Some("dead")) => true,
|
||||||
|
(CommandType::ServiceStop, Some("active")) => true,
|
||||||
|
(CommandType::ServiceStart, Some("active")) => {
|
||||||
|
// Already running - don't execute
|
||||||
|
false
|
||||||
|
},
|
||||||
|
(CommandType::ServiceStop, Some("inactive") | Some("failed") | Some("dead")) => {
|
||||||
|
// Already stopped - don't execute
|
||||||
|
false
|
||||||
|
},
|
||||||
|
(_, None) => {
|
||||||
|
// Unknown service state - allow command to proceed
|
||||||
|
true
|
||||||
|
},
|
||||||
|
_ => true, // Default: allow other combinations
|
||||||
|
};
|
||||||
|
|
||||||
|
// ALWAYS store the pending transition for immediate visual feedback, even if we don't execute
|
||||||
|
if let Some(host_widgets) = self.host_widgets.get_mut(hostname) {
|
||||||
|
host_widgets.pending_service_transitions.insert(
|
||||||
|
target.clone(),
|
||||||
|
(command_type, current_status.unwrap_or_else(|| "unknown".to_string()), Instant::now())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
should_execute
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Clear pending transitions when real status updates arrive or timeout
|
||||||
|
fn clear_completed_transitions(&mut self, hostname: &str, service_metrics: &[&Metric]) {
|
||||||
|
if let Some(host_widgets) = self.host_widgets.get_mut(hostname) {
|
||||||
|
let mut completed_services = Vec::new();
|
||||||
|
|
||||||
|
// Check each pending transition to see if real status has changed
|
||||||
|
for (service_name, (command_type, original_status, _start_time)) in &host_widgets.pending_service_transitions {
|
||||||
|
|
||||||
|
// Look for status metric for this service
|
||||||
|
for metric in service_metrics {
|
||||||
|
if metric.name == format!("service_{}_status", service_name) {
|
||||||
|
let new_status = metric.value.as_string();
|
||||||
|
|
||||||
|
// Check if status has changed from original (command completed)
|
||||||
|
if &new_status != original_status {
|
||||||
|
// Verify it changed in the expected direction
|
||||||
|
let expected_change = match command_type {
|
||||||
|
CommandType::ServiceStart => &new_status == "active",
|
||||||
|
CommandType::ServiceStop => &new_status != "active",
|
||||||
|
_ => false,
|
||||||
|
};
|
||||||
|
|
||||||
|
if expected_change {
|
||||||
|
completed_services.push(service_name.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
visible_panels
|
// Remove completed transitions
|
||||||
|
for service_name in completed_services {
|
||||||
|
host_widgets.pending_service_transitions.remove(&service_name);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// Render the dashboard (real btop-style multi-panel layout)
|
/// Render the dashboard (real btop-style multi-panel layout)
|
||||||
pub fn render(&mut self, frame: &mut Frame, metric_store: &MetricStore) {
|
pub fn render(&mut self, frame: &mut Frame, metric_store: &MetricStore) {
|
||||||
@@ -681,26 +512,20 @@ impl TuiApp {
|
|||||||
|
|
||||||
// Render services widget for current host
|
// Render services widget for current host
|
||||||
if let Some(hostname) = self.current_host.clone() {
|
if let Some(hostname) = self.current_host.clone() {
|
||||||
let is_focused = self.focused_panel == PanelType::Services;
|
let is_focused = true; // Always show service selection
|
||||||
let (scroll_offset, command_status) = {
|
let (scroll_offset, pending_transitions) = {
|
||||||
let host_widgets = self.get_or_create_host_widgets(&hostname);
|
let host_widgets = self.get_or_create_host_widgets(&hostname);
|
||||||
(host_widgets.services_scroll_offset, host_widgets.command_status.clone())
|
(host_widgets.services_scroll_offset, host_widgets.pending_service_transitions.clone())
|
||||||
};
|
};
|
||||||
let host_widgets = self.get_or_create_host_widgets(&hostname);
|
let host_widgets = self.get_or_create_host_widgets(&hostname);
|
||||||
host_widgets
|
host_widgets
|
||||||
.services_widget
|
.services_widget
|
||||||
.render_with_command_status(frame, content_chunks[1], is_focused, scroll_offset, command_status.as_ref()); // Services takes full right side
|
.render_with_transitions(frame, content_chunks[1], is_focused, scroll_offset, &pending_transitions); // Services takes full right side
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render statusbar at the bottom
|
// Render statusbar at the bottom
|
||||||
self.render_statusbar(frame, main_chunks[2]); // main_chunks[2] is the statusbar area
|
self.render_statusbar(frame, main_chunks[2]); // main_chunks[2] is the statusbar area
|
||||||
|
|
||||||
// Render terminal popup on top of everything else
|
|
||||||
if let Some(ref popup) = self.terminal_popup {
|
|
||||||
if popup.visible {
|
|
||||||
self.render_terminal_popup(frame, size, popup);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render btop-style minimal title with host status colors
|
/// Render btop-style minimal title with host status colors
|
||||||
@@ -711,63 +536,87 @@ impl TuiApp {
|
|||||||
|
|
||||||
if self.available_hosts.is_empty() {
|
if self.available_hosts.is_empty() {
|
||||||
let title_text = "cm-dashboard • no hosts discovered";
|
let title_text = "cm-dashboard • no hosts discovered";
|
||||||
let title = Paragraph::new(title_text).style(Typography::title());
|
let title = Paragraph::new(title_text)
|
||||||
|
.style(Style::default().fg(Theme::background()).bg(Theme::status_color(Status::Unknown)));
|
||||||
frame.render_widget(title, area);
|
frame.render_widget(title, area);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create spans for each host with status indicators
|
// Calculate worst-case status across all hosts
|
||||||
let mut spans = vec![Span::styled("cm-dashboard • ", Typography::title())];
|
let mut worst_status = Status::Ok;
|
||||||
|
for host in &self.available_hosts {
|
||||||
|
let host_status = self.calculate_host_status(host, metric_store);
|
||||||
|
worst_status = Status::aggregate(&[worst_status, host_status]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the worst status color as background
|
||||||
|
let background_color = Theme::status_color(worst_status);
|
||||||
|
|
||||||
|
// Split the title bar into left and right sections
|
||||||
|
let chunks = Layout::default()
|
||||||
|
.direction(Direction::Horizontal)
|
||||||
|
.constraints([Constraint::Length(15), Constraint::Min(0)])
|
||||||
|
.split(area);
|
||||||
|
|
||||||
|
// Left side: "cm-dashboard" text
|
||||||
|
let left_span = Span::styled(
|
||||||
|
" cm-dashboard",
|
||||||
|
Style::default().fg(Theme::background()).bg(background_color)
|
||||||
|
);
|
||||||
|
let left_title = Paragraph::new(Line::from(vec![left_span]))
|
||||||
|
.style(Style::default().bg(background_color));
|
||||||
|
frame.render_widget(left_title, chunks[0]);
|
||||||
|
|
||||||
|
// Right side: hosts with status indicators
|
||||||
|
let mut host_spans = Vec::new();
|
||||||
|
|
||||||
for (i, host) in self.available_hosts.iter().enumerate() {
|
for (i, host) in self.available_hosts.iter().enumerate() {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
spans.push(Span::styled(" ", Typography::title()));
|
host_spans.push(Span::styled(
|
||||||
|
" ",
|
||||||
|
Style::default().fg(Theme::background()).bg(background_color)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this host has a command status that affects the icon
|
// Always show normal status icon based on metrics (no command status at host level)
|
||||||
let (status_icon, status_color) = if let Some(host_widgets) = self.host_widgets.get(host) {
|
|
||||||
match &host_widgets.command_status {
|
|
||||||
Some(CommandStatus::InProgress { .. }) => {
|
|
||||||
// Show working indicator for in-progress commands
|
|
||||||
("⏳", Theme::highlight())
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
// Normal status icon based on metrics
|
|
||||||
let host_status = self.calculate_host_status(host, metric_store);
|
let host_status = self.calculate_host_status(host, metric_store);
|
||||||
(StatusIcons::get_icon(host_status), Theme::status_color(host_status))
|
let status_icon = StatusIcons::get_icon(host_status);
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// No host widgets yet, use normal status
|
|
||||||
let host_status = self.calculate_host_status(host, metric_store);
|
|
||||||
(StatusIcons::get_icon(host_status), Theme::status_color(host_status))
|
|
||||||
};
|
|
||||||
|
|
||||||
// Add status icon
|
// Add status icon with background color as foreground against status background
|
||||||
spans.push(Span::styled(
|
host_spans.push(Span::styled(
|
||||||
format!("{} ", status_icon),
|
format!("{} ", status_icon),
|
||||||
Style::default().fg(status_color),
|
Style::default().fg(Theme::background()).bg(background_color),
|
||||||
));
|
));
|
||||||
|
|
||||||
if Some(host) == self.current_host.as_ref() {
|
if Some(host) == self.current_host.as_ref() {
|
||||||
// Selected host in bold bright white
|
// Selected host in bold background color against status background
|
||||||
spans.push(Span::styled(
|
host_spans.push(Span::styled(
|
||||||
host.clone(),
|
host.clone(),
|
||||||
Typography::title().add_modifier(Modifier::BOLD),
|
Style::default()
|
||||||
|
.fg(Theme::background())
|
||||||
|
.bg(background_color)
|
||||||
|
.add_modifier(Modifier::BOLD),
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
// Other hosts in normal style with status color
|
// Other hosts in normal background color against status background
|
||||||
spans.push(Span::styled(
|
host_spans.push(Span::styled(
|
||||||
host.clone(),
|
host.clone(),
|
||||||
Style::default().fg(status_color),
|
Style::default().fg(Theme::background()).bg(background_color),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let title_line = Line::from(spans);
|
// Add right padding
|
||||||
let title = Paragraph::new(vec![title_line]);
|
host_spans.push(Span::styled(
|
||||||
|
" ",
|
||||||
|
Style::default().fg(Theme::background()).bg(background_color)
|
||||||
|
));
|
||||||
|
|
||||||
frame.render_widget(title, area);
|
let host_line = Line::from(host_spans);
|
||||||
|
let host_title = Paragraph::new(vec![host_line])
|
||||||
|
.style(Style::default().bg(background_color))
|
||||||
|
.alignment(ratatui::layout::Alignment::Right);
|
||||||
|
frame.render_widget(host_title, chunks[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate overall status for a host based on its metrics
|
/// Calculate overall status for a host based on its metrics
|
||||||
@@ -831,38 +680,18 @@ impl TuiApp {
|
|||||||
|
|
||||||
// Global shortcuts
|
// Global shortcuts
|
||||||
shortcuts.push("Tab: Switch Host".to_string());
|
shortcuts.push("Tab: Switch Host".to_string());
|
||||||
shortcuts.push("Shift+Tab: Switch Panel".to_string());
|
shortcuts.push("↑↓/jk: Select Service".to_string());
|
||||||
|
shortcuts.push("r: Rebuild Host".to_string());
|
||||||
// Scroll shortcuts (always available)
|
shortcuts.push("s/S: Start/Stop Service".to_string());
|
||||||
shortcuts.push("↑↓: Scroll".to_string());
|
|
||||||
|
|
||||||
// Panel-specific shortcuts
|
|
||||||
match self.focused_panel {
|
|
||||||
PanelType::System => {
|
|
||||||
shortcuts.push("R: Rebuild".to_string());
|
|
||||||
}
|
|
||||||
PanelType::Services => {
|
|
||||||
shortcuts.push("S: Start".to_string());
|
|
||||||
shortcuts.push("Shift+S: Stop".to_string());
|
|
||||||
shortcuts.push("R: Restart".to_string());
|
|
||||||
}
|
|
||||||
PanelType::Backup => {
|
|
||||||
shortcuts.push("B: Trigger Backup".to_string());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Always show quit
|
// Always show quit
|
||||||
shortcuts.push("Q: Quit".to_string());
|
shortcuts.push("q: Quit".to_string());
|
||||||
|
|
||||||
shortcuts
|
shortcuts
|
||||||
}
|
}
|
||||||
|
|
||||||
fn render_system_panel(&mut self, frame: &mut Frame, area: Rect, _metric_store: &MetricStore) {
|
fn render_system_panel(&mut self, frame: &mut Frame, area: Rect, _metric_store: &MetricStore) {
|
||||||
let system_block = if self.focused_panel == PanelType::System {
|
let system_block = Components::widget_block("system");
|
||||||
Components::focused_widget_block("system")
|
|
||||||
} else {
|
|
||||||
Components::widget_block("system")
|
|
||||||
};
|
|
||||||
let inner_area = system_block.inner(area);
|
let inner_area = system_block.inner(area);
|
||||||
frame.render_widget(system_block, area);
|
frame.render_widget(system_block, area);
|
||||||
// Get current host widgets, create if none exist
|
// Get current host widgets, create if none exist
|
||||||
@@ -877,11 +706,7 @@ impl TuiApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn render_backup_panel(&mut self, frame: &mut Frame, area: Rect) {
|
fn render_backup_panel(&mut self, frame: &mut Frame, area: Rect) {
|
||||||
let backup_block = if self.focused_panel == PanelType::Backup {
|
let backup_block = Components::widget_block("backup");
|
||||||
Components::focused_widget_block("backup")
|
|
||||||
} else {
|
|
||||||
Components::widget_block("backup")
|
|
||||||
};
|
|
||||||
let inner_area = backup_block.inner(area);
|
let inner_area = backup_block.inner(area);
|
||||||
frame.render_widget(backup_block, area);
|
frame.render_widget(backup_block, area);
|
||||||
|
|
||||||
@@ -896,112 +721,5 @@ impl TuiApp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render terminal popup with streaming output
|
|
||||||
fn render_terminal_popup(&self, frame: &mut Frame, area: Rect, popup: &TerminalPopup) {
|
|
||||||
use ratatui::{
|
|
||||||
style::{Color, Style},
|
|
||||||
text::{Line, Span},
|
|
||||||
widgets::{Block, Borders, Clear, Paragraph, Wrap},
|
|
||||||
};
|
|
||||||
|
|
||||||
// Calculate popup size (80% of screen, centered)
|
|
||||||
let popup_width = area.width * 80 / 100;
|
|
||||||
let popup_height = area.height * 80 / 100;
|
|
||||||
let popup_x = (area.width - popup_width) / 2;
|
|
||||||
let popup_y = (area.height - popup_height) / 2;
|
|
||||||
|
|
||||||
let popup_area = Rect {
|
|
||||||
x: popup_x,
|
|
||||||
y: popup_y,
|
|
||||||
width: popup_width,
|
|
||||||
height: popup_height,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Clear background
|
|
||||||
frame.render_widget(Clear, popup_area);
|
|
||||||
|
|
||||||
// Create terminal-style block
|
|
||||||
let title = format!(" {} → {} ({:.1}s) ",
|
|
||||||
popup.hostname,
|
|
||||||
popup.target,
|
|
||||||
popup.start_time.elapsed().as_secs_f32()
|
|
||||||
);
|
|
||||||
|
|
||||||
let block = Block::default()
|
|
||||||
.title(title)
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.border_style(Style::default().fg(Color::Cyan))
|
|
||||||
.style(Style::default().bg(Color::Black));
|
|
||||||
|
|
||||||
let inner_area = block.inner(popup_area);
|
|
||||||
frame.render_widget(block, popup_area);
|
|
||||||
|
|
||||||
// Render output content
|
|
||||||
let available_height = inner_area.height as usize;
|
|
||||||
let total_lines = popup.output_lines.len();
|
|
||||||
|
|
||||||
// Calculate which lines to show based on scroll offset
|
|
||||||
let start_line = popup.scroll_offset;
|
|
||||||
let end_line = (start_line + available_height).min(total_lines);
|
|
||||||
|
|
||||||
let visible_lines: Vec<Line> = popup.output_lines[start_line..end_line]
|
|
||||||
.iter()
|
|
||||||
.map(|line| {
|
|
||||||
// Style output lines with terminal colors
|
|
||||||
if line.contains("error") || line.contains("Error") || line.contains("failed") {
|
|
||||||
Line::from(Span::styled(line.clone(), Style::default().fg(Color::Red)))
|
|
||||||
} else if line.contains("warning") || line.contains("Warning") {
|
|
||||||
Line::from(Span::styled(line.clone(), Style::default().fg(Color::Yellow)))
|
|
||||||
} else if line.contains("building") || line.contains("Building") {
|
|
||||||
Line::from(Span::styled(line.clone(), Style::default().fg(Color::Blue)))
|
|
||||||
} else if line.contains("✓") || line.contains("success") || line.contains("completed") {
|
|
||||||
Line::from(Span::styled(line.clone(), Style::default().fg(Color::Green)))
|
|
||||||
} else {
|
|
||||||
Line::from(Span::styled(line.clone(), Style::default().fg(Color::White)))
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
let content = Paragraph::new(visible_lines)
|
|
||||||
.wrap(Wrap { trim: false })
|
|
||||||
.style(Style::default().bg(Color::Black));
|
|
||||||
|
|
||||||
frame.render_widget(content, inner_area);
|
|
||||||
|
|
||||||
// Render scroll indicator if needed
|
|
||||||
if total_lines > available_height {
|
|
||||||
let scroll_info = format!(" {}% ",
|
|
||||||
if total_lines > 0 {
|
|
||||||
(end_line * 100) / total_lines
|
|
||||||
} else {
|
|
||||||
100
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
let scroll_area = Rect {
|
|
||||||
x: popup_area.x + popup_area.width - scroll_info.len() as u16 - 1,
|
|
||||||
y: popup_area.y + popup_area.height - 1,
|
|
||||||
width: scroll_info.len() as u16,
|
|
||||||
height: 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
let scroll_widget = Paragraph::new(scroll_info)
|
|
||||||
.style(Style::default().fg(Color::Cyan).bg(Color::Black));
|
|
||||||
frame.render_widget(scroll_widget, scroll_area);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Instructions at bottom
|
|
||||||
let instructions = " ESC/Q: Close • ↑↓: Scroll ";
|
|
||||||
let instructions_area = Rect {
|
|
||||||
x: popup_area.x + 1,
|
|
||||||
y: popup_area.y + popup_area.height - 1,
|
|
||||||
width: instructions.len() as u16,
|
|
||||||
height: 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
let instructions_widget = Paragraph::new(instructions)
|
|
||||||
.style(Style::default().fg(Color::Gray).bg(Color::Black));
|
|
||||||
frame.render_widget(instructions_widget, instructions_area);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -289,18 +289,6 @@ impl Components {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Widget block with focus indicator (blue border)
|
|
||||||
pub fn focused_widget_block(title: &str) -> Block<'_> {
|
|
||||||
Block::default()
|
|
||||||
.title(title)
|
|
||||||
.borders(Borders::ALL)
|
|
||||||
.style(Style::default().fg(Theme::highlight()).bg(Theme::background())) // Blue border for focus
|
|
||||||
.title_style(
|
|
||||||
Style::default()
|
|
||||||
.fg(Theme::highlight()) // Blue title for focus
|
|
||||||
.bg(Theme::background()),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Typography {
|
impl Typography {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use tracing::debug;
|
|||||||
|
|
||||||
use super::Widget;
|
use super::Widget;
|
||||||
use crate::ui::theme::{Components, StatusIcons, Theme, Typography};
|
use crate::ui::theme::{Components, StatusIcons, Theme, Typography};
|
||||||
use crate::ui::{CommandStatus, CommandType};
|
use crate::ui::CommandType;
|
||||||
use ratatui::style::Style;
|
use ratatui::style::Style;
|
||||||
|
|
||||||
/// Services widget displaying hierarchical systemd service statuses
|
/// Services widget displaying hierarchical systemd service statuses
|
||||||
@@ -128,26 +128,18 @@ impl ServicesWidget {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get status icon for service, considering command status for visual feedback
|
/// Get status icon for service, considering pending transitions for visual feedback
|
||||||
fn get_service_icon_and_status(&self, service_name: &str, info: &ServiceInfo, command_status: Option<&CommandStatus>) -> (String, String, ratatui::prelude::Color) {
|
fn get_service_icon_and_status(&self, service_name: &str, info: &ServiceInfo, pending_transitions: &HashMap<String, (CommandType, String, std::time::Instant)>) -> (String, String, ratatui::prelude::Color) {
|
||||||
// Check if this service is currently being operated on
|
// Check if this service has a pending transition
|
||||||
if let Some(status) = command_status {
|
if let Some((command_type, _original_status, _start_time)) = pending_transitions.get(service_name) {
|
||||||
match status {
|
// Show transitional icons for pending commands
|
||||||
CommandStatus::InProgress { command_type, target, .. } => {
|
let (icon, status_text) = match command_type {
|
||||||
if target == service_name {
|
CommandType::ServiceStart => ("↑", "starting"),
|
||||||
// Only show special icons for service commands
|
CommandType::ServiceStop => ("↓", "stopping"),
|
||||||
if let Some((icon, status_text)) = match command_type {
|
_ => return (StatusIcons::get_icon(info.widget_status).to_string(), info.status.clone(), Theme::status_color(info.widget_status)), // Not a service command
|
||||||
CommandType::ServiceRestart => Some(("↻", "restarting")),
|
};
|
||||||
CommandType::ServiceStart => Some(("↑", "starting")),
|
|
||||||
CommandType::ServiceStop => Some(("↓", "stopping")),
|
|
||||||
_ => None, // Don't handle non-service commands here
|
|
||||||
} {
|
|
||||||
return (icon.to_string(), status_text.to_string(), Theme::highlight());
|
return (icon.to_string(), status_text.to_string(), Theme::highlight());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Normal status display
|
// Normal status display
|
||||||
let icon = StatusIcons::get_icon(info.widget_status);
|
let icon = StatusIcons::get_icon(info.widget_status);
|
||||||
@@ -163,13 +155,13 @@ impl ServicesWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Create spans for sub-service with icon next to name, considering command status
|
/// Create spans for sub-service with icon next to name, considering pending transitions
|
||||||
fn create_sub_service_spans_with_status(
|
fn create_sub_service_spans_with_transitions(
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
name: &str,
|
||||||
info: &ServiceInfo,
|
info: &ServiceInfo,
|
||||||
is_last: bool,
|
is_last: bool,
|
||||||
command_status: Option<&CommandStatus>,
|
pending_transitions: &HashMap<String, (CommandType, String, std::time::Instant)>,
|
||||||
) -> Vec<ratatui::text::Span<'static>> {
|
) -> Vec<ratatui::text::Span<'static>> {
|
||||||
// Truncate long sub-service names to fit layout (accounting for indentation)
|
// Truncate long sub-service names to fit layout (accounting for indentation)
|
||||||
let short_name = if name.len() > 18 {
|
let short_name = if name.len() > 18 {
|
||||||
@@ -178,11 +170,11 @@ impl ServicesWidget {
|
|||||||
name.to_string()
|
name.to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get status icon and text, considering command status
|
// Get status icon and text, considering pending transitions
|
||||||
let (icon, mut status_str, status_color) = self.get_service_icon_and_status(name, info, command_status);
|
let (icon, mut status_str, status_color) = self.get_service_icon_and_status(name, info, pending_transitions);
|
||||||
|
|
||||||
// For sub-services, prefer latency if available (unless command is in progress)
|
// For sub-services, prefer latency if available (unless transition is pending)
|
||||||
if command_status.is_none() {
|
if !pending_transitions.contains_key(name) {
|
||||||
if let Some(latency) = info.latency_ms {
|
if let Some(latency) = info.latency_ms {
|
||||||
status_str = if latency < 0.0 {
|
status_str = if latency < 0.0 {
|
||||||
"timeout".to_string()
|
"timeout".to_string()
|
||||||
@@ -240,13 +232,14 @@ impl ServicesWidget {
|
|||||||
/// Get currently selected service name (for actions)
|
/// Get currently selected service name (for actions)
|
||||||
pub fn get_selected_service(&self) -> Option<String> {
|
pub fn get_selected_service(&self) -> Option<String> {
|
||||||
// Build the same display list to find the selected service
|
// Build the same display list to find the selected service
|
||||||
let mut display_lines: Vec<(String, Status, bool, Option<(ServiceInfo, bool)>)> = Vec::new();
|
let mut display_lines: Vec<(String, Status, bool, Option<(ServiceInfo, bool)>, String)> = Vec::new();
|
||||||
|
|
||||||
let mut parent_services: Vec<_> = self.parent_services.iter().collect();
|
let mut parent_services: Vec<_> = self.parent_services.iter().collect();
|
||||||
parent_services.sort_by(|(a, _), (b, _)| a.cmp(b));
|
parent_services.sort_by(|(a, _), (b, _)| a.cmp(b));
|
||||||
|
|
||||||
for (parent_name, parent_info) in parent_services {
|
for (parent_name, parent_info) in parent_services {
|
||||||
display_lines.push((parent_name.clone(), parent_info.widget_status, false, None));
|
let parent_line = self.format_parent_service_line(parent_name, parent_info);
|
||||||
|
display_lines.push((parent_line, parent_info.widget_status, false, None, parent_name.clone()));
|
||||||
|
|
||||||
if let Some(sub_list) = self.sub_services.get(parent_name) {
|
if let Some(sub_list) = self.sub_services.get(parent_name) {
|
||||||
let mut sorted_subs = sub_list.clone();
|
let mut sorted_subs = sub_list.clone();
|
||||||
@@ -254,17 +247,19 @@ impl ServicesWidget {
|
|||||||
|
|
||||||
for (i, (sub_name, sub_info)) in sorted_subs.iter().enumerate() {
|
for (i, (sub_name, sub_info)) in sorted_subs.iter().enumerate() {
|
||||||
let is_last_sub = i == sorted_subs.len() - 1;
|
let is_last_sub = i == sorted_subs.len() - 1;
|
||||||
|
let full_sub_name = format!("{}_{}", parent_name, sub_name);
|
||||||
display_lines.push((
|
display_lines.push((
|
||||||
format!("{}_{}", parent_name, sub_name), // Use parent_sub format for sub-services
|
sub_name.clone(),
|
||||||
sub_info.widget_status,
|
sub_info.widget_status,
|
||||||
true,
|
true,
|
||||||
Some((sub_info.clone(), is_last_sub)),
|
Some((sub_info.clone(), is_last_sub)),
|
||||||
|
full_sub_name,
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
display_lines.get(self.selected_index).map(|(name, _, _, _)| name.clone())
|
display_lines.get(self.selected_index).map(|(_, _, _, _, raw_name)| raw_name.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get total count of selectable services (parent services only, not sub-services)
|
/// Get total count of selectable services (parent services only, not sub-services)
|
||||||
@@ -273,6 +268,26 @@ impl ServicesWidget {
|
|||||||
self.parent_services.len()
|
self.parent_services.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get current status of a specific service by name
|
||||||
|
pub fn get_service_status(&self, service_name: &str) -> Option<String> {
|
||||||
|
// Check if it's a parent service
|
||||||
|
if let Some(parent_info) = self.parent_services.get(service_name) {
|
||||||
|
return Some(parent_info.status.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check sub-services (format: parent_sub)
|
||||||
|
for (parent_name, sub_list) in &self.sub_services {
|
||||||
|
for (sub_name, sub_info) in sub_list {
|
||||||
|
let full_sub_name = format!("{}_{}", parent_name, sub_name);
|
||||||
|
if full_sub_name == service_name {
|
||||||
|
return Some(sub_info.status.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
/// Calculate which parent service index corresponds to a display line index
|
/// Calculate which parent service index corresponds to a display line index
|
||||||
fn calculate_parent_service_index(&self, display_line_index: &usize) -> usize {
|
fn calculate_parent_service_index(&self, display_line_index: &usize) -> usize {
|
||||||
// Build the same display list to map line index to parent service index
|
// Build the same display list to map line index to parent service index
|
||||||
@@ -426,13 +441,9 @@ impl Widget for ServicesWidget {
|
|||||||
|
|
||||||
impl ServicesWidget {
|
impl ServicesWidget {
|
||||||
|
|
||||||
/// Render with focus, scroll, and command status for visual feedback
|
/// Render with focus, scroll, and pending transitions for visual feedback
|
||||||
pub fn render_with_command_status(&mut self, frame: &mut Frame, area: Rect, is_focused: bool, scroll_offset: usize, command_status: Option<&CommandStatus>) {
|
pub fn render_with_transitions(&mut self, frame: &mut Frame, area: Rect, is_focused: bool, scroll_offset: usize, pending_transitions: &HashMap<String, (CommandType, String, std::time::Instant)>) {
|
||||||
let services_block = if is_focused {
|
let services_block = Components::widget_block("services");
|
||||||
Components::focused_widget_block("services")
|
|
||||||
} else {
|
|
||||||
Components::widget_block("services")
|
|
||||||
};
|
|
||||||
let inner_area = services_block.inner(area);
|
let inner_area = services_block.inner(area);
|
||||||
frame.render_widget(services_block, area);
|
frame.render_widget(services_block, area);
|
||||||
|
|
||||||
@@ -456,14 +467,14 @@ impl ServicesWidget {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use the existing render logic but with command status
|
// Use the existing render logic but with pending transitions
|
||||||
self.render_services_with_status(frame, content_chunks[1], is_focused, scroll_offset, command_status);
|
self.render_services_with_transitions(frame, content_chunks[1], is_focused, scroll_offset, pending_transitions);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render services list with command status awareness
|
/// Render services list with pending transitions awareness
|
||||||
fn render_services_with_status(&mut self, frame: &mut Frame, area: Rect, is_focused: bool, scroll_offset: usize, command_status: Option<&CommandStatus>) {
|
fn render_services_with_transitions(&mut self, frame: &mut Frame, area: Rect, is_focused: bool, scroll_offset: usize, pending_transitions: &HashMap<String, (CommandType, String, std::time::Instant)>) {
|
||||||
// Build hierarchical service list for display (same as existing logic)
|
// Build hierarchical service list for display - include raw service name for pending transition lookups
|
||||||
let mut display_lines: Vec<(String, Status, bool, Option<(ServiceInfo, bool)>)> = Vec::new();
|
let mut display_lines: Vec<(String, Status, bool, Option<(ServiceInfo, bool)>, String)> = Vec::new(); // Added raw service name
|
||||||
|
|
||||||
// Sort parent services alphabetically for consistent order
|
// Sort parent services alphabetically for consistent order
|
||||||
let mut parent_services: Vec<_> = self.parent_services.iter().collect();
|
let mut parent_services: Vec<_> = self.parent_services.iter().collect();
|
||||||
@@ -472,7 +483,7 @@ impl ServicesWidget {
|
|||||||
for (parent_name, parent_info) in parent_services {
|
for (parent_name, parent_info) in parent_services {
|
||||||
// Add parent service line
|
// Add parent service line
|
||||||
let parent_line = self.format_parent_service_line(parent_name, parent_info);
|
let parent_line = self.format_parent_service_line(parent_name, parent_info);
|
||||||
display_lines.push((parent_line, parent_info.widget_status, false, None)); // false = not sub-service
|
display_lines.push((parent_line, parent_info.widget_status, false, None, parent_name.clone())); // Include raw name
|
||||||
|
|
||||||
// Add sub-services for this parent (if any)
|
// Add sub-services for this parent (if any)
|
||||||
if let Some(sub_list) = self.sub_services.get(parent_name) {
|
if let Some(sub_list) = self.sub_services.get(parent_name) {
|
||||||
@@ -482,12 +493,14 @@ impl ServicesWidget {
|
|||||||
|
|
||||||
for (i, (sub_name, sub_info)) in sorted_subs.iter().enumerate() {
|
for (i, (sub_name, sub_info)) in sorted_subs.iter().enumerate() {
|
||||||
let is_last_sub = i == sorted_subs.len() - 1;
|
let is_last_sub = i == sorted_subs.len() - 1;
|
||||||
|
let full_sub_name = format!("{}_{}", parent_name, sub_name);
|
||||||
// Store sub-service info for custom span rendering
|
// Store sub-service info for custom span rendering
|
||||||
display_lines.push((
|
display_lines.push((
|
||||||
sub_name.clone(),
|
sub_name.clone(),
|
||||||
sub_info.widget_status,
|
sub_info.widget_status,
|
||||||
true,
|
true,
|
||||||
Some((sub_info.clone(), is_last_sub)),
|
Some((sub_info.clone(), is_last_sub)),
|
||||||
|
full_sub_name, // Raw service name for pending transition lookup
|
||||||
)); // true = sub-service, with is_last info
|
)); // true = sub-service, with is_last info
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -520,7 +533,7 @@ impl ServicesWidget {
|
|||||||
.constraints(vec![Constraint::Length(1); lines_to_show])
|
.constraints(vec![Constraint::Length(1); lines_to_show])
|
||||||
.split(area);
|
.split(area);
|
||||||
|
|
||||||
for (i, (line_text, line_status, is_sub, sub_info)) in visible_lines.iter().enumerate()
|
for (i, (line_text, line_status, is_sub, sub_info, raw_service_name)) in visible_lines.iter().enumerate()
|
||||||
{
|
{
|
||||||
let actual_index = effective_scroll + i; // Real index in the full list
|
let actual_index = effective_scroll + i; // Real index in the full list
|
||||||
|
|
||||||
@@ -534,46 +547,48 @@ impl ServicesWidget {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut spans = if *is_sub && sub_info.is_some() {
|
let mut spans = if *is_sub && sub_info.is_some() {
|
||||||
// Use custom sub-service span creation WITH command status
|
// Use custom sub-service span creation WITH pending transitions
|
||||||
let (service_info, is_last) = sub_info.as_ref().unwrap();
|
let (service_info, is_last) = sub_info.as_ref().unwrap();
|
||||||
self.create_sub_service_spans_with_status(line_text, service_info, *is_last, command_status)
|
self.create_sub_service_spans_with_transitions(line_text, service_info, *is_last, pending_transitions)
|
||||||
} else {
|
} else {
|
||||||
// Parent services - check if this parent service has a command in progress
|
// Parent services - check if this parent service has a pending transition using RAW service name
|
||||||
let service_spans = if let Some(status) = command_status {
|
if pending_transitions.contains_key(raw_service_name) {
|
||||||
match status {
|
// Create spans with transitional status
|
||||||
CommandStatus::InProgress { target, .. } => {
|
let (icon, status_text, _) = self.get_service_icon_and_status(raw_service_name, &ServiceInfo {
|
||||||
if target == line_text {
|
|
||||||
// Create spans with progress status
|
|
||||||
let (icon, status_text, status_color) = self.get_service_icon_and_status(line_text, &ServiceInfo {
|
|
||||||
status: "".to_string(),
|
status: "".to_string(),
|
||||||
memory_mb: None,
|
memory_mb: None,
|
||||||
disk_gb: None,
|
disk_gb: None,
|
||||||
latency_ms: None,
|
latency_ms: None,
|
||||||
widget_status: *line_status
|
widget_status: *line_status
|
||||||
}, command_status);
|
}, pending_transitions);
|
||||||
|
|
||||||
|
// Use blue for transitional icons when not selected, background color when selected
|
||||||
|
let icon_color = if is_selected && !*is_sub && is_focused {
|
||||||
|
Theme::background() // Dark background color for visibility against blue selection
|
||||||
|
} else {
|
||||||
|
Theme::highlight() // Blue for normal case
|
||||||
|
};
|
||||||
|
|
||||||
vec![
|
vec![
|
||||||
ratatui::text::Span::styled(format!("{} ", icon), Style::default().fg(status_color)),
|
ratatui::text::Span::styled(format!("{} ", icon), Style::default().fg(icon_color)),
|
||||||
ratatui::text::Span::styled(line_text.clone(), Style::default().fg(Theme::primary_text())),
|
ratatui::text::Span::styled(line_text.clone(), Style::default().fg(Theme::primary_text())),
|
||||||
ratatui::text::Span::styled(format!(" {}", status_text), Style::default().fg(status_color)),
|
ratatui::text::Span::styled(format!(" {}", status_text), Style::default().fg(icon_color)),
|
||||||
]
|
]
|
||||||
} else {
|
} else {
|
||||||
StatusIcons::create_status_spans(*line_status, line_text)
|
StatusIcons::create_status_spans(*line_status, line_text)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
StatusIcons::create_status_spans(*line_status, line_text)
|
|
||||||
};
|
|
||||||
service_spans
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Apply selection highlighting to parent services only, preserving status icon color
|
// Apply selection highlighting to parent services only, making icons background color when selected
|
||||||
// Only show selection when Services panel is focused
|
// Only show selection when Services panel is focused
|
||||||
|
// Show selection highlighting even when transitional icons are present
|
||||||
if is_selected && !*is_sub && is_focused {
|
if is_selected && !*is_sub && is_focused {
|
||||||
for (i, span) in spans.iter_mut().enumerate() {
|
for (i, span) in spans.iter_mut().enumerate() {
|
||||||
if i == 0 {
|
if i == 0 {
|
||||||
// First span is the status icon - preserve its color
|
// First span is the status icon - use background color for visibility against blue selection
|
||||||
span.style = span.style.bg(Theme::highlight());
|
span.style = span.style
|
||||||
|
.bg(Theme::highlight())
|
||||||
|
.fg(Theme::background());
|
||||||
} else {
|
} else {
|
||||||
// Other spans (text) get full selection highlighting
|
// Other spans (text) get full selection highlighting
|
||||||
span.style = span.style
|
span.style = span.style
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ pub struct SystemWidget {
|
|||||||
// NixOS information
|
// NixOS information
|
||||||
nixos_build: Option<String>,
|
nixos_build: Option<String>,
|
||||||
config_hash: Option<String>,
|
config_hash: Option<String>,
|
||||||
active_users: Option<String>,
|
|
||||||
agent_hash: Option<String>,
|
agent_hash: Option<String>,
|
||||||
|
|
||||||
// CPU metrics
|
// CPU metrics
|
||||||
@@ -33,6 +32,7 @@ pub struct SystemWidget {
|
|||||||
tmp_used_gb: Option<f32>,
|
tmp_used_gb: Option<f32>,
|
||||||
tmp_total_gb: Option<f32>,
|
tmp_total_gb: Option<f32>,
|
||||||
memory_status: Status,
|
memory_status: Status,
|
||||||
|
tmp_status: Status,
|
||||||
|
|
||||||
// Storage metrics (collected from disk metrics)
|
// Storage metrics (collected from disk metrics)
|
||||||
storage_pools: Vec<StoragePool>,
|
storage_pools: Vec<StoragePool>,
|
||||||
@@ -66,7 +66,6 @@ impl SystemWidget {
|
|||||||
Self {
|
Self {
|
||||||
nixos_build: None,
|
nixos_build: None,
|
||||||
config_hash: None,
|
config_hash: None,
|
||||||
active_users: None,
|
|
||||||
agent_hash: None,
|
agent_hash: None,
|
||||||
cpu_load_1min: None,
|
cpu_load_1min: None,
|
||||||
cpu_load_5min: None,
|
cpu_load_5min: None,
|
||||||
@@ -80,6 +79,7 @@ impl SystemWidget {
|
|||||||
tmp_used_gb: None,
|
tmp_used_gb: None,
|
||||||
tmp_total_gb: None,
|
tmp_total_gb: None,
|
||||||
memory_status: Status::Unknown,
|
memory_status: Status::Unknown,
|
||||||
|
tmp_status: Status::Unknown,
|
||||||
storage_pools: Vec::new(),
|
storage_pools: Vec::new(),
|
||||||
has_data: false,
|
has_data: false,
|
||||||
}
|
}
|
||||||
@@ -230,20 +230,49 @@ impl SystemWidget {
|
|||||||
|
|
||||||
/// Extract pool name from disk metric name
|
/// Extract pool name from disk metric name
|
||||||
fn extract_pool_name(&self, metric_name: &str) -> Option<String> {
|
fn extract_pool_name(&self, metric_name: &str) -> Option<String> {
|
||||||
if let Some(captures) = metric_name.strip_prefix("disk_") {
|
// Pattern: disk_{pool_name}_{drive_name}_{metric_type}
|
||||||
|
// Since pool_name can contain underscores, work backwards from known metric suffixes
|
||||||
|
if metric_name.starts_with("disk_") {
|
||||||
|
// First try drive-specific metrics that have device names
|
||||||
|
if let Some(suffix_pos) = metric_name.rfind("_temperature")
|
||||||
|
.or_else(|| metric_name.rfind("_wear_percent"))
|
||||||
|
.or_else(|| metric_name.rfind("_health")) {
|
||||||
|
// Find the second-to-last underscore to get pool name
|
||||||
|
let before_suffix = &metric_name[..suffix_pos];
|
||||||
|
if let Some(drive_start) = before_suffix.rfind('_') {
|
||||||
|
return Some(metric_name[5..drive_start].to_string()); // Skip "disk_"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// For pool-level metrics (usage_percent, used_gb, total_gb), take everything before the metric suffix
|
||||||
|
else if let Some(suffix_pos) = metric_name.rfind("_usage_percent")
|
||||||
|
.or_else(|| metric_name.rfind("_used_gb"))
|
||||||
|
.or_else(|| metric_name.rfind("_total_gb")) {
|
||||||
|
return Some(metric_name[5..suffix_pos].to_string()); // Skip "disk_"
|
||||||
|
}
|
||||||
|
// Fallback to old behavior for unknown patterns
|
||||||
|
else if let Some(captures) = metric_name.strip_prefix("disk_") {
|
||||||
if let Some(pos) = captures.find('_') {
|
if let Some(pos) = captures.find('_') {
|
||||||
return Some(captures[..pos].to_string());
|
return Some(captures[..pos].to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract drive name from disk metric name
|
/// Extract drive name from disk metric name
|
||||||
fn extract_drive_name(&self, metric_name: &str) -> Option<String> {
|
fn extract_drive_name(&self, metric_name: &str) -> Option<String> {
|
||||||
// Pattern: disk_pool_drive_metric
|
// Pattern: disk_{pool_name}_{drive_name}_{metric_type}
|
||||||
let parts: Vec<&str> = metric_name.split('_').collect();
|
// Since pool_name can contain underscores, work backwards from known metric suffixes
|
||||||
if parts.len() >= 3 && parts[0] == "disk" {
|
if metric_name.starts_with("disk_") {
|
||||||
return Some(parts[2].to_string());
|
if let Some(suffix_pos) = metric_name.rfind("_temperature")
|
||||||
|
.or_else(|| metric_name.rfind("_wear_percent"))
|
||||||
|
.or_else(|| metric_name.rfind("_health")) {
|
||||||
|
// Find the second-to-last underscore to get the drive name
|
||||||
|
let before_suffix = &metric_name[..suffix_pos];
|
||||||
|
if let Some(drive_start) = before_suffix.rfind('_') {
|
||||||
|
return Some(before_suffix[drive_start + 1..].to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -334,11 +363,6 @@ impl Widget for SystemWidget {
|
|||||||
self.config_hash = Some(hash.clone());
|
self.config_hash = Some(hash.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"system_active_users" => {
|
|
||||||
if let MetricValue::String(users) = &metric.value {
|
|
||||||
self.active_users = Some(users.clone());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"agent_version" => {
|
"agent_version" => {
|
||||||
if let MetricValue::String(version) = &metric.value {
|
if let MetricValue::String(version) = &metric.value {
|
||||||
self.agent_hash = Some(version.clone());
|
self.agent_hash = Some(version.clone());
|
||||||
@@ -390,6 +414,7 @@ impl Widget for SystemWidget {
|
|||||||
"memory_tmp_usage_percent" => {
|
"memory_tmp_usage_percent" => {
|
||||||
if let MetricValue::Float(usage) = metric.value {
|
if let MetricValue::Float(usage) = metric.value {
|
||||||
self.tmp_usage_percent = Some(usage);
|
self.tmp_usage_percent = Some(usage);
|
||||||
|
self.tmp_status = metric.status.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"memory_tmp_used_gb" => {
|
"memory_tmp_used_gb" => {
|
||||||
@@ -432,10 +457,6 @@ impl SystemWidget {
|
|||||||
Span::styled(format!("Agent: {}", agent_version_text), Typography::secondary())
|
Span::styled(format!("Agent: {}", agent_version_text), Typography::secondary())
|
||||||
]));
|
]));
|
||||||
|
|
||||||
let users_text = self.active_users.as_deref().unwrap_or("unknown");
|
|
||||||
lines.push(Line::from(vec![
|
|
||||||
Span::styled(format!("Active users: {}", users_text), Typography::secondary())
|
|
||||||
]));
|
|
||||||
|
|
||||||
// CPU section
|
// CPU section
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
@@ -472,7 +493,7 @@ impl SystemWidget {
|
|||||||
Span::styled(" └─ ", Typography::tree()),
|
Span::styled(" └─ ", Typography::tree()),
|
||||||
];
|
];
|
||||||
tmp_spans.extend(StatusIcons::create_status_spans(
|
tmp_spans.extend(StatusIcons::create_status_spans(
|
||||||
self.memory_status.clone(),
|
self.tmp_status.clone(),
|
||||||
&format!("/tmp: {}", tmp_text)
|
&format!("/tmp: {}", tmp_text)
|
||||||
));
|
));
|
||||||
lines.push(Line::from(tmp_spans));
|
lines.push(Line::from(tmp_spans));
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.18"
|
version = "0.1.38"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
Reference in New Issue
Block a user