Compare commits
72 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 7c030b33d6 | |||
| c6817537a8 | |||
| 2189d34b16 | |||
| 28cfd5758f | |||
| 5deb8cf8d8 | |||
| 0e01813ff5 | |||
| c3c9507a42 | |||
| 4d77ffe17e | |||
| 14f74b4cac | |||
| 67b686f8c7 | |||
| e3996fdb84 | |||
| f94ca60e69 | |||
| c19ff56df8 | |||
| fe2f604703 | |||
| 8bfd416327 | |||
| 85c6c624fb | |||
| eab3f17428 | |||
| 7ad149bbe4 | |||
| b444c88ea0 | |||
| 317cf76bd1 | |||
| 0db1a165b9 | |||
| 3c2955376d | |||
| f09ccabc7f | |||
| 43dd5a901a | |||
| 01e1f33b66 | |||
| ed6399b914 | |||
| 14618c59c6 | |||
| 2740de9b54 | |||
| 37f2650200 | |||
| 833010e270 | |||
| 549d9d1c72 | |||
| 9b84b70581 | |||
| 92c3ee3f2a | |||
| 1be55f765d | |||
| 2f94a4b853 | |||
| ff2b43827a | |||
| fac0188c6f | |||
| 6bb350f016 | |||
| 374b126446 | |||
| 76c04633b5 | |||
| 1e0510be81 | |||
| 9a2df906ea | |||
| 6d6beb207d | |||
| 7a68da01f5 | |||
| 5be67fed64 | |||
| cac836601b | |||
| bd22ce265b | |||
| bbc8b7b1cb | |||
| 5dd8cadef3 | |||
| fefe30ec51 | |||
| fb40cce748 | |||
| eaa057b284 | |||
| f23a1b5cec | |||
| 3f98f68b51 | |||
| 3d38a7a984 | |||
| b0ee0242bd | |||
| 8f9e9eabca | |||
| 937f4ad427 | |||
| 8aefab83ae | |||
| 748a9f3a3b | |||
| 5c6b11c794 | |||
| 9f0aa5f806 | |||
| fc247bd0ad | |||
| 00fe8c28ab | |||
| fbbb4a4cfb | |||
| 53e1d8bbce | |||
| 1b9fecea98 | |||
| b7ffeaced5 | |||
| 3858309a5d | |||
| df104bf940 | |||
| d5ce36ee18 | |||
| 4f80701671 |
@@ -113,13 +113,13 @@ jobs:
|
|||||||
NIX_HASH="sha256-$(python3 -c "import base64, binascii; print(base64.b64encode(binascii.unhexlify('$NEW_HASH')).decode())")"
|
NIX_HASH="sha256-$(python3 -c "import base64, binascii; print(base64.b64encode(binascii.unhexlify('$NEW_HASH')).decode())")"
|
||||||
|
|
||||||
# Update the NixOS configuration
|
# Update the NixOS configuration
|
||||||
sed -i "s|version = \"v[^\"]*\"|version = \"$VERSION\"|" hosts/services/cm-dashboard.nix
|
sed -i "s|version = \"v[^\"]*\"|version = \"$VERSION\"|" services/cm-dashboard.nix
|
||||||
sed -i "s|sha256 = \"sha256-[^\"]*\"|sha256 = \"$NIX_HASH\"|" hosts/services/cm-dashboard.nix
|
sed -i "s|sha256 = \"sha256-[^\"]*\"|sha256 = \"$NIX_HASH\"|" services/cm-dashboard.nix
|
||||||
|
|
||||||
# Commit and push changes
|
# Commit and push changes
|
||||||
git config user.name "Gitea Actions"
|
git config user.name "Gitea Actions"
|
||||||
git config user.email "actions@gitea.cmtec.se"
|
git config user.email "actions@gitea.cmtec.se"
|
||||||
git add hosts/services/cm-dashboard.nix
|
git add services/cm-dashboard.nix
|
||||||
git commit -m "Auto-update cm-dashboard to $VERSION
|
git commit -m "Auto-update cm-dashboard to $VERSION
|
||||||
|
|
||||||
- Update version to $VERSION with automated release
|
- Update version to $VERSION with automated release
|
||||||
|
|||||||
116
CLAUDE.md
116
CLAUDE.md
@@ -304,28 +304,28 @@ exclude_fs_types = ["tmpfs", "devtmpfs", "sysfs", "proc"]
|
|||||||
### Display Format
|
### Display Format
|
||||||
|
|
||||||
```
|
```
|
||||||
|
Network:
|
||||||
|
● eno1:
|
||||||
|
├─ ip: 192.168.30.105
|
||||||
|
└─ tailscale0: 100.125.108.16
|
||||||
|
● eno2:
|
||||||
|
└─ ip: 192.168.32.105
|
||||||
CPU:
|
CPU:
|
||||||
● Load: 0.23 0.21 0.13
|
● Load: 0.23 0.21 0.13
|
||||||
└─ Freq: 1048 MHz
|
└─ Freq: 1048 MHz
|
||||||
|
|
||||||
RAM:
|
RAM:
|
||||||
● Usage: 25% 5.8GB/23.3GB
|
● Usage: 25% 5.8GB/23.3GB
|
||||||
├─ ● /tmp: 2% 0.5GB/2GB
|
├─ ● /tmp: 2% 0.5GB/2GB
|
||||||
└─ ● /var/tmp: 0% 0GB/1.0GB
|
└─ ● /var/tmp: 0% 0GB/1.0GB
|
||||||
|
|
||||||
Storage:
|
Storage:
|
||||||
● mergerfs (2+1):
|
● 844B9A25 T: 25C W: 4%
|
||||||
├─ Total: ● 63% 2355.2GB/3686.4GB
|
|
||||||
├─ Data Disks:
|
|
||||||
│ ├─ ● sdb T: 24°C W: 5%
|
|
||||||
│ └─ ● sdd T: 27°C W: 5%
|
|
||||||
├─ Parity: ● sdc T: 24°C W: 5%
|
|
||||||
└─ Mount: /srv/media
|
|
||||||
|
|
||||||
● nvme0n1 T: 25C W: 4%
|
|
||||||
├─ ● /: 55% 250.5GB/456.4GB
|
├─ ● /: 55% 250.5GB/456.4GB
|
||||||
└─ ● /boot: 26% 0.3GB/1.0GB
|
└─ ● /boot: 26% 0.3GB/1.0GB
|
||||||
|
● mergerfs /srv/media:
|
||||||
|
├─ ● 63% 2355.2GB/3686.4GB
|
||||||
|
├─ ● Data_1: WDZQ8H8D T: 28°C
|
||||||
|
├─ ● Data_2: GGA04461 T: 28°C
|
||||||
|
└─ ● Parity: WDZS8RY0 T: 29°C
|
||||||
Backup:
|
Backup:
|
||||||
● WD-WCC7K1234567 T: 32°C W: 12%
|
● WD-WCC7K1234567 T: 32°C W: 12%
|
||||||
├─ Last: 2h ago (12.3GB)
|
├─ Last: 2h ago (12.3GB)
|
||||||
@@ -361,98 +361,6 @@ Keep responses concise and focused. Avoid extensive implementation summaries unl
|
|||||||
- ✅ "Restructure storage widget with improved layout"
|
- ✅ "Restructure storage widget with improved layout"
|
||||||
- ✅ "Update CPU thresholds to production values"
|
- ✅ "Update CPU thresholds to production values"
|
||||||
|
|
||||||
## Completed Architecture Migration (v0.1.131)
|
|
||||||
|
|
||||||
## ✅ COMPLETE MONITORING SYSTEM RESTORATION (v0.1.141)
|
|
||||||
|
|
||||||
**🎉 SUCCESS: All Issues Fixed - Complete Functional Monitoring System**
|
|
||||||
|
|
||||||
### ✅ Completed Implementation (v0.1.141)
|
|
||||||
|
|
||||||
**All Major Issues Resolved:**
|
|
||||||
```
|
|
||||||
✅ Data Collection: Agent collects structured data correctly
|
|
||||||
✅ Storage Display: Perfect format with correct mount points and temperature/wear
|
|
||||||
✅ Status Evaluation: All metrics properly evaluated against thresholds
|
|
||||||
✅ Notifications: Working email alerts on status changes
|
|
||||||
✅ Thresholds: All collectors using configured thresholds for status calculation
|
|
||||||
✅ Build Information: NixOS version displayed correctly
|
|
||||||
✅ Mount Point Consistency: Stable, sorted display order
|
|
||||||
```
|
|
||||||
|
|
||||||
### ✅ All Phases Completed Successfully
|
|
||||||
|
|
||||||
#### ✅ Phase 1: Storage Display - COMPLETED
|
|
||||||
- ✅ Use `lsblk` instead of `findmnt` (eliminated `/nix/store` bind mount issue)
|
|
||||||
- ✅ Add `sudo smartctl` for permissions (SMART data collection working)
|
|
||||||
- ✅ Fix NVMe SMART parsing (`Temperature:` and `Percentage Used:` fields)
|
|
||||||
- ✅ Consistent filesystem/tmpfs sorting (no more random order swapping)
|
|
||||||
- ✅ **VERIFIED**: Dashboard shows `● nvme0n1 T: 28°C W: 1%` correctly
|
|
||||||
|
|
||||||
#### ✅ Phase 2: Status Evaluation System - COMPLETED
|
|
||||||
- ✅ **CPU Status**: Load averages and temperature evaluated against `HysteresisThresholds`
|
|
||||||
- ✅ **Memory Status**: Usage percentage evaluated against thresholds
|
|
||||||
- ✅ **Storage Status**: Drive temperature, health, and filesystem usage evaluated
|
|
||||||
- ✅ **Service Status**: Service states properly tracked and evaluated
|
|
||||||
- ✅ **Status Fields**: All AgentData structures include status information
|
|
||||||
- ✅ **Threshold Integration**: All collectors use their configured thresholds
|
|
||||||
|
|
||||||
#### ✅ Phase 3: Notification System - COMPLETED
|
|
||||||
- ✅ **Status Change Detection**: Agent tracks status between collection cycles
|
|
||||||
- ✅ **Email Notifications**: Alerts sent on degradation (OK→Warning/Critical, Warning→Critical)
|
|
||||||
- ✅ **Notification Content**: Detailed alerts with metric values and timestamps
|
|
||||||
- ✅ **NotificationManager Integration**: Fully restored and operational
|
|
||||||
- ✅ **Maintenance Mode**: `/tmp/cm-maintenance` file support maintained
|
|
||||||
|
|
||||||
#### ✅ Phase 4: Integration & Testing - COMPLETED
|
|
||||||
- ✅ **AgentData Status Fields**: All structured data includes status evaluation
|
|
||||||
- ✅ **Status Processing**: Agent applies thresholds at collection time
|
|
||||||
- ✅ **End-to-End Flow**: Collection → Evaluation → Notification → Display
|
|
||||||
- ✅ **Dynamic Versioning**: Agent version from `CARGO_PKG_VERSION`
|
|
||||||
- ✅ **Build Information**: NixOS generation display restored
|
|
||||||
|
|
||||||
### ✅ Final Architecture - WORKING
|
|
||||||
|
|
||||||
**Complete Operational Flow:**
|
|
||||||
```
|
|
||||||
Collectors → AgentData (with Status) → NotificationManager → Email Alerts
|
|
||||||
↘ ↗
|
|
||||||
ZMQ → Dashboard → Perfect Display
|
|
||||||
```
|
|
||||||
|
|
||||||
**Operational Components:**
|
|
||||||
1. ✅ **Collectors**: Populate AgentData with metrics AND status evaluation
|
|
||||||
2. ✅ **Status Evaluation**: `HysteresisThresholds.evaluate()` applied per collector
|
|
||||||
3. ✅ **Notifications**: Email alerts on status change detection
|
|
||||||
4. ✅ **Display**: Correct mount points, temperature, wear, and build information
|
|
||||||
|
|
||||||
### ✅ Success Criteria - ALL MET
|
|
||||||
|
|
||||||
**Display Requirements:**
|
|
||||||
- ✅ Dashboard shows `● nvme0n1 T: 28°C W: 1%` format perfectly
|
|
||||||
- ✅ Mount points show `/` and `/boot` (not `root`/`boot`)
|
|
||||||
- ✅ Build information shows actual NixOS version (not "unknown")
|
|
||||||
- ✅ Consistent sorting eliminates random order changes
|
|
||||||
|
|
||||||
**Monitoring Requirements:**
|
|
||||||
- ✅ High CPU load triggers Warning/Critical status and email alert
|
|
||||||
- ✅ High memory usage triggers Warning/Critical status and email alert
|
|
||||||
- ✅ High disk temperature triggers Warning/Critical status and email alert
|
|
||||||
- ✅ Failed services trigger Warning/Critical status and email alert
|
|
||||||
- ✅ Maintenance mode suppresses notifications as expected
|
|
||||||
|
|
||||||
### 🚀 Production Ready
|
|
||||||
|
|
||||||
**CM Dashboard v0.1.141 is a complete, functional infrastructure monitoring system:**
|
|
||||||
|
|
||||||
- **Real-time Monitoring**: All system components with 1-second intervals
|
|
||||||
- **Intelligent Alerting**: Email notifications on threshold violations
|
|
||||||
- **Perfect Display**: Accurate mount points, temperatures, and system information
|
|
||||||
- **Status-Aware**: All metrics evaluated against configurable thresholds
|
|
||||||
- **Production Ready**: Full monitoring capabilities restored
|
|
||||||
|
|
||||||
**The monitoring system is fully operational and ready for production use.**
|
|
||||||
|
|
||||||
## Implementation Rules
|
## Implementation Rules
|
||||||
|
|
||||||
1. **Agent Status Authority**: Agent calculates status for each metric using thresholds
|
1. **Agent Status Authority**: Agent calculates status for each metric using thresholds
|
||||||
|
|||||||
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.156"
|
version = "0.1.208"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -301,7 +301,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.156"
|
version = "0.1.208"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -324,7 +324,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.156"
|
version = "0.1.208"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.156"
|
version = "0.1.209"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use std::time::Duration;
|
|||||||
use tokio::time::interval;
|
use tokio::time::interval;
|
||||||
use tracing::{debug, error, info};
|
use tracing::{debug, error, info};
|
||||||
|
|
||||||
use crate::communication::{AgentCommand, ZmqHandler};
|
use crate::communication::ZmqHandler;
|
||||||
use crate::config::AgentConfig;
|
use crate::config::AgentConfig;
|
||||||
use crate::collectors::{
|
use crate::collectors::{
|
||||||
Collector,
|
Collector,
|
||||||
@@ -12,11 +12,11 @@ use crate::collectors::{
|
|||||||
cpu::CpuCollector,
|
cpu::CpuCollector,
|
||||||
disk::DiskCollector,
|
disk::DiskCollector,
|
||||||
memory::MemoryCollector,
|
memory::MemoryCollector,
|
||||||
|
network::NetworkCollector,
|
||||||
nixos::NixOSCollector,
|
nixos::NixOSCollector,
|
||||||
systemd::SystemdCollector,
|
systemd::SystemdCollector,
|
||||||
};
|
};
|
||||||
use crate::notifications::NotificationManager;
|
use crate::notifications::NotificationManager;
|
||||||
use crate::service_tracker::UserStoppedServiceTracker;
|
|
||||||
use cm_dashboard_shared::AgentData;
|
use cm_dashboard_shared::AgentData;
|
||||||
|
|
||||||
pub struct Agent {
|
pub struct Agent {
|
||||||
@@ -25,7 +25,6 @@ pub struct Agent {
|
|||||||
zmq_handler: ZmqHandler,
|
zmq_handler: ZmqHandler,
|
||||||
collectors: Vec<Box<dyn Collector>>,
|
collectors: Vec<Box<dyn Collector>>,
|
||||||
notification_manager: NotificationManager,
|
notification_manager: NotificationManager,
|
||||||
service_tracker: UserStoppedServiceTracker,
|
|
||||||
previous_status: Option<SystemStatus>,
|
previous_status: Option<SystemStatus>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +78,11 @@ impl Agent {
|
|||||||
if config.collectors.backup.enabled {
|
if config.collectors.backup.enabled {
|
||||||
collectors.push(Box::new(BackupCollector::new()));
|
collectors.push(Box::new(BackupCollector::new()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.collectors.network.enabled {
|
||||||
|
collectors.push(Box::new(NetworkCollector::new(config.collectors.network.clone())));
|
||||||
|
}
|
||||||
|
|
||||||
if config.collectors.nixos.enabled {
|
if config.collectors.nixos.enabled {
|
||||||
collectors.push(Box::new(NixOSCollector::new(config.collectors.nixos.clone())));
|
collectors.push(Box::new(NixOSCollector::new(config.collectors.nixos.clone())));
|
||||||
}
|
}
|
||||||
@@ -90,17 +93,12 @@ impl Agent {
|
|||||||
let notification_manager = NotificationManager::new(&config.notifications, &hostname)?;
|
let notification_manager = NotificationManager::new(&config.notifications, &hostname)?;
|
||||||
info!("Notification manager initialized");
|
info!("Notification manager initialized");
|
||||||
|
|
||||||
// Initialize service tracker
|
|
||||||
let service_tracker = UserStoppedServiceTracker::new();
|
|
||||||
info!("Service tracker initialized");
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
hostname,
|
hostname,
|
||||||
config,
|
config,
|
||||||
zmq_handler,
|
zmq_handler,
|
||||||
collectors,
|
collectors,
|
||||||
notification_manager,
|
notification_manager,
|
||||||
service_tracker,
|
|
||||||
previous_status: None,
|
previous_status: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -136,12 +134,6 @@ impl Agent {
|
|||||||
// NOTE: With structured data, we might need to implement status tracking differently
|
// NOTE: With structured data, we might need to implement status tracking differently
|
||||||
// For now, we skip this until status evaluation is migrated
|
// For now, we skip this until status evaluation is migrated
|
||||||
}
|
}
|
||||||
// Handle incoming commands (check periodically)
|
|
||||||
_ = tokio::time::sleep(Duration::from_millis(100)) => {
|
|
||||||
if let Err(e) = self.handle_commands().await {
|
|
||||||
error!("Error handling commands: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ = &mut shutdown_rx => {
|
_ = &mut shutdown_rx => {
|
||||||
info!("Shutdown signal received, stopping agent loop");
|
info!("Shutdown signal received, stopping agent loop");
|
||||||
break;
|
break;
|
||||||
@@ -261,36 +253,4 @@ impl Agent {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle incoming commands from dashboard
|
|
||||||
async fn handle_commands(&mut self) -> Result<()> {
|
|
||||||
// Try to receive a command (non-blocking)
|
|
||||||
if let Ok(Some(command)) = self.zmq_handler.try_receive_command() {
|
|
||||||
info!("Received command: {:?}", command);
|
|
||||||
|
|
||||||
match command {
|
|
||||||
AgentCommand::CollectNow => {
|
|
||||||
info!("Received immediate collection request");
|
|
||||||
if let Err(e) = self.collect_and_broadcast().await {
|
|
||||||
error!("Failed to collect on demand: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
AgentCommand::SetInterval { seconds } => {
|
|
||||||
info!("Received interval change request: {}s", seconds);
|
|
||||||
// Note: This would require more complex handling to update the interval
|
|
||||||
// For now, just acknowledge
|
|
||||||
}
|
|
||||||
AgentCommand::ToggleCollector { name, enabled } => {
|
|
||||||
info!("Received collector toggle request: {} -> {}", name, enabled);
|
|
||||||
// Note: This would require more complex handling to enable/disable collectors
|
|
||||||
// For now, just acknowledge
|
|
||||||
}
|
|
||||||
AgentCommand::Ping => {
|
|
||||||
info!("Received ping command");
|
|
||||||
// Maybe send back a pong or status
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,4 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use chrono::{NaiveDateTime, DateTime};
|
|
||||||
use cm_dashboard_shared::{AgentData, BackupData, BackupDiskData};
|
use cm_dashboard_shared::{AgentData, BackupData, BackupDiskData};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|||||||
@@ -119,36 +119,56 @@ impl CpuCollector {
|
|||||||
utils::parse_u64(content.trim())
|
utils::parse_u64(content.trim())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Collect CPU frequency and populate AgentData
|
/// Collect CPU C-state (idle depth) and populate AgentData with top 3 C-states by usage
|
||||||
async fn collect_frequency(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
async fn collect_cstate(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
||||||
// Try scaling frequency first (more accurate for current frequency)
|
// Read C-state usage from first CPU (representative of overall system)
|
||||||
if let Ok(freq) =
|
// C-states indicate CPU idle depth: C1=light sleep, C6=deep sleep, C10=deepest
|
||||||
utils::read_proc_file("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq")
|
|
||||||
{
|
|
||||||
if let Ok(freq_khz) = utils::parse_u64(freq.trim()) {
|
|
||||||
let freq_mhz = freq_khz as f32 / 1000.0;
|
|
||||||
agent_data.system.cpu.frequency_mhz = freq_mhz;
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fallback: parse /proc/cpuinfo for base frequency
|
let mut cstate_times: Vec<(String, u64)> = Vec::new();
|
||||||
if let Ok(content) = utils::read_proc_file("/proc/cpuinfo") {
|
let mut total_time: u64 = 0;
|
||||||
for line in content.lines() {
|
|
||||||
if line.starts_with("cpu MHz") {
|
// Collect all C-state times from CPU0
|
||||||
if let Some(freq_str) = line.split(':').nth(1) {
|
for state_num in 0..=10 {
|
||||||
if let Ok(freq_mhz) = utils::parse_f32(freq_str) {
|
let time_path = format!("/sys/devices/system/cpu/cpu0/cpuidle/state{}/time", state_num);
|
||||||
agent_data.system.cpu.frequency_mhz = freq_mhz;
|
let name_path = format!("/sys/devices/system/cpu/cpu0/cpuidle/state{}/name", state_num);
|
||||||
return Ok(());
|
|
||||||
|
if let Ok(time_str) = utils::read_proc_file(&time_path) {
|
||||||
|
if let Ok(time) = utils::parse_u64(time_str.trim()) {
|
||||||
|
if let Ok(name) = utils::read_proc_file(&name_path) {
|
||||||
|
let state_name = name.trim().to_string();
|
||||||
|
// Skip POLL state (not real idle)
|
||||||
|
if state_name != "POLL" && time > 0 {
|
||||||
|
cstate_times.push((state_name, time));
|
||||||
|
total_time += time;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break; // Only need first CPU entry
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
// No more states available
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
debug!("CPU frequency not available");
|
// Sort by time descending to get top 3
|
||||||
// Leave frequency as 0.0 if not available
|
cstate_times.sort_by(|a, b| b.1.cmp(&a.1));
|
||||||
|
|
||||||
|
// Calculate percentages for top 3 and populate AgentData
|
||||||
|
agent_data.system.cpu.cstates = cstate_times
|
||||||
|
.iter()
|
||||||
|
.take(3)
|
||||||
|
.map(|(name, time)| {
|
||||||
|
let percent = if total_time > 0 {
|
||||||
|
(*time as f32 / total_time as f32) * 100.0
|
||||||
|
} else {
|
||||||
|
0.0
|
||||||
|
};
|
||||||
|
cm_dashboard_shared::CStateInfo {
|
||||||
|
name: name.clone(),
|
||||||
|
percent,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -165,8 +185,8 @@ impl Collector for CpuCollector {
|
|||||||
// Collect temperature (optional)
|
// Collect temperature (optional)
|
||||||
self.collect_temperature(agent_data).await?;
|
self.collect_temperature(agent_data).await?;
|
||||||
|
|
||||||
// Collect frequency (optional)
|
// Collect C-state (CPU idle depth)
|
||||||
self.collect_frequency(agent_data).await?;
|
self.collect_cstate(agent_data).await?;
|
||||||
|
|
||||||
let duration = start.elapsed();
|
let duration = start.elapsed();
|
||||||
debug!("CPU collection completed in {:?}", duration);
|
debug!("CPU collection completed in {:?}", duration);
|
||||||
|
|||||||
@@ -19,10 +19,8 @@ pub struct DiskCollector {
|
|||||||
/// A physical drive with its filesystems
|
/// A physical drive with its filesystems
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct PhysicalDrive {
|
struct PhysicalDrive {
|
||||||
name: String, // e.g., "nvme0n1", "sda"
|
name: String, // e.g., "nvme0n1", "sda"
|
||||||
health: String, // SMART health status
|
health: String, // SMART health status
|
||||||
temperature_celsius: Option<f32>, // Drive temperature
|
|
||||||
wear_percent: Option<f32>, // SSD wear level
|
|
||||||
filesystems: Vec<Filesystem>, // mounted filesystems on this drive
|
filesystems: Vec<Filesystem>, // mounted filesystems on this drive
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -114,9 +112,12 @@ impl DiskCollector {
|
|||||||
|
|
||||||
/// Get block devices and their mount points using lsblk
|
/// Get block devices and their mount points using lsblk
|
||||||
async fn get_mount_devices(&self) -> Result<HashMap<String, String>, CollectorError> {
|
async fn get_mount_devices(&self) -> Result<HashMap<String, String>, CollectorError> {
|
||||||
let output = Command::new("lsblk")
|
use super::run_command_with_timeout;
|
||||||
.args(&["-rn", "-o", "NAME,MOUNTPOINT"])
|
|
||||||
.output()
|
let mut cmd = Command::new("lsblk");
|
||||||
|
cmd.args(&["-rn", "-o", "NAME,MOUNTPOINT"]);
|
||||||
|
|
||||||
|
let output = run_command_with_timeout(cmd, 2).await
|
||||||
.map_err(|e| CollectorError::SystemRead {
|
.map_err(|e| CollectorError::SystemRead {
|
||||||
path: "block devices".to_string(),
|
path: "block devices".to_string(),
|
||||||
error: e.to_string(),
|
error: e.to_string(),
|
||||||
@@ -188,8 +189,8 @@ impl DiskCollector {
|
|||||||
|
|
||||||
/// Get filesystem info for a single mount point
|
/// Get filesystem info for a single mount point
|
||||||
fn get_filesystem_info(&self, mount_point: &str) -> Result<(u64, u64), CollectorError> {
|
fn get_filesystem_info(&self, mount_point: &str) -> Result<(u64, u64), CollectorError> {
|
||||||
let output = Command::new("df")
|
let output = std::process::Command::new("timeout")
|
||||||
.args(&["--block-size=1", mount_point])
|
.args(&["2", "df", "--block-size=1", mount_point])
|
||||||
.output()
|
.output()
|
||||||
.map_err(|e| CollectorError::SystemRead {
|
.map_err(|e| CollectorError::SystemRead {
|
||||||
path: format!("df {}", mount_point),
|
path: format!("df {}", mount_point),
|
||||||
@@ -351,8 +352,6 @@ impl DiskCollector {
|
|||||||
let physical_drive = PhysicalDrive {
|
let physical_drive = PhysicalDrive {
|
||||||
name: drive_name,
|
name: drive_name,
|
||||||
health: "UNKNOWN".to_string(), // Will be updated with SMART data
|
health: "UNKNOWN".to_string(), // Will be updated with SMART data
|
||||||
temperature_celsius: None,
|
|
||||||
wear_percent: None,
|
|
||||||
filesystems,
|
filesystems,
|
||||||
};
|
};
|
||||||
physical_drives.push(physical_drive);
|
physical_drives.push(physical_drive);
|
||||||
@@ -390,7 +389,7 @@ impl DiskCollector {
|
|||||||
/// Get SMART data for drives
|
/// Get SMART data for drives
|
||||||
async fn get_smart_data_for_drives(&self, physical_drives: &[PhysicalDrive], mergerfs_pools: &[MergerfsPool]) -> HashMap<String, SmartData> {
|
async fn get_smart_data_for_drives(&self, physical_drives: &[PhysicalDrive], mergerfs_pools: &[MergerfsPool]) -> HashMap<String, SmartData> {
|
||||||
let mut smart_data = HashMap::new();
|
let mut smart_data = HashMap::new();
|
||||||
|
|
||||||
// Collect all drive names
|
// Collect all drive names
|
||||||
let mut all_drives = std::collections::HashSet::new();
|
let mut all_drives = std::collections::HashSet::new();
|
||||||
for drive in physical_drives {
|
for drive in physical_drives {
|
||||||
@@ -417,23 +416,26 @@ impl DiskCollector {
|
|||||||
|
|
||||||
/// Get SMART data for a single drive
|
/// Get SMART data for a single drive
|
||||||
async fn get_smart_data(&self, drive_name: &str) -> Result<SmartData, CollectorError> {
|
async fn get_smart_data(&self, drive_name: &str) -> Result<SmartData, CollectorError> {
|
||||||
let output = Command::new("sudo")
|
use super::run_command_with_timeout;
|
||||||
.args(&["smartctl", "-a", &format!("/dev/{}", drive_name)])
|
|
||||||
.output()
|
// Use direct smartctl (no sudo) - service has CAP_SYS_RAWIO and CAP_SYS_ADMIN capabilities
|
||||||
|
// For NVMe drives, specify device type explicitly
|
||||||
|
let mut cmd = Command::new("smartctl");
|
||||||
|
if drive_name.starts_with("nvme") {
|
||||||
|
cmd.args(&["-d", "nvme", "-a", &format!("/dev/{}", drive_name)]);
|
||||||
|
} else {
|
||||||
|
cmd.args(&["-a", &format!("/dev/{}", drive_name)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
let output = run_command_with_timeout(cmd, 3).await
|
||||||
.map_err(|e| CollectorError::SystemRead {
|
.map_err(|e| CollectorError::SystemRead {
|
||||||
path: format!("SMART data for {}", drive_name),
|
path: format!("SMART data for {}", drive_name),
|
||||||
error: e.to_string(),
|
error: e.to_string(),
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let output_str = String::from_utf8_lossy(&output.stdout);
|
let output_str = String::from_utf8_lossy(&output.stdout);
|
||||||
let error_str = String::from_utf8_lossy(&output.stderr);
|
|
||||||
|
|
||||||
// Debug logging for SMART command results
|
|
||||||
debug!("SMART output for {}: status={}, stdout_len={}, stderr={}",
|
|
||||||
drive_name, output.status, output_str.len(), error_str);
|
|
||||||
|
|
||||||
if !output.status.success() {
|
if !output.status.success() {
|
||||||
debug!("SMART command failed for {}: {}", drive_name, error_str);
|
|
||||||
// Return unknown data rather than failing completely
|
// Return unknown data rather than failing completely
|
||||||
return Ok(SmartData {
|
return Ok(SmartData {
|
||||||
health: "UNKNOWN".to_string(),
|
health: "UNKNOWN".to_string(),
|
||||||
@@ -471,7 +473,7 @@ impl DiskCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Temperature parsing for different drive types
|
// Temperature parsing for different drive types
|
||||||
if line.contains("Temperature_Celsius") || line.contains("Airflow_Temperature_Cel") {
|
if line.contains("Temperature_Celsius") || line.contains("Airflow_Temperature_Cel") || line.contains("Temperature_Case") {
|
||||||
// Traditional SATA drives: attribute table format
|
// Traditional SATA drives: attribute table format
|
||||||
if let Some(temp_str) = line.split_whitespace().nth(9) {
|
if let Some(temp_str) = line.split_whitespace().nth(9) {
|
||||||
if let Ok(temp) = temp_str.parse::<f32>() {
|
if let Ok(temp) = temp_str.parse::<f32>() {
|
||||||
@@ -489,7 +491,15 @@ impl DiskCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wear level parsing for SSDs
|
// Wear level parsing for SSDs
|
||||||
if line.contains("Wear_Leveling_Count") || line.contains("SSD_Life_Left") {
|
if line.contains("Media_Wearout_Indicator") {
|
||||||
|
// Media_Wearout_Indicator stores remaining life % in column 3 (VALUE)
|
||||||
|
if let Some(wear_str) = line.split_whitespace().nth(3) {
|
||||||
|
if let Ok(remaining) = wear_str.parse::<f32>() {
|
||||||
|
wear_percent = Some(100.0 - remaining); // Convert remaining life to wear
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if line.contains("Wear_Leveling_Count") || line.contains("SSD_Life_Left") {
|
||||||
|
// Other wear attributes store value in column 9 (RAW_VALUE)
|
||||||
if let Some(wear_str) = line.split_whitespace().nth(9) {
|
if let Some(wear_str) = line.split_whitespace().nth(9) {
|
||||||
if let Ok(wear) = wear_str.parse::<f32>() {
|
if let Ok(wear) = wear_str.parse::<f32>() {
|
||||||
wear_percent = Some(100.0 - wear); // Convert remaining life to wear
|
wear_percent = Some(100.0 - wear); // Convert remaining life to wear
|
||||||
@@ -639,10 +649,19 @@ impl DiskCollector {
|
|||||||
}).collect();
|
}).collect();
|
||||||
|
|
||||||
// Calculate overall pool health string and status
|
// Calculate overall pool health string and status
|
||||||
let (pool_health, health_status) = match (failed_data, failed_parity) {
|
// SnapRAID logic: can tolerate up to N parity drive failures (where N = number of parity drives)
|
||||||
(0, 0) => ("healthy".to_string(), cm_dashboard_shared::Status::Ok),
|
// If data drives fail AND we've lost parity protection, that's critical
|
||||||
(1, 0) | (0, 1) => ("degraded".to_string(), cm_dashboard_shared::Status::Warning),
|
let (pool_health, health_status) = if failed_data == 0 && failed_parity == 0 {
|
||||||
_ => ("critical".to_string(), cm_dashboard_shared::Status::Critical),
|
("healthy".to_string(), cm_dashboard_shared::Status::Ok)
|
||||||
|
} else if failed_data == 0 && failed_parity > 0 {
|
||||||
|
// Parity failed but no data loss - degraded (reduced protection)
|
||||||
|
("degraded".to_string(), cm_dashboard_shared::Status::Warning)
|
||||||
|
} else if failed_data == 1 && failed_parity == 0 {
|
||||||
|
// One data drive failed, parity intact - degraded (recoverable)
|
||||||
|
("degraded".to_string(), cm_dashboard_shared::Status::Warning)
|
||||||
|
} else {
|
||||||
|
// Multiple data drives failed OR data+parity failed = data loss risk
|
||||||
|
("critical".to_string(), cm_dashboard_shared::Status::Critical)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Calculate pool usage status using config thresholds
|
// Calculate pool usage status using config thresholds
|
||||||
@@ -743,9 +762,9 @@ impl DiskCollector {
|
|||||||
|
|
||||||
/// Get drive information for a mount path
|
/// Get drive information for a mount path
|
||||||
fn get_drive_info_for_path(&self, path: &str) -> anyhow::Result<PoolDrive> {
|
fn get_drive_info_for_path(&self, path: &str) -> anyhow::Result<PoolDrive> {
|
||||||
// Use lsblk to find the backing device
|
// Use lsblk to find the backing device with timeout
|
||||||
let output = Command::new("lsblk")
|
let output = Command::new("timeout")
|
||||||
.args(&["-rn", "-o", "NAME,MOUNTPOINT"])
|
.args(&["2", "lsblk", "-rn", "-o", "NAME,MOUNTPOINT"])
|
||||||
.output()
|
.output()
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to run lsblk: {}", e))?;
|
.map_err(|e| anyhow::anyhow!("Failed to run lsblk: {}", e))?;
|
||||||
|
|
||||||
|
|||||||
@@ -105,12 +105,12 @@ impl MemoryCollector {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get usage data for all tmpfs mounts at once using df
|
// Get usage data for all tmpfs mounts at once using df (with 2 second timeout)
|
||||||
let mut df_args = vec!["df", "--output=target,size,used", "--block-size=1"];
|
let mut df_args = vec!["2", "df", "--output=target,size,used", "--block-size=1"];
|
||||||
df_args.extend(tmpfs_mounts.iter().map(|s| s.as_str()));
|
df_args.extend(tmpfs_mounts.iter().map(|s| s.as_str()));
|
||||||
|
|
||||||
let df_output = std::process::Command::new(df_args[0])
|
let df_output = std::process::Command::new("timeout")
|
||||||
.args(&df_args[1..])
|
.args(&df_args[..])
|
||||||
.output()
|
.output()
|
||||||
.map_err(|e| CollectorError::SystemRead {
|
.map_err(|e| CollectorError::SystemRead {
|
||||||
path: "tmpfs mounts".to_string(),
|
path: "tmpfs mounts".to_string(),
|
||||||
|
|||||||
@@ -1,17 +1,34 @@
|
|||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use cm_dashboard_shared::{AgentData};
|
use cm_dashboard_shared::{AgentData};
|
||||||
|
use std::process::{Command, Output};
|
||||||
|
use std::time::Duration;
|
||||||
|
use tokio::time::timeout;
|
||||||
|
|
||||||
pub mod backup;
|
pub mod backup;
|
||||||
pub mod cpu;
|
pub mod cpu;
|
||||||
pub mod disk;
|
pub mod disk;
|
||||||
pub mod error;
|
pub mod error;
|
||||||
pub mod memory;
|
pub mod memory;
|
||||||
|
pub mod network;
|
||||||
pub mod nixos;
|
pub mod nixos;
|
||||||
pub mod systemd;
|
pub mod systemd;
|
||||||
|
|
||||||
pub use error::CollectorError;
|
pub use error::CollectorError;
|
||||||
|
|
||||||
|
/// Run a command with a timeout to prevent blocking
|
||||||
|
pub async fn run_command_with_timeout(mut cmd: Command, timeout_secs: u64) -> std::io::Result<Output> {
|
||||||
|
let timeout_duration = Duration::from_secs(timeout_secs);
|
||||||
|
|
||||||
|
match timeout(timeout_duration, tokio::task::spawn_blocking(move || cmd.output())).await {
|
||||||
|
Ok(Ok(result)) => result,
|
||||||
|
Ok(Err(e)) => Err(std::io::Error::new(std::io::ErrorKind::Other, e)),
|
||||||
|
Err(_) => Err(std::io::Error::new(
|
||||||
|
std::io::ErrorKind::TimedOut,
|
||||||
|
format!("Command timed out after {} seconds", timeout_secs)
|
||||||
|
)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Base trait for all collectors with direct structured data output
|
/// Base trait for all collectors with direct structured data output
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
|||||||
224
agent/src/collectors/network.rs
Normal file
224
agent/src/collectors/network.rs
Normal file
@@ -0,0 +1,224 @@
|
|||||||
|
use async_trait::async_trait;
|
||||||
|
use cm_dashboard_shared::{AgentData, NetworkInterfaceData, Status};
|
||||||
|
use std::process::Command;
|
||||||
|
use tracing::debug;
|
||||||
|
|
||||||
|
use super::{Collector, CollectorError};
|
||||||
|
use crate::config::NetworkConfig;
|
||||||
|
|
||||||
|
/// Network interface collector with physical/virtual classification and link status
|
||||||
|
pub struct NetworkCollector {
|
||||||
|
_config: NetworkConfig,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl NetworkCollector {
|
||||||
|
pub fn new(config: NetworkConfig) -> Self {
|
||||||
|
Self { _config: config }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Check if interface is physical (not virtual)
|
||||||
|
fn is_physical_interface(name: &str) -> bool {
|
||||||
|
// Physical interface patterns
|
||||||
|
matches!(
|
||||||
|
&name[..],
|
||||||
|
s if s.starts_with("eth")
|
||||||
|
|| s.starts_with("ens")
|
||||||
|
|| s.starts_with("enp")
|
||||||
|
|| s.starts_with("wlan")
|
||||||
|
|| s.starts_with("wlp")
|
||||||
|
|| s.starts_with("eno")
|
||||||
|
|| s.starts_with("enx")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get link status for an interface
|
||||||
|
fn get_link_status(interface: &str) -> Status {
|
||||||
|
let operstate_path = format!("/sys/class/net/{}/operstate", interface);
|
||||||
|
|
||||||
|
match std::fs::read_to_string(&operstate_path) {
|
||||||
|
Ok(state) => {
|
||||||
|
let state = state.trim();
|
||||||
|
match state {
|
||||||
|
"up" => Status::Ok,
|
||||||
|
"down" => Status::Inactive,
|
||||||
|
"unknown" => Status::Warning,
|
||||||
|
_ => Status::Unknown,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(_) => Status::Unknown,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get the primary physical interface (the one with default route)
|
||||||
|
fn get_primary_physical_interface() -> Option<String> {
|
||||||
|
match Command::new("timeout").args(["2", "ip", "route", "show", "default"]).output() {
|
||||||
|
Ok(output) if output.status.success() => {
|
||||||
|
let output_str = String::from_utf8_lossy(&output.stdout);
|
||||||
|
// Parse: "default via 192.168.1.1 dev eno1 ..."
|
||||||
|
for line in output_str.lines() {
|
||||||
|
if line.starts_with("default") {
|
||||||
|
if let Some(dev_pos) = line.find(" dev ") {
|
||||||
|
let after_dev = &line[dev_pos + 5..];
|
||||||
|
if let Some(space_pos) = after_dev.find(' ') {
|
||||||
|
let interface = &after_dev[..space_pos];
|
||||||
|
// Only return if it's a physical interface
|
||||||
|
if Self::is_physical_interface(interface) {
|
||||||
|
return Some(interface.to_string());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// No space after interface name (end of line)
|
||||||
|
let interface = after_dev.trim();
|
||||||
|
if Self::is_physical_interface(interface) {
|
||||||
|
return Some(interface.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse VLAN configuration from /proc/net/vlan/config
|
||||||
|
/// Returns a map of interface name -> VLAN ID
|
||||||
|
fn parse_vlan_config() -> std::collections::HashMap<String, u16> {
|
||||||
|
let mut vlan_map = std::collections::HashMap::new();
|
||||||
|
|
||||||
|
if let Ok(contents) = std::fs::read_to_string("/proc/net/vlan/config") {
|
||||||
|
for line in contents.lines().skip(2) { // Skip header lines
|
||||||
|
let parts: Vec<&str> = line.split('|').collect();
|
||||||
|
if parts.len() >= 2 {
|
||||||
|
let interface_name = parts[0].trim();
|
||||||
|
let vlan_id_str = parts[1].trim();
|
||||||
|
|
||||||
|
if let Ok(vlan_id) = vlan_id_str.parse::<u16>() {
|
||||||
|
vlan_map.insert(interface_name.to_string(), vlan_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
vlan_map
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Collect network interfaces using ip command
|
||||||
|
async fn collect_interfaces(&self) -> Vec<NetworkInterfaceData> {
|
||||||
|
let mut interfaces = Vec::new();
|
||||||
|
|
||||||
|
// Parse VLAN configuration
|
||||||
|
let vlan_map = Self::parse_vlan_config();
|
||||||
|
|
||||||
|
match Command::new("timeout").args(["2", "ip", "-j", "addr"]).output() {
|
||||||
|
Ok(output) if output.status.success() => {
|
||||||
|
let json_str = String::from_utf8_lossy(&output.stdout);
|
||||||
|
|
||||||
|
if let Ok(json_data) = serde_json::from_str::<serde_json::Value>(&json_str) {
|
||||||
|
if let Some(ifaces) = json_data.as_array() {
|
||||||
|
for iface in ifaces {
|
||||||
|
let name = iface["ifname"].as_str().unwrap_or("").to_string();
|
||||||
|
|
||||||
|
// Skip loopback, empty names, and ifb* interfaces
|
||||||
|
if name.is_empty() || name == "lo" || name.starts_with("ifb") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse parent interface from @parent notation (e.g., lan@enp0s31f6)
|
||||||
|
let (interface_name, parent_interface) = if let Some(at_pos) = name.find('@') {
|
||||||
|
let (child, parent) = name.split_at(at_pos);
|
||||||
|
(child.to_string(), Some(parent[1..].to_string()))
|
||||||
|
} else {
|
||||||
|
(name.clone(), None)
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut ipv4_addresses = Vec::new();
|
||||||
|
let mut ipv6_addresses = Vec::new();
|
||||||
|
|
||||||
|
// Extract IP addresses
|
||||||
|
if let Some(addr_info) = iface["addr_info"].as_array() {
|
||||||
|
for addr in addr_info {
|
||||||
|
if let Some(family) = addr["family"].as_str() {
|
||||||
|
if let Some(local) = addr["local"].as_str() {
|
||||||
|
match family {
|
||||||
|
"inet" => ipv4_addresses.push(local.to_string()),
|
||||||
|
"inet6" => {
|
||||||
|
// Skip link-local IPv6 addresses (fe80::)
|
||||||
|
if !local.starts_with("fe80:") {
|
||||||
|
ipv6_addresses.push(local.to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine if physical and get status
|
||||||
|
let is_physical = Self::is_physical_interface(&interface_name);
|
||||||
|
|
||||||
|
// Only filter out virtual interfaces without IPs
|
||||||
|
// Physical interfaces should always be shown even if down/no IPs
|
||||||
|
if !is_physical && ipv4_addresses.is_empty() && ipv6_addresses.is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let link_status = if is_physical {
|
||||||
|
Self::get_link_status(&name)
|
||||||
|
} else {
|
||||||
|
Status::Unknown // Virtual interfaces don't have meaningful link status
|
||||||
|
};
|
||||||
|
|
||||||
|
// Look up VLAN ID from the map (use original name before @ parsing)
|
||||||
|
let vlan_id = vlan_map.get(&name).copied();
|
||||||
|
|
||||||
|
interfaces.push(NetworkInterfaceData {
|
||||||
|
name: interface_name,
|
||||||
|
ipv4_addresses,
|
||||||
|
ipv6_addresses,
|
||||||
|
is_physical,
|
||||||
|
link_status,
|
||||||
|
parent_interface,
|
||||||
|
vlan_id,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
debug!("Failed to execute ip command: {}", e);
|
||||||
|
}
|
||||||
|
Ok(output) => {
|
||||||
|
debug!("ip command failed with status: {}", output.status);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Assign primary physical interface as parent to virtual interfaces without explicit parent
|
||||||
|
let primary_interface = Self::get_primary_physical_interface();
|
||||||
|
if let Some(primary) = primary_interface {
|
||||||
|
for interface in interfaces.iter_mut() {
|
||||||
|
// Only assign parent to virtual interfaces that don't already have one
|
||||||
|
if !interface.is_physical && interface.parent_interface.is_none() {
|
||||||
|
interface.parent_interface = Some(primary.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
interfaces
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_trait]
|
||||||
|
impl Collector for NetworkCollector {
|
||||||
|
async fn collect_structured(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
||||||
|
debug!("Collecting network interface data");
|
||||||
|
|
||||||
|
// Collect all network interfaces
|
||||||
|
let interfaces = self.collect_interfaces().await;
|
||||||
|
|
||||||
|
agent_data.system.network.interfaces = interfaces;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,21 +5,18 @@ use std::process::Command;
|
|||||||
use tracing::debug;
|
use tracing::debug;
|
||||||
|
|
||||||
use super::{Collector, CollectorError};
|
use super::{Collector, CollectorError};
|
||||||
use crate::config::NixOSConfig;
|
|
||||||
|
|
||||||
/// NixOS system information collector with structured data output
|
/// NixOS system information collector with structured data output
|
||||||
///
|
///
|
||||||
/// This collector gathers NixOS-specific information like:
|
/// This collector gathers NixOS-specific information like:
|
||||||
/// - System generation/build information
|
/// - System generation/build information
|
||||||
/// - Version information
|
/// - Version information
|
||||||
/// - Agent version from Nix store path
|
/// - Agent version from Nix store path
|
||||||
pub struct NixOSCollector {
|
pub struct NixOSCollector;
|
||||||
config: NixOSConfig,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl NixOSCollector {
|
impl NixOSCollector {
|
||||||
pub fn new(config: NixOSConfig) -> Self {
|
pub fn new(_config: crate::config::NixOSConfig) -> Self {
|
||||||
Self { config }
|
Self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Collect NixOS system information and populate AgentData
|
/// Collect NixOS system information and populate AgentData
|
||||||
@@ -46,8 +43,8 @@ impl NixOSCollector {
|
|||||||
match fs::read_to_string("/etc/hostname") {
|
match fs::read_to_string("/etc/hostname") {
|
||||||
Ok(hostname) => Some(hostname.trim().to_string()),
|
Ok(hostname) => Some(hostname.trim().to_string()),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
// Fallback to hostname command
|
// Fallback to hostname command (with 2 second timeout)
|
||||||
match Command::new("hostname").output() {
|
match Command::new("timeout").args(["2", "hostname"]).output() {
|
||||||
Ok(output) => Some(String::from_utf8_lossy(&output.stdout).trim().to_string()),
|
Ok(output) => Some(String::from_utf8_lossy(&output.stdout).trim().to_string()),
|
||||||
Err(_) => None,
|
Err(_) => None,
|
||||||
}
|
}
|
||||||
@@ -83,14 +80,25 @@ impl NixOSCollector {
|
|||||||
std::env::var("CM_DASHBOARD_VERSION").unwrap_or_else(|_| "unknown".to_string())
|
std::env::var("CM_DASHBOARD_VERSION").unwrap_or_else(|_| "unknown".to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get NixOS system generation (build) information
|
/// Get NixOS system generation (build) information from git commit
|
||||||
async fn get_nixos_generation(&self) -> Option<String> {
|
async fn get_nixos_generation(&self) -> Option<String> {
|
||||||
match Command::new("nixos-version").output() {
|
// Try to read git commit hash from file written during rebuild
|
||||||
Ok(output) => {
|
let commit_file = "/var/lib/cm-dashboard/git-commit";
|
||||||
let version_str = String::from_utf8_lossy(&output.stdout);
|
match fs::read_to_string(commit_file) {
|
||||||
Some(version_str.trim().to_string())
|
Ok(content) => {
|
||||||
|
let commit_hash = content.trim();
|
||||||
|
if commit_hash.len() >= 7 {
|
||||||
|
debug!("Found git commit hash: {}", commit_hash);
|
||||||
|
Some(commit_hash.to_string())
|
||||||
|
} else {
|
||||||
|
debug!("Git commit hash too short: {}", commit_hash);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
debug!("Failed to read git commit file {}: {}", commit_file, e);
|
||||||
|
None
|
||||||
}
|
}
|
||||||
Err(_) => None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ pub struct SystemdCollector {
|
|||||||
struct ServiceCacheState {
|
struct ServiceCacheState {
|
||||||
/// Last collection time for performance tracking
|
/// Last collection time for performance tracking
|
||||||
last_collection: Option<Instant>,
|
last_collection: Option<Instant>,
|
||||||
/// Cached service data
|
|
||||||
services: Vec<ServiceInfo>,
|
|
||||||
/// Cached complete service data with sub-services
|
/// Cached complete service data with sub-services
|
||||||
cached_service_data: Vec<ServiceData>,
|
cached_service_data: Vec<ServiceData>,
|
||||||
/// Interesting services to monitor (cached after discovery)
|
/// Interesting services to monitor (cached after discovery)
|
||||||
@@ -45,25 +43,16 @@ struct ServiceCacheState {
|
|||||||
/// Cached service status information from systemctl list-units
|
/// Cached service status information from systemctl list-units
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct ServiceStatusInfo {
|
struct ServiceStatusInfo {
|
||||||
load_state: String,
|
|
||||||
active_state: String,
|
active_state: String,
|
||||||
sub_state: String,
|
memory_bytes: Option<u64>,
|
||||||
}
|
restart_count: Option<u32>,
|
||||||
|
start_timestamp: Option<u64>,
|
||||||
/// Internal service information
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
struct ServiceInfo {
|
|
||||||
name: String,
|
|
||||||
status: String, // "active", "inactive", "failed", etc.
|
|
||||||
memory_mb: f32, // Memory usage in MB
|
|
||||||
disk_gb: f32, // Disk usage in GB
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl SystemdCollector {
|
impl SystemdCollector {
|
||||||
pub fn new(config: SystemdConfig) -> Self {
|
pub fn new(config: SystemdConfig) -> Self {
|
||||||
let state = ServiceCacheState {
|
let state = ServiceCacheState {
|
||||||
last_collection: None,
|
last_collection: None,
|
||||||
services: Vec::new(),
|
|
||||||
cached_service_data: Vec::new(),
|
cached_service_data: Vec::new(),
|
||||||
monitored_services: Vec::new(),
|
monitored_services: Vec::new(),
|
||||||
service_status_cache: std::collections::HashMap::new(),
|
service_status_cache: std::collections::HashMap::new(),
|
||||||
@@ -73,7 +62,7 @@ impl SystemdCollector {
|
|||||||
last_nginx_check_time: None,
|
last_nginx_check_time: None,
|
||||||
nginx_check_interval_seconds: config.nginx_check_interval_seconds,
|
nginx_check_interval_seconds: config.nginx_check_interval_seconds,
|
||||||
};
|
};
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
state: RwLock::new(state),
|
state: RwLock::new(state),
|
||||||
config,
|
config,
|
||||||
@@ -95,18 +84,23 @@ impl SystemdCollector {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Collect service data for each monitored service
|
// Collect service data for each monitored service
|
||||||
let mut services = Vec::new();
|
|
||||||
let mut complete_service_data = Vec::new();
|
let mut complete_service_data = Vec::new();
|
||||||
for service_name in &monitored_services {
|
for service_name in &monitored_services {
|
||||||
match self.get_service_status(service_name) {
|
match self.get_service_status(service_name) {
|
||||||
Ok((active_status, _detailed_info)) => {
|
Ok(status_info) => {
|
||||||
let memory_mb = self.get_service_memory_usage(service_name).await.unwrap_or(0.0);
|
|
||||||
let disk_gb = self.get_service_disk_usage(service_name).await.unwrap_or(0.0);
|
|
||||||
|
|
||||||
let mut sub_services = Vec::new();
|
let mut sub_services = Vec::new();
|
||||||
|
|
||||||
|
// Calculate uptime if we have start timestamp
|
||||||
|
let uptime_seconds = status_info.start_timestamp.and_then(|start| {
|
||||||
|
let now = std::time::SystemTime::now()
|
||||||
|
.duration_since(std::time::UNIX_EPOCH)
|
||||||
|
.ok()?
|
||||||
|
.as_secs();
|
||||||
|
Some(now.saturating_sub(start))
|
||||||
|
});
|
||||||
|
|
||||||
// Sub-service metrics for specific services (always include cached results)
|
// Sub-service metrics for specific services (always include cached results)
|
||||||
if service_name.contains("nginx") && active_status == "active" {
|
if service_name.contains("nginx") && status_info.active_state == "active" {
|
||||||
let nginx_sites = self.get_nginx_site_metrics();
|
let nginx_sites = self.get_nginx_site_metrics();
|
||||||
for (site_name, latency_ms) in nginx_sites {
|
for (site_name, latency_ms) in nginx_sites {
|
||||||
let site_status = if latency_ms >= 0.0 && latency_ms < self.config.nginx_latency_critical_ms {
|
let site_status = if latency_ms >= 0.0 && latency_ms < self.config.nginx_latency_critical_ms {
|
||||||
@@ -126,41 +120,54 @@ impl SystemdCollector {
|
|||||||
name: site_name.clone(),
|
name: site_name.clone(),
|
||||||
service_status: self.calculate_service_status(&site_name, &site_status),
|
service_status: self.calculate_service_status(&site_name, &site_status),
|
||||||
metrics,
|
metrics,
|
||||||
|
service_type: "nginx_site".to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if service_name.contains("docker") && active_status == "active" {
|
if service_name.contains("docker") && status_info.active_state == "active" {
|
||||||
let docker_containers = self.get_docker_containers();
|
let docker_containers = self.get_docker_containers();
|
||||||
for (container_name, container_status) in docker_containers {
|
for (container_name, container_status) in docker_containers {
|
||||||
// For now, docker containers have no additional metrics
|
// For now, docker containers have no additional metrics
|
||||||
// Future: could add memory_mb, cpu_percent, restart_count, etc.
|
// Future: could add memory_mb, cpu_percent, restart_count, etc.
|
||||||
let metrics = Vec::new();
|
let metrics = Vec::new();
|
||||||
|
|
||||||
sub_services.push(SubServiceData {
|
sub_services.push(SubServiceData {
|
||||||
name: container_name.clone(),
|
name: container_name.clone(),
|
||||||
service_status: self.calculate_service_status(&container_name, &container_status),
|
service_status: self.calculate_service_status(&container_name, &container_status),
|
||||||
metrics,
|
metrics,
|
||||||
|
service_type: "container".to_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add Docker images
|
||||||
|
let docker_images = self.get_docker_images();
|
||||||
|
for (image_name, image_status, image_size_mb) in docker_images {
|
||||||
|
let mut metrics = Vec::new();
|
||||||
|
metrics.push(SubServiceMetric {
|
||||||
|
label: "size".to_string(),
|
||||||
|
value: image_size_mb,
|
||||||
|
unit: Some("MB".to_string()),
|
||||||
|
});
|
||||||
|
|
||||||
|
sub_services.push(SubServiceData {
|
||||||
|
name: image_name.to_string(),
|
||||||
|
service_status: self.calculate_service_status(&image_name, &image_status),
|
||||||
|
metrics,
|
||||||
|
service_type: "image".to_string(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let service_info = ServiceInfo {
|
|
||||||
name: service_name.clone(),
|
|
||||||
status: active_status.clone(),
|
|
||||||
memory_mb,
|
|
||||||
disk_gb,
|
|
||||||
};
|
|
||||||
services.push(service_info);
|
|
||||||
|
|
||||||
// Create complete service data
|
// Create complete service data
|
||||||
let service_data = ServiceData {
|
let service_data = ServiceData {
|
||||||
name: service_name.clone(),
|
name: service_name.clone(),
|
||||||
memory_mb,
|
|
||||||
disk_gb,
|
|
||||||
user_stopped: false, // TODO: Integrate with service tracker
|
user_stopped: false, // TODO: Integrate with service tracker
|
||||||
service_status: self.calculate_service_status(service_name, &active_status),
|
service_status: self.calculate_service_status(service_name, &status_info.active_state),
|
||||||
sub_services,
|
sub_services,
|
||||||
|
memory_bytes: status_info.memory_bytes,
|
||||||
|
restart_count: status_info.restart_count,
|
||||||
|
uptime_seconds,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Add to AgentData and cache
|
// Add to AgentData and cache
|
||||||
@@ -172,12 +179,15 @@ impl SystemdCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sort services alphabetically by name
|
||||||
|
agent_data.services.sort_by(|a, b| a.name.cmp(&b.name));
|
||||||
|
complete_service_data.sort_by(|a, b| a.name.cmp(&b.name));
|
||||||
|
|
||||||
// Update cached state
|
// Update cached state
|
||||||
{
|
{
|
||||||
let mut state = self.state.write().unwrap();
|
let mut state = self.state.write().unwrap();
|
||||||
state.last_collection = Some(start_time);
|
state.last_collection = Some(start_time);
|
||||||
state.services = services;
|
|
||||||
state.cached_service_data = complete_service_data;
|
state.cached_service_data = complete_service_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -252,18 +262,18 @@ impl SystemdCollector {
|
|||||||
|
|
||||||
/// Auto-discover interesting services to monitor
|
/// Auto-discover interesting services to monitor
|
||||||
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>)> {
|
||||||
// First: Get all service unit files
|
// First: Get all service unit files (with 3 second timeout)
|
||||||
let unit_files_output = Command::new("systemctl")
|
let unit_files_output = Command::new("timeout")
|
||||||
.args(&["list-unit-files", "--type=service", "--no-pager", "--plain"])
|
.args(&["3", "systemctl", "list-unit-files", "--type=service", "--no-pager", "--plain"])
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
if !unit_files_output.status.success() {
|
if !unit_files_output.status.success() {
|
||||||
return Err(anyhow::anyhow!("systemctl list-unit-files command failed"));
|
return Err(anyhow::anyhow!("systemctl list-unit-files command failed"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Second: Get runtime status of all units
|
// Second: Get runtime status of all units (with 3 second timeout)
|
||||||
let units_status_output = Command::new("systemctl")
|
let units_status_output = Command::new("timeout")
|
||||||
.args(&["list-units", "--type=service", "--all", "--no-pager", "--plain"])
|
.args(&["3", "systemctl", "list-units", "--type=service", "--all", "--no-pager", "--plain"])
|
||||||
.output()?;
|
.output()?;
|
||||||
|
|
||||||
if !units_status_output.status.success() {
|
if !units_status_output.status.success() {
|
||||||
@@ -293,14 +303,13 @@ impl SystemdCollector {
|
|||||||
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");
|
||||||
let load_state = fields.get(1).unwrap_or(&"unknown").to_string();
|
|
||||||
let active_state = fields.get(2).unwrap_or(&"unknown").to_string();
|
let active_state = fields.get(2).unwrap_or(&"unknown").to_string();
|
||||||
let sub_state = fields.get(3).unwrap_or(&"unknown").to_string();
|
|
||||||
|
|
||||||
status_cache.insert(service_name.to_string(), ServiceStatusInfo {
|
status_cache.insert(service_name.to_string(), ServiceStatusInfo {
|
||||||
load_state,
|
|
||||||
active_state,
|
active_state,
|
||||||
sub_state,
|
memory_bytes: None,
|
||||||
|
restart_count: None,
|
||||||
|
start_timestamp: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -309,9 +318,10 @@ impl SystemdCollector {
|
|||||||
for service_name in &all_service_names {
|
for service_name in &all_service_names {
|
||||||
if !status_cache.contains_key(service_name) {
|
if !status_cache.contains_key(service_name) {
|
||||||
status_cache.insert(service_name.to_string(), ServiceStatusInfo {
|
status_cache.insert(service_name.to_string(), ServiceStatusInfo {
|
||||||
load_state: "not-loaded".to_string(),
|
|
||||||
active_state: "inactive".to_string(),
|
active_state: "inactive".to_string(),
|
||||||
sub_state: "dead".to_string(),
|
memory_bytes: None,
|
||||||
|
restart_count: None,
|
||||||
|
start_timestamp: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -343,36 +353,60 @@ impl SystemdCollector {
|
|||||||
Ok((services, status_cache))
|
Ok((services, status_cache))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get service status from cache (if available) or fallback to systemctl
|
/// Get service status with detailed metrics from systemctl
|
||||||
fn get_service_status(&self, service: &str) -> Result<(String, String)> {
|
fn get_service_status(&self, service: &str) -> Result<ServiceStatusInfo> {
|
||||||
// Try to get status from cache first
|
// Always fetch fresh data to get detailed metrics (memory, restarts, uptime)
|
||||||
if let Ok(state) = self.state.read() {
|
// Note: Cache in service_status_cache only has basic active_state from discovery,
|
||||||
if let Some(cached_info) = state.service_status_cache.get(service) {
|
// with all detailed metrics set to None. We need fresh systemctl show data.
|
||||||
let active_status = cached_info.active_state.clone();
|
|
||||||
let detailed_info = format!(
|
let output = Command::new("timeout")
|
||||||
"LoadState={}\nActiveState={}\nSubState={}",
|
.args(&[
|
||||||
cached_info.load_state,
|
"2",
|
||||||
cached_info.active_state,
|
"systemctl",
|
||||||
cached_info.sub_state
|
"show",
|
||||||
);
|
&format!("{}.service", service),
|
||||||
return Ok((active_status, detailed_info));
|
"--property=LoadState,ActiveState,SubState,MemoryCurrent,NRestarts,ExecMainStartTimestamp"
|
||||||
|
])
|
||||||
|
.output()?;
|
||||||
|
|
||||||
|
let output_str = String::from_utf8(output.stdout)?;
|
||||||
|
|
||||||
|
// Parse properties
|
||||||
|
let mut active_state = String::new();
|
||||||
|
let mut memory_bytes = None;
|
||||||
|
let mut restart_count = None;
|
||||||
|
let mut start_timestamp = None;
|
||||||
|
|
||||||
|
for line in output_str.lines() {
|
||||||
|
if let Some(value) = line.strip_prefix("ActiveState=") {
|
||||||
|
active_state = value.to_string();
|
||||||
|
} else if let Some(value) = line.strip_prefix("MemoryCurrent=") {
|
||||||
|
if value != "[not set]" {
|
||||||
|
memory_bytes = value.parse().ok();
|
||||||
|
}
|
||||||
|
} else if let Some(value) = line.strip_prefix("NRestarts=") {
|
||||||
|
restart_count = value.parse().ok();
|
||||||
|
} else if let Some(value) = line.strip_prefix("ExecMainStartTimestamp=") {
|
||||||
|
if value != "[not set]" && !value.is_empty() {
|
||||||
|
// Parse timestamp to seconds since epoch
|
||||||
|
if let Ok(output) = Command::new("date")
|
||||||
|
.args(&["+%s", "-d", value])
|
||||||
|
.output()
|
||||||
|
{
|
||||||
|
if let Ok(timestamp_str) = String::from_utf8(output.stdout) {
|
||||||
|
start_timestamp = timestamp_str.trim().parse().ok();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fallback to systemctl if not in cache
|
Ok(ServiceStatusInfo {
|
||||||
let output = Command::new("systemctl")
|
active_state,
|
||||||
.args(&["is-active", &format!("{}.service", service)])
|
memory_bytes,
|
||||||
.output()?;
|
restart_count,
|
||||||
|
start_timestamp,
|
||||||
let active_status = String::from_utf8(output.stdout)?.trim().to_string();
|
})
|
||||||
|
|
||||||
// Get more detailed info
|
|
||||||
let output = Command::new("systemctl")
|
|
||||||
.args(&["show", &format!("{}.service", service), "--property=LoadState,ActiveState,SubState"])
|
|
||||||
.output()?;
|
|
||||||
|
|
||||||
let detailed_info = String::from_utf8(output.stdout)?;
|
|
||||||
Ok((active_status, detailed_info))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if service name matches pattern (supports wildcards like nginx*)
|
/// Check if service name matches pattern (supports wildcards like nginx*)
|
||||||
@@ -414,94 +448,6 @@ impl SystemdCollector {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get disk usage for a specific service
|
|
||||||
async fn get_service_disk_usage(&self, service_name: &str) -> Result<f32, CollectorError> {
|
|
||||||
// Check if this service has configured directory paths
|
|
||||||
if let Some(dirs) = self.config.service_directories.get(service_name) {
|
|
||||||
// Service has configured paths - use the first accessible one
|
|
||||||
for dir in dirs {
|
|
||||||
if let Some(size) = self.get_directory_size(dir) {
|
|
||||||
return Ok(size);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If configured paths failed, return 0
|
|
||||||
return Ok(0.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// No configured path - try to get WorkingDirectory from systemctl
|
|
||||||
let output = Command::new("systemctl")
|
|
||||||
.args(&["show", &format!("{}.service", service_name), "--property=WorkingDirectory"])
|
|
||||||
.output()
|
|
||||||
.map_err(|e| CollectorError::SystemRead {
|
|
||||||
path: format!("WorkingDirectory for {}", service_name),
|
|
||||||
error: e.to_string(),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let output_str = String::from_utf8_lossy(&output.stdout);
|
|
||||||
for line in output_str.lines() {
|
|
||||||
if line.starts_with("WorkingDirectory=") && !line.contains("[not set]") {
|
|
||||||
let dir = line.strip_prefix("WorkingDirectory=").unwrap_or("");
|
|
||||||
if !dir.is_empty() && dir != "/" {
|
|
||||||
return Ok(self.get_directory_size(dir).unwrap_or(0.0));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(0.0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get size of a directory in GB
|
|
||||||
fn get_directory_size(&self, path: &str) -> Option<f32> {
|
|
||||||
let output = Command::new("sudo")
|
|
||||||
.args(&["du", "-sb", path])
|
|
||||||
.output()
|
|
||||||
.ok()?;
|
|
||||||
|
|
||||||
if !output.status.success() {
|
|
||||||
// Log permission errors for debugging but don't spam logs
|
|
||||||
let stderr = String::from_utf8_lossy(&output.stderr);
|
|
||||||
if stderr.contains("Permission denied") {
|
|
||||||
debug!("Permission denied accessing directory: {}", path);
|
|
||||||
} else {
|
|
||||||
debug!("Failed to get size for directory {}: {}", path, stderr);
|
|
||||||
}
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
|
|
||||||
let output_str = String::from_utf8(output.stdout).ok()?;
|
|
||||||
let size_str = output_str.split_whitespace().next()?;
|
|
||||||
if let Ok(size_bytes) = size_str.parse::<u64>() {
|
|
||||||
let size_gb = size_bytes as f32 / (1024.0 * 1024.0 * 1024.0);
|
|
||||||
// Return size even if very small (minimum 0.001 GB = 1MB for visibility)
|
|
||||||
if size_gb > 0.0 {
|
|
||||||
Some(size_gb.max(0.001))
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get service memory usage (if available)
|
|
||||||
fn get_service_memory(&self, service: &str) -> Option<f32> {
|
|
||||||
let output = Command::new("systemctl")
|
|
||||||
.args(&["show", &format!("{}.service", service), "--property=MemoryCurrent"])
|
|
||||||
.output()
|
|
||||||
.ok()?;
|
|
||||||
|
|
||||||
let output_str = String::from_utf8(output.stdout).ok()?;
|
|
||||||
for line in output_str.lines() {
|
|
||||||
if line.starts_with("MemoryCurrent=") {
|
|
||||||
let memory_str = line.strip_prefix("MemoryCurrent=")?;
|
|
||||||
if let Ok(memory_bytes) = memory_str.parse::<u64>() {
|
|
||||||
return Some(memory_bytes as f32 / (1024.0 * 1024.0)); // Convert to MB
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Calculate service status, taking user-stopped services into account
|
/// Calculate service status, taking user-stopped services into account
|
||||||
fn calculate_service_status(&self, service_name: &str, active_status: &str) -> Status {
|
fn calculate_service_status(&self, service_name: &str, active_status: &str) -> Status {
|
||||||
match active_status.to_lowercase().as_str() {
|
match active_status.to_lowercase().as_str() {
|
||||||
@@ -519,37 +465,10 @@ impl SystemdCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get memory usage for a specific service
|
|
||||||
async fn get_service_memory_usage(&self, service_name: &str) -> Result<f32, CollectorError> {
|
|
||||||
let output = Command::new("systemctl")
|
|
||||||
.args(&["show", &format!("{}.service", service_name), "--property=MemoryCurrent"])
|
|
||||||
.output()
|
|
||||||
.map_err(|e| CollectorError::SystemRead {
|
|
||||||
path: format!("memory usage for {}", service_name),
|
|
||||||
error: e.to_string(),
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let output_str = String::from_utf8_lossy(&output.stdout);
|
|
||||||
|
|
||||||
for line in output_str.lines() {
|
|
||||||
if line.starts_with("MemoryCurrent=") {
|
|
||||||
if let Some(mem_str) = line.strip_prefix("MemoryCurrent=") {
|
|
||||||
if mem_str != "[not set]" {
|
|
||||||
if let Ok(memory_bytes) = mem_str.parse::<u64>() {
|
|
||||||
return Ok(memory_bytes as f32 / (1024.0 * 1024.0)); // Convert to MB
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(0.0)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if service collection cache should be updated
|
/// Check if service collection cache should be updated
|
||||||
fn should_update_cache(&self) -> bool {
|
fn should_update_cache(&self) -> bool {
|
||||||
let state = self.state.read().unwrap();
|
let state = self.state.read().unwrap();
|
||||||
|
|
||||||
match state.last_collection {
|
match state.last_collection {
|
||||||
None => true,
|
None => true,
|
||||||
Some(last) => {
|
Some(last) => {
|
||||||
@@ -559,16 +478,6 @@ impl SystemdCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get cached service data if available and fresh
|
|
||||||
fn get_cached_services(&self) -> Option<Vec<ServiceInfo>> {
|
|
||||||
if !self.should_update_cache() {
|
|
||||||
let state = self.state.read().unwrap();
|
|
||||||
Some(state.services.clone())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get cached complete service data with sub-services if available and fresh
|
/// Get cached complete service data with sub-services if available and fresh
|
||||||
fn get_cached_complete_services(&self) -> Option<Vec<ServiceData>> {
|
fn get_cached_complete_services(&self) -> Option<Vec<ServiceData>> {
|
||||||
if !self.should_update_cache() {
|
if !self.should_update_cache() {
|
||||||
@@ -807,9 +716,10 @@ impl SystemdCollector {
|
|||||||
fn get_docker_containers(&self) -> Vec<(String, String)> {
|
fn get_docker_containers(&self) -> Vec<(String, String)> {
|
||||||
let mut containers = Vec::new();
|
let mut containers = Vec::new();
|
||||||
|
|
||||||
// Check if docker is available
|
// Check if docker is available (cm-agent user is in docker group)
|
||||||
let output = Command::new("docker")
|
// Use -a to show ALL containers (running and stopped) with 3 second timeout
|
||||||
.args(&["ps", "--format", "{{.Names}},{{.Status}}"])
|
let output = Command::new("timeout")
|
||||||
|
.args(&["3", "docker", "ps", "-a", "--format", "{{.Names}},{{.Status}}"])
|
||||||
.output();
|
.output();
|
||||||
|
|
||||||
let output = match output {
|
let output = match output {
|
||||||
@@ -834,10 +744,10 @@ impl SystemdCollector {
|
|||||||
|
|
||||||
let container_status = if status_str.contains("Up") {
|
let container_status = if status_str.contains("Up") {
|
||||||
"active"
|
"active"
|
||||||
} else if status_str.contains("Exited") {
|
} else if status_str.contains("Exited") || status_str.contains("Created") {
|
||||||
"warning" // Match original: Exited → Warning, not inactive
|
"inactive" // Stopped/created containers are inactive
|
||||||
} else {
|
} else {
|
||||||
"failed" // Other states → failed
|
"failed" // Other states (restarting, paused, dead) → failed
|
||||||
};
|
};
|
||||||
|
|
||||||
containers.push((format!("docker_{}", container_name), container_status.to_string()));
|
containers.push((format!("docker_{}", container_name), container_status.to_string()));
|
||||||
@@ -846,6 +756,86 @@ impl SystemdCollector {
|
|||||||
|
|
||||||
containers
|
containers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get docker images as sub-services
|
||||||
|
fn get_docker_images(&self) -> Vec<(String, String, f32)> {
|
||||||
|
let mut images = Vec::new();
|
||||||
|
// Check if docker is available (cm-agent user is in docker group) with 3 second timeout
|
||||||
|
let output = Command::new("timeout")
|
||||||
|
.args(&["3", "docker", "images", "--format", "{{.Repository}}:{{.Tag}},{{.Size}}"])
|
||||||
|
.output();
|
||||||
|
|
||||||
|
let output = match output {
|
||||||
|
Ok(out) if out.status.success() => out,
|
||||||
|
Ok(_) => {
|
||||||
|
return images;
|
||||||
|
}
|
||||||
|
Err(_) => {
|
||||||
|
return images;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let output_str = match String::from_utf8(output.stdout) {
|
||||||
|
Ok(s) => s,
|
||||||
|
Err(_) => return images,
|
||||||
|
};
|
||||||
|
|
||||||
|
for line in output_str.lines() {
|
||||||
|
if line.trim().is_empty() {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let parts: Vec<&str> = line.split(',').collect();
|
||||||
|
if parts.len() >= 2 {
|
||||||
|
let image_name = parts[0].trim();
|
||||||
|
let size_str = parts[1].trim();
|
||||||
|
|
||||||
|
// Skip <none>:<none> images (dangling images)
|
||||||
|
if image_name.contains("<none>") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Parse size to MB (sizes come as "142MB", "1.5GB", "512kB", etc.)
|
||||||
|
let size_mb = self.parse_docker_size(size_str);
|
||||||
|
|
||||||
|
images.push((
|
||||||
|
image_name.to_string(),
|
||||||
|
"inactive".to_string(), // Images are informational - use inactive for neutral display
|
||||||
|
size_mb
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
images
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Parse Docker size string to MB
|
||||||
|
fn parse_docker_size(&self, size_str: &str) -> f32 {
|
||||||
|
let size_upper = size_str.to_uppercase();
|
||||||
|
|
||||||
|
// Extract numeric part and unit
|
||||||
|
let mut num_str = String::new();
|
||||||
|
let mut unit = String::new();
|
||||||
|
|
||||||
|
for ch in size_upper.chars() {
|
||||||
|
if ch.is_ascii_digit() || ch == '.' {
|
||||||
|
num_str.push(ch);
|
||||||
|
} else if ch.is_alphabetic() {
|
||||||
|
unit.push(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let value: f32 = num_str.parse().unwrap_or(0.0);
|
||||||
|
|
||||||
|
// Convert to MB
|
||||||
|
match unit.as_str() {
|
||||||
|
"KB" | "K" => value / 1024.0,
|
||||||
|
"MB" | "M" => value,
|
||||||
|
"GB" | "G" => value * 1024.0,
|
||||||
|
"TB" | "T" => value * 1024.0 * 1024.0,
|
||||||
|
_ => value, // Assume bytes if no unit
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
|||||||
@@ -5,10 +5,9 @@ use zmq::{Context, Socket, SocketType};
|
|||||||
|
|
||||||
use crate::config::ZmqConfig;
|
use crate::config::ZmqConfig;
|
||||||
|
|
||||||
/// ZMQ communication handler for publishing metrics and receiving commands
|
/// ZMQ communication handler for publishing metrics
|
||||||
pub struct ZmqHandler {
|
pub struct ZmqHandler {
|
||||||
publisher: Socket,
|
publisher: Socket,
|
||||||
command_receiver: Socket,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ZmqHandler {
|
impl ZmqHandler {
|
||||||
@@ -26,20 +25,8 @@ impl ZmqHandler {
|
|||||||
publisher.set_sndhwm(1000)?; // High water mark for outbound messages
|
publisher.set_sndhwm(1000)?; // High water mark for outbound messages
|
||||||
publisher.set_linger(1000)?; // Linger time on close
|
publisher.set_linger(1000)?; // Linger time on close
|
||||||
|
|
||||||
// Create command receiver socket (PULL socket to receive commands from dashboard)
|
|
||||||
let command_receiver = context.socket(SocketType::PULL)?;
|
|
||||||
let cmd_bind_address = format!("tcp://{}:{}", config.bind_address, config.command_port);
|
|
||||||
command_receiver.bind(&cmd_bind_address)?;
|
|
||||||
|
|
||||||
info!("ZMQ command receiver bound to {}", cmd_bind_address);
|
|
||||||
|
|
||||||
// Set non-blocking mode for command receiver
|
|
||||||
command_receiver.set_rcvtimeo(0)?; // Non-blocking receive
|
|
||||||
command_receiver.set_linger(1000)?;
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
publisher,
|
publisher,
|
||||||
command_receiver,
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,36 +52,4 @@ impl ZmqHandler {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Try to receive a command (non-blocking)
|
|
||||||
pub fn try_receive_command(&self) -> Result<Option<AgentCommand>> {
|
|
||||||
match self.command_receiver.recv_bytes(zmq::DONTWAIT) {
|
|
||||||
Ok(bytes) => {
|
|
||||||
debug!("Received command message ({} bytes)", bytes.len());
|
|
||||||
|
|
||||||
let command: AgentCommand = serde_json::from_slice(&bytes)
|
|
||||||
.map_err(|e| anyhow::anyhow!("Failed to deserialize command: {}", e))?;
|
|
||||||
|
|
||||||
debug!("Parsed command: {:?}", command);
|
|
||||||
Ok(Some(command))
|
|
||||||
}
|
|
||||||
Err(zmq::Error::EAGAIN) => {
|
|
||||||
// No message available (non-blocking)
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
Err(e) => Err(anyhow::anyhow!("ZMQ receive error: {}", e)),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Commands that can be sent to the agent
|
|
||||||
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
|
|
||||||
pub enum AgentCommand {
|
|
||||||
/// Request immediate metric collection
|
|
||||||
CollectNow,
|
|
||||||
/// Change collection interval
|
|
||||||
SetInterval { seconds: u64 },
|
|
||||||
/// Enable/disable a collector
|
|
||||||
ToggleCollector { name: String, enabled: bool },
|
|
||||||
/// Request status/health check
|
|
||||||
Ping,
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
// This file is now empty - all configuration values come from config files
|
|
||||||
// No hardcoded defaults are used
|
|
||||||
@@ -20,7 +20,6 @@ pub struct AgentConfig {
|
|||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct ZmqConfig {
|
pub struct ZmqConfig {
|
||||||
pub publisher_port: u16,
|
pub publisher_port: u16,
|
||||||
pub command_port: u16,
|
|
||||||
pub bind_address: String,
|
pub bind_address: String,
|
||||||
pub transmission_interval_seconds: u64,
|
pub transmission_interval_seconds: u64,
|
||||||
/// Heartbeat transmission interval in seconds for host connectivity detection
|
/// Heartbeat transmission interval in seconds for host connectivity detection
|
||||||
|
|||||||
@@ -7,14 +7,6 @@ pub fn validate_config(config: &AgentConfig) -> Result<()> {
|
|||||||
bail!("ZMQ publisher port cannot be 0");
|
bail!("ZMQ publisher port cannot be 0");
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.zmq.command_port == 0 {
|
|
||||||
bail!("ZMQ command port cannot be 0");
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.zmq.publisher_port == config.zmq.command_port {
|
|
||||||
bail!("ZMQ publisher and command ports cannot be the same");
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.zmq.bind_address.is_empty() {
|
if config.zmq.bind_address.is_empty() {
|
||||||
bail!("ZMQ bind address cannot be empty");
|
bail!("ZMQ bind address cannot be empty");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ mod collectors;
|
|||||||
mod communication;
|
mod communication;
|
||||||
mod config;
|
mod config;
|
||||||
mod notifications;
|
mod notifications;
|
||||||
mod service_tracker;
|
|
||||||
|
|
||||||
use agent::Agent;
|
use agent::Agent;
|
||||||
|
|
||||||
|
|||||||
@@ -1,164 +0,0 @@
|
|||||||
use anyhow::Result;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use std::collections::HashSet;
|
|
||||||
use std::fs;
|
|
||||||
use std::path::Path;
|
|
||||||
use std::sync::{Arc, Mutex, OnceLock};
|
|
||||||
use tracing::{debug, info, warn};
|
|
||||||
|
|
||||||
/// Shared instance for global access
|
|
||||||
static GLOBAL_TRACKER: OnceLock<Arc<Mutex<UserStoppedServiceTracker>>> = OnceLock::new();
|
|
||||||
|
|
||||||
/// Tracks services that have been stopped by user action
|
|
||||||
/// These services should be treated as OK status instead of Warning
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct UserStoppedServiceTracker {
|
|
||||||
/// Set of services stopped by user action
|
|
||||||
user_stopped_services: HashSet<String>,
|
|
||||||
/// Path to persistent storage file
|
|
||||||
storage_path: String,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Serializable data structure for persistence
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
|
||||||
struct UserStoppedData {
|
|
||||||
services: Vec<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl UserStoppedServiceTracker {
|
|
||||||
/// Create new tracker with default storage path
|
|
||||||
pub fn new() -> Self {
|
|
||||||
Self::with_storage_path("/var/lib/cm-dashboard/user-stopped-services.json")
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Initialize global instance (called by agent)
|
|
||||||
pub fn init_global() -> Result<Self> {
|
|
||||||
let tracker = Self::new();
|
|
||||||
|
|
||||||
// Set global instance
|
|
||||||
let global_instance = Arc::new(Mutex::new(tracker));
|
|
||||||
if GLOBAL_TRACKER.set(global_instance).is_err() {
|
|
||||||
warn!("Global service tracker was already initialized");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return a new instance for the agent to use
|
|
||||||
Ok(Self::new())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if a service is user-stopped (global access for collectors)
|
|
||||||
pub fn is_service_user_stopped(service_name: &str) -> bool {
|
|
||||||
if let Some(global) = GLOBAL_TRACKER.get() {
|
|
||||||
if let Ok(tracker) = global.lock() {
|
|
||||||
tracker.is_user_stopped(service_name)
|
|
||||||
} else {
|
|
||||||
debug!("Failed to lock global service tracker");
|
|
||||||
false
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
debug!("Global service tracker not initialized");
|
|
||||||
false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Update global tracker (called by agent when tracker state changes)
|
|
||||||
pub fn update_global(updated_tracker: &UserStoppedServiceTracker) {
|
|
||||||
if let Some(global) = GLOBAL_TRACKER.get() {
|
|
||||||
if let Ok(mut tracker) = global.lock() {
|
|
||||||
tracker.user_stopped_services = updated_tracker.user_stopped_services.clone();
|
|
||||||
} else {
|
|
||||||
debug!("Failed to lock global service tracker for update");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
debug!("Global service tracker not initialized for update");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Create new tracker with custom storage path
|
|
||||||
pub fn with_storage_path<P: AsRef<Path>>(storage_path: P) -> Self {
|
|
||||||
let storage_path = storage_path.as_ref().to_string_lossy().to_string();
|
|
||||||
let mut tracker = Self {
|
|
||||||
user_stopped_services: HashSet::new(),
|
|
||||||
storage_path,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Load existing data from storage
|
|
||||||
if let Err(e) = tracker.load_from_storage() {
|
|
||||||
warn!("Failed to load user-stopped services from storage: {}", e);
|
|
||||||
info!("Starting with empty user-stopped services list");
|
|
||||||
}
|
|
||||||
|
|
||||||
tracker
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Clear user-stopped flag for a service (when user starts it)
|
|
||||||
pub fn clear_user_stopped(&mut self, service_name: &str) -> Result<()> {
|
|
||||||
if self.user_stopped_services.remove(service_name) {
|
|
||||||
info!("Cleared user-stopped flag for service '{}'", service_name);
|
|
||||||
self.save_to_storage()?;
|
|
||||||
debug!("Service '{}' user-stopped flag cleared and saved to storage", service_name);
|
|
||||||
} else {
|
|
||||||
debug!("Service '{}' was not marked as user-stopped", service_name);
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Check if a service is marked as user-stopped
|
|
||||||
pub fn is_user_stopped(&self, service_name: &str) -> bool {
|
|
||||||
let is_stopped = self.user_stopped_services.contains(service_name);
|
|
||||||
debug!("Service '{}' user-stopped status: {}", service_name, is_stopped);
|
|
||||||
is_stopped
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/// Save current state to persistent storage
|
|
||||||
fn save_to_storage(&self) -> Result<()> {
|
|
||||||
// Create parent directory if it doesn't exist
|
|
||||||
if let Some(parent_dir) = Path::new(&self.storage_path).parent() {
|
|
||||||
if !parent_dir.exists() {
|
|
||||||
fs::create_dir_all(parent_dir)?;
|
|
||||||
debug!("Created parent directory: {}", parent_dir.display());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let data = UserStoppedData {
|
|
||||||
services: self.user_stopped_services.iter().cloned().collect(),
|
|
||||||
};
|
|
||||||
|
|
||||||
let json_data = serde_json::to_string_pretty(&data)?;
|
|
||||||
fs::write(&self.storage_path, json_data)?;
|
|
||||||
|
|
||||||
debug!(
|
|
||||||
"Saved {} user-stopped services to {}",
|
|
||||||
data.services.len(),
|
|
||||||
self.storage_path
|
|
||||||
);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Load state from persistent storage
|
|
||||||
fn load_from_storage(&mut self) -> Result<()> {
|
|
||||||
if !Path::new(&self.storage_path).exists() {
|
|
||||||
debug!("Storage file {} does not exist, starting fresh", self.storage_path);
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
|
|
||||||
let json_data = fs::read_to_string(&self.storage_path)?;
|
|
||||||
let data: UserStoppedData = serde_json::from_str(&json_data)?;
|
|
||||||
|
|
||||||
self.user_stopped_services = data.services.into_iter().collect();
|
|
||||||
|
|
||||||
info!(
|
|
||||||
"Loaded {} user-stopped services from {}",
|
|
||||||
self.user_stopped_services.len(),
|
|
||||||
self.storage_path
|
|
||||||
);
|
|
||||||
|
|
||||||
if !self.user_stopped_services.is_empty() {
|
|
||||||
debug!("User-stopped services: {:?}", self.user_stopped_services);
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
1001
agent_stream.log
1001
agent_stream.log
@@ -1,1001 +0,0 @@
|
|||||||
warning: fields `total_services`, `backup_disk_filesystem_label`, `services_completed_count`, `services_failed_count`, and `services_disabled_count` are never read
|
|
||||||
--> dashboard/src/ui/widgets/backup.rs:22:5
|
|
||||||
|
|
|
||||||
14 | pub struct BackupWidget {
|
|
||||||
| ------------ fields in this struct
|
|
||||||
...
|
|
||||||
22 | total_services: Option<i64>,
|
|
||||||
| ^^^^^^^^^^^^^^
|
|
||||||
...
|
|
||||||
36 | backup_disk_filesystem_label: Option<String>,
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
37 | /// Number of completed services
|
|
||||||
38 | services_completed_count: Option<i64>,
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
39 | /// Number of failed services
|
|
||||||
40 | services_failed_count: Option<i64>,
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
41 | /// Number of disabled services
|
|
||||||
42 | services_disabled_count: Option<i64>,
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: `BackupWidget` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis
|
|
||||||
= note: `#[warn(dead_code)]` on by default
|
|
||||||
|
|
||||||
warning: field `exit_code` is never read
|
|
||||||
--> dashboard/src/ui/widgets/backup.rs:53:5
|
|
||||||
|
|
|
||||||
50 | struct ServiceMetricData {
|
|
||||||
| ----------------- field in this struct
|
|
||||||
...
|
|
||||||
53 | exit_code: Option<i64>,
|
|
||||||
| ^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: `ServiceMetricData` has derived impls for the traits `Clone` and `Debug`, but these are intentionally ignored during dead code analysis
|
|
||||||
|
|
||||||
warning: associated function `extract_service_name` is never used
|
|
||||||
--> dashboard/src/ui/widgets/backup.rs:115:8
|
|
||||||
|
|
|
||||||
58 | impl BackupWidget {
|
|
||||||
| ----------------- associated function in this implementation
|
|
||||||
...
|
|
||||||
115 | fn extract_service_name(metric_name: &str) -> Option<String> {
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
warning: method `update_from_metrics` is never used
|
|
||||||
--> dashboard/src/ui/widgets/backup.rs:157:8
|
|
||||||
|
|
|
||||||
156 | impl BackupWidget {
|
|
||||||
| ----------------- method in this implementation
|
|
||||||
157 | fn update_from_metrics(&mut self, metrics: &[&Metric]) {
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
warning: associated function `extract_service_info` is never used
|
|
||||||
--> dashboard/src/ui/widgets/services.rs:50:8
|
|
||||||
|
|
|
||||||
38 | impl ServicesWidget {
|
|
||||||
| ------------------- associated function in this implementation
|
|
||||||
...
|
|
||||||
50 | fn extract_service_info(metric_name: &str) -> Option<(String, Option<String>)> {
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
warning: method `update_from_metrics` is never used
|
|
||||||
--> dashboard/src/ui/widgets/services.rs:285:8
|
|
||||||
|
|
|
||||||
284 | impl ServicesWidget {
|
|
||||||
| ------------------- method in this implementation
|
|
||||||
285 | fn update_from_metrics(&mut self, metrics: &[&Metric]) {
|
|
||||||
| ^^^^^^^^^^^^^^^^^^^
|
|
||||||
|
|
||||||
warning: field `health_status` is never read
|
|
||||||
--> dashboard/src/ui/widgets/system.rs:53:5
|
|
||||||
|
|
|
||||||
43 | struct StoragePool {
|
|
||||||
| ----------- field in this struct
|
|
||||||
...
|
|
||||||
53 | health_status: Status, // Separate status for pool health vs usage
|
|
||||||
| ^^^^^^^^^^^^^
|
|
||||||
|
|
|
||||||
= note: `StoragePool` has a derived impl for the trait `Clone`, but this is intentionally ignored during dead code analysis
|
|
||||||
|
|
||||||
warning: `cm-dashboard` (bin "cm-dashboard") generated 7 warnings
|
|
||||||
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.16s
|
|
||||||
Running `target/debug/cm-dashboard --headless --raw-data`
|
|
||||||
RAW AGENT DATA FROM cmbox:
|
|
||||||
{
|
|
||||||
"hostname": "cmbox",
|
|
||||||
"agent_version": "v0.1.133",
|
|
||||||
"timestamp": 1763936501,
|
|
||||||
"system": {
|
|
||||||
"cpu": {
|
|
||||||
"load_1min": 1.82,
|
|
||||||
"load_5min": 2.1,
|
|
||||||
"load_15min": 2.1,
|
|
||||||
"frequency_mhz": 3743.09,
|
|
||||||
"temperature_celsius": 55.0
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"usage_percent": 27.183601,
|
|
||||||
"total_gb": 23.339516,
|
|
||||||
"used_gb": 6.3445206,
|
|
||||||
"available_gb": 16.994995,
|
|
||||||
"swap_total_gb": 14.634708,
|
|
||||||
"swap_used_gb": 0.17599106,
|
|
||||||
"tmpfs": [
|
|
||||||
{
|
|
||||||
"mount": "/tmp",
|
|
||||||
"usage_percent": 15.094376,
|
|
||||||
"used_gb": 0.3018875,
|
|
||||||
"total_gb": 2.0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"storage": {
|
|
||||||
"drives": [
|
|
||||||
{
|
|
||||||
"name": "nvme0n1",
|
|
||||||
"health": "PASSED",
|
|
||||||
"temperature_celsius": 28.0,
|
|
||||||
"wear_percent": 1.0,
|
|
||||||
"filesystems": [
|
|
||||||
{
|
|
||||||
"mount": "root",
|
|
||||||
"usage_percent": 24.404377,
|
|
||||||
"used_gb": 226.51398,
|
|
||||||
"total_gb": 928.1695
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"mount": "boot",
|
|
||||||
"usage_percent": 10.666672,
|
|
||||||
"used_gb": 0.10645676,
|
|
||||||
"total_gb": 0.9980316
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"pools": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"name": "tailscaled",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 25.582031,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sshd",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 4.3085938,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"backup": {
|
|
||||||
"status": "unknown",
|
|
||||||
"last_run": null,
|
|
||||||
"next_scheduled": null,
|
|
||||||
"total_size_gb": null,
|
|
||||||
"repository_health": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
────────────────────────────────────────────────────────────────────────────────
|
|
||||||
RAW AGENT DATA FROM cmbox:
|
|
||||||
{
|
|
||||||
"hostname": "cmbox",
|
|
||||||
"agent_version": "v0.1.133",
|
|
||||||
"timestamp": 1763936502,
|
|
||||||
"system": {
|
|
||||||
"cpu": {
|
|
||||||
"load_1min": 1.82,
|
|
||||||
"load_5min": 2.1,
|
|
||||||
"load_15min": 2.1,
|
|
||||||
"frequency_mhz": 3743.09,
|
|
||||||
"temperature_celsius": 55.0
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"usage_percent": 27.183601,
|
|
||||||
"total_gb": 23.339516,
|
|
||||||
"used_gb": 6.3445206,
|
|
||||||
"available_gb": 16.994995,
|
|
||||||
"swap_total_gb": 14.634708,
|
|
||||||
"swap_used_gb": 0.17599106,
|
|
||||||
"tmpfs": [
|
|
||||||
{
|
|
||||||
"mount": "/tmp",
|
|
||||||
"usage_percent": 15.094376,
|
|
||||||
"used_gb": 0.3018875,
|
|
||||||
"total_gb": 2.0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"storage": {
|
|
||||||
"drives": [
|
|
||||||
{
|
|
||||||
"name": "nvme0n1",
|
|
||||||
"health": "PASSED",
|
|
||||||
"temperature_celsius": 28.0,
|
|
||||||
"wear_percent": 1.0,
|
|
||||||
"filesystems": [
|
|
||||||
{
|
|
||||||
"mount": "root",
|
|
||||||
"usage_percent": 24.404377,
|
|
||||||
"used_gb": 226.51398,
|
|
||||||
"total_gb": 928.1695
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"mount": "boot",
|
|
||||||
"usage_percent": 10.666672,
|
|
||||||
"used_gb": 0.10645676,
|
|
||||||
"total_gb": 0.9980316
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"pools": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"name": "tailscaled",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 25.582031,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sshd",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 4.3085938,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"backup": {
|
|
||||||
"status": "unknown",
|
|
||||||
"last_run": null,
|
|
||||||
"next_scheduled": null,
|
|
||||||
"total_size_gb": null,
|
|
||||||
"repository_health": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
────────────────────────────────────────────────────────────────────────────────
|
|
||||||
RAW AGENT DATA FROM cmbox:
|
|
||||||
{
|
|
||||||
"hostname": "cmbox",
|
|
||||||
"agent_version": "v0.1.133",
|
|
||||||
"timestamp": 1763936503,
|
|
||||||
"system": {
|
|
||||||
"cpu": {
|
|
||||||
"load_1min": 1.82,
|
|
||||||
"load_5min": 2.1,
|
|
||||||
"load_15min": 2.1,
|
|
||||||
"frequency_mhz": 3743.09,
|
|
||||||
"temperature_celsius": 55.0
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"usage_percent": 27.183601,
|
|
||||||
"total_gb": 23.339516,
|
|
||||||
"used_gb": 6.3445206,
|
|
||||||
"available_gb": 16.994995,
|
|
||||||
"swap_total_gb": 14.634708,
|
|
||||||
"swap_used_gb": 0.17599106,
|
|
||||||
"tmpfs": [
|
|
||||||
{
|
|
||||||
"mount": "/tmp",
|
|
||||||
"usage_percent": 15.094376,
|
|
||||||
"used_gb": 0.3018875,
|
|
||||||
"total_gb": 2.0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"storage": {
|
|
||||||
"drives": [
|
|
||||||
{
|
|
||||||
"name": "nvme0n1",
|
|
||||||
"health": "PASSED",
|
|
||||||
"temperature_celsius": 28.0,
|
|
||||||
"wear_percent": 1.0,
|
|
||||||
"filesystems": [
|
|
||||||
{
|
|
||||||
"mount": "root",
|
|
||||||
"usage_percent": 24.404377,
|
|
||||||
"used_gb": 226.51398,
|
|
||||||
"total_gb": 928.1695
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"mount": "boot",
|
|
||||||
"usage_percent": 10.666672,
|
|
||||||
"used_gb": 0.10645676,
|
|
||||||
"total_gb": 0.9980316
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"pools": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"name": "tailscaled",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 25.582031,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sshd",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 4.3085938,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"backup": {
|
|
||||||
"status": "unknown",
|
|
||||||
"last_run": null,
|
|
||||||
"next_scheduled": null,
|
|
||||||
"total_size_gb": null,
|
|
||||||
"repository_health": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
────────────────────────────────────────────────────────────────────────────────
|
|
||||||
RAW AGENT DATA FROM cmbox:
|
|
||||||
{
|
|
||||||
"hostname": "cmbox",
|
|
||||||
"agent_version": "v0.1.133",
|
|
||||||
"timestamp": 1763936505,
|
|
||||||
"system": {
|
|
||||||
"cpu": {
|
|
||||||
"load_1min": 1.75,
|
|
||||||
"load_5min": 2.08,
|
|
||||||
"load_15min": 2.1,
|
|
||||||
"frequency_mhz": 3600.005,
|
|
||||||
"temperature_celsius": 56.0
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"usage_percent": 26.780334,
|
|
||||||
"total_gb": 23.339516,
|
|
||||||
"used_gb": 6.2504005,
|
|
||||||
"available_gb": 17.089115,
|
|
||||||
"swap_total_gb": 14.634708,
|
|
||||||
"swap_used_gb": 0.17599106,
|
|
||||||
"tmpfs": [
|
|
||||||
{
|
|
||||||
"mount": "/tmp",
|
|
||||||
"usage_percent": 15.095139,
|
|
||||||
"used_gb": 0.30190277,
|
|
||||||
"total_gb": 2.0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"storage": {
|
|
||||||
"drives": [
|
|
||||||
{
|
|
||||||
"name": "nvme0n1",
|
|
||||||
"health": "PASSED",
|
|
||||||
"temperature_celsius": 28.0,
|
|
||||||
"wear_percent": 1.0,
|
|
||||||
"filesystems": [
|
|
||||||
{
|
|
||||||
"mount": "root",
|
|
||||||
"usage_percent": 24.404377,
|
|
||||||
"used_gb": 226.51398,
|
|
||||||
"total_gb": 928.1695
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"mount": "boot",
|
|
||||||
"usage_percent": 10.666672,
|
|
||||||
"used_gb": 0.10645676,
|
|
||||||
"total_gb": 0.9980316
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"pools": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"name": "tailscaled",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 25.59375,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sshd",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 4.3085938,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"backup": {
|
|
||||||
"status": "unknown",
|
|
||||||
"last_run": null,
|
|
||||||
"next_scheduled": null,
|
|
||||||
"total_size_gb": null,
|
|
||||||
"repository_health": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
────────────────────────────────────────────────────────────────────────────────
|
|
||||||
RAW AGENT DATA FROM cmbox:
|
|
||||||
{
|
|
||||||
"hostname": "cmbox",
|
|
||||||
"agent_version": "v0.1.133",
|
|
||||||
"timestamp": 1763936506,
|
|
||||||
"system": {
|
|
||||||
"cpu": {
|
|
||||||
"load_1min": 1.75,
|
|
||||||
"load_5min": 2.08,
|
|
||||||
"load_15min": 2.1,
|
|
||||||
"frequency_mhz": 3600.005,
|
|
||||||
"temperature_celsius": 56.0
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"usage_percent": 26.780334,
|
|
||||||
"total_gb": 23.339516,
|
|
||||||
"used_gb": 6.2504005,
|
|
||||||
"available_gb": 17.089115,
|
|
||||||
"swap_total_gb": 14.634708,
|
|
||||||
"swap_used_gb": 0.17599106,
|
|
||||||
"tmpfs": [
|
|
||||||
{
|
|
||||||
"mount": "/tmp",
|
|
||||||
"usage_percent": 15.095139,
|
|
||||||
"used_gb": 0.30190277,
|
|
||||||
"total_gb": 2.0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"storage": {
|
|
||||||
"drives": [
|
|
||||||
{
|
|
||||||
"name": "nvme0n1",
|
|
||||||
"health": "PASSED",
|
|
||||||
"temperature_celsius": 28.0,
|
|
||||||
"wear_percent": 1.0,
|
|
||||||
"filesystems": [
|
|
||||||
{
|
|
||||||
"mount": "root",
|
|
||||||
"usage_percent": 24.404377,
|
|
||||||
"used_gb": 226.51398,
|
|
||||||
"total_gb": 928.1695
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"mount": "boot",
|
|
||||||
"usage_percent": 10.666672,
|
|
||||||
"used_gb": 0.10645676,
|
|
||||||
"total_gb": 0.9980316
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"pools": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"name": "tailscaled",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 25.59375,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sshd",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 4.3085938,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"backup": {
|
|
||||||
"status": "unknown",
|
|
||||||
"last_run": null,
|
|
||||||
"next_scheduled": null,
|
|
||||||
"total_size_gb": null,
|
|
||||||
"repository_health": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
────────────────────────────────────────────────────────────────────────────────
|
|
||||||
RAW AGENT DATA FROM cmbox:
|
|
||||||
{
|
|
||||||
"hostname": "cmbox",
|
|
||||||
"agent_version": "v0.1.133",
|
|
||||||
"timestamp": 1763936507,
|
|
||||||
"system": {
|
|
||||||
"cpu": {
|
|
||||||
"load_1min": 1.75,
|
|
||||||
"load_5min": 2.08,
|
|
||||||
"load_15min": 2.1,
|
|
||||||
"frequency_mhz": 3600.005,
|
|
||||||
"temperature_celsius": 56.0
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"usage_percent": 26.780334,
|
|
||||||
"total_gb": 23.339516,
|
|
||||||
"used_gb": 6.2504005,
|
|
||||||
"available_gb": 17.089115,
|
|
||||||
"swap_total_gb": 14.634708,
|
|
||||||
"swap_used_gb": 0.17599106,
|
|
||||||
"tmpfs": [
|
|
||||||
{
|
|
||||||
"mount": "/tmp",
|
|
||||||
"usage_percent": 15.095139,
|
|
||||||
"used_gb": 0.30190277,
|
|
||||||
"total_gb": 2.0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"storage": {
|
|
||||||
"drives": [
|
|
||||||
{
|
|
||||||
"name": "nvme0n1",
|
|
||||||
"health": "PASSED",
|
|
||||||
"temperature_celsius": 28.0,
|
|
||||||
"wear_percent": 1.0,
|
|
||||||
"filesystems": [
|
|
||||||
{
|
|
||||||
"mount": "root",
|
|
||||||
"usage_percent": 24.404377,
|
|
||||||
"used_gb": 226.51398,
|
|
||||||
"total_gb": 928.1695
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"mount": "boot",
|
|
||||||
"usage_percent": 10.666672,
|
|
||||||
"used_gb": 0.10645676,
|
|
||||||
"total_gb": 0.9980316
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"pools": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"name": "tailscaled",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 25.59375,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sshd",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 4.3085938,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"backup": {
|
|
||||||
"status": "unknown",
|
|
||||||
"last_run": null,
|
|
||||||
"next_scheduled": null,
|
|
||||||
"total_size_gb": null,
|
|
||||||
"repository_health": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
────────────────────────────────────────────────────────────────────────────────
|
|
||||||
RAW AGENT DATA FROM cmbox:
|
|
||||||
{
|
|
||||||
"hostname": "cmbox",
|
|
||||||
"agent_version": "v0.1.133",
|
|
||||||
"timestamp": 1763936508,
|
|
||||||
"system": {
|
|
||||||
"cpu": {
|
|
||||||
"load_1min": 1.75,
|
|
||||||
"load_5min": 2.08,
|
|
||||||
"load_15min": 2.1,
|
|
||||||
"frequency_mhz": 3600.005,
|
|
||||||
"temperature_celsius": 56.0
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"usage_percent": 26.780334,
|
|
||||||
"total_gb": 23.339516,
|
|
||||||
"used_gb": 6.2504005,
|
|
||||||
"available_gb": 17.089115,
|
|
||||||
"swap_total_gb": 14.634708,
|
|
||||||
"swap_used_gb": 0.17599106,
|
|
||||||
"tmpfs": [
|
|
||||||
{
|
|
||||||
"mount": "/tmp",
|
|
||||||
"usage_percent": 15.095139,
|
|
||||||
"used_gb": 0.30190277,
|
|
||||||
"total_gb": 2.0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"storage": {
|
|
||||||
"drives": [
|
|
||||||
{
|
|
||||||
"name": "nvme0n1",
|
|
||||||
"health": "PASSED",
|
|
||||||
"temperature_celsius": 28.0,
|
|
||||||
"wear_percent": 1.0,
|
|
||||||
"filesystems": [
|
|
||||||
{
|
|
||||||
"mount": "root",
|
|
||||||
"usage_percent": 24.404377,
|
|
||||||
"used_gb": 226.51398,
|
|
||||||
"total_gb": 928.1695
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"mount": "boot",
|
|
||||||
"usage_percent": 10.666672,
|
|
||||||
"used_gb": 0.10645676,
|
|
||||||
"total_gb": 0.9980316
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"pools": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"name": "tailscaled",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 25.59375,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sshd",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 4.3085938,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"backup": {
|
|
||||||
"status": "unknown",
|
|
||||||
"last_run": null,
|
|
||||||
"next_scheduled": null,
|
|
||||||
"total_size_gb": null,
|
|
||||||
"repository_health": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
────────────────────────────────────────────────────────────────────────────────
|
|
||||||
RAW AGENT DATA FROM cmbox:
|
|
||||||
{
|
|
||||||
"hostname": "cmbox",
|
|
||||||
"agent_version": "v0.1.133",
|
|
||||||
"timestamp": 1763936509,
|
|
||||||
"system": {
|
|
||||||
"cpu": {
|
|
||||||
"load_1min": 1.75,
|
|
||||||
"load_5min": 2.08,
|
|
||||||
"load_15min": 2.1,
|
|
||||||
"frequency_mhz": 3638.71,
|
|
||||||
"temperature_celsius": 56.0
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"usage_percent": 27.014532,
|
|
||||||
"total_gb": 23.339516,
|
|
||||||
"used_gb": 6.3050613,
|
|
||||||
"available_gb": 17.034454,
|
|
||||||
"swap_total_gb": 14.634708,
|
|
||||||
"swap_used_gb": 0.17599106,
|
|
||||||
"tmpfs": [
|
|
||||||
{
|
|
||||||
"mount": "/tmp",
|
|
||||||
"usage_percent": 15.095139,
|
|
||||||
"used_gb": 0.30190277,
|
|
||||||
"total_gb": 2.0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"storage": {
|
|
||||||
"drives": [
|
|
||||||
{
|
|
||||||
"name": "nvme0n1",
|
|
||||||
"health": "PASSED",
|
|
||||||
"temperature_celsius": 28.0,
|
|
||||||
"wear_percent": 1.0,
|
|
||||||
"filesystems": [
|
|
||||||
{
|
|
||||||
"mount": "root",
|
|
||||||
"usage_percent": 24.404377,
|
|
||||||
"used_gb": 226.51398,
|
|
||||||
"total_gb": 928.1695
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"mount": "boot",
|
|
||||||
"usage_percent": 10.666672,
|
|
||||||
"used_gb": 0.10645676,
|
|
||||||
"total_gb": 0.9980316
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"pools": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"name": "tailscaled",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 25.59375,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sshd",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 4.3085938,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"backup": {
|
|
||||||
"status": "unknown",
|
|
||||||
"last_run": null,
|
|
||||||
"next_scheduled": null,
|
|
||||||
"total_size_gb": null,
|
|
||||||
"repository_health": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
────────────────────────────────────────────────────────────────────────────────
|
|
||||||
RAW AGENT DATA FROM cmbox:
|
|
||||||
{
|
|
||||||
"hostname": "cmbox",
|
|
||||||
"agent_version": "v0.1.133",
|
|
||||||
"timestamp": 1763936509,
|
|
||||||
"system": {
|
|
||||||
"cpu": {
|
|
||||||
"load_1min": 0.0,
|
|
||||||
"load_5min": 0.0,
|
|
||||||
"load_15min": 0.0,
|
|
||||||
"frequency_mhz": 0.0,
|
|
||||||
"temperature_celsius": null
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"usage_percent": 0.0,
|
|
||||||
"total_gb": 0.0,
|
|
||||||
"used_gb": 0.0,
|
|
||||||
"available_gb": 0.0,
|
|
||||||
"swap_total_gb": 0.0,
|
|
||||||
"swap_used_gb": 0.0,
|
|
||||||
"tmpfs": []
|
|
||||||
},
|
|
||||||
"storage": {
|
|
||||||
"drives": [],
|
|
||||||
"pools": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"services": [],
|
|
||||||
"backup": {
|
|
||||||
"status": "unknown",
|
|
||||||
"last_run": null,
|
|
||||||
"next_scheduled": null,
|
|
||||||
"total_size_gb": null,
|
|
||||||
"repository_health": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
────────────────────────────────────────────────────────────────────────────────
|
|
||||||
RAW AGENT DATA FROM cmbox:
|
|
||||||
{
|
|
||||||
"hostname": "cmbox",
|
|
||||||
"agent_version": "v0.1.133",
|
|
||||||
"timestamp": 1763936510,
|
|
||||||
"system": {
|
|
||||||
"cpu": {
|
|
||||||
"load_1min": 1.75,
|
|
||||||
"load_5min": 2.08,
|
|
||||||
"load_15min": 2.1,
|
|
||||||
"frequency_mhz": 3638.71,
|
|
||||||
"temperature_celsius": 56.0
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"usage_percent": 27.014532,
|
|
||||||
"total_gb": 23.339516,
|
|
||||||
"used_gb": 6.3050613,
|
|
||||||
"available_gb": 17.034454,
|
|
||||||
"swap_total_gb": 14.634708,
|
|
||||||
"swap_used_gb": 0.17599106,
|
|
||||||
"tmpfs": [
|
|
||||||
{
|
|
||||||
"mount": "/tmp",
|
|
||||||
"usage_percent": 15.095139,
|
|
||||||
"used_gb": 0.30190277,
|
|
||||||
"total_gb": 2.0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"storage": {
|
|
||||||
"drives": [
|
|
||||||
{
|
|
||||||
"name": "nvme0n1",
|
|
||||||
"health": "PASSED",
|
|
||||||
"temperature_celsius": 28.0,
|
|
||||||
"wear_percent": 1.0,
|
|
||||||
"filesystems": [
|
|
||||||
{
|
|
||||||
"mount": "root",
|
|
||||||
"usage_percent": 24.404377,
|
|
||||||
"used_gb": 226.51398,
|
|
||||||
"total_gb": 928.1695
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"mount": "boot",
|
|
||||||
"usage_percent": 10.666672,
|
|
||||||
"used_gb": 0.10645676,
|
|
||||||
"total_gb": 0.9980316
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"pools": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"name": "tailscaled",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 25.59375,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sshd",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 4.3085938,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"backup": {
|
|
||||||
"status": "unknown",
|
|
||||||
"last_run": null,
|
|
||||||
"next_scheduled": null,
|
|
||||||
"total_size_gb": null,
|
|
||||||
"repository_health": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
────────────────────────────────────────────────────────────────────────────────
|
|
||||||
RAW AGENT DATA FROM cmbox:
|
|
||||||
{
|
|
||||||
"hostname": "cmbox",
|
|
||||||
"agent_version": "v0.1.133",
|
|
||||||
"timestamp": 1763936511,
|
|
||||||
"system": {
|
|
||||||
"cpu": {
|
|
||||||
"load_1min": 1.75,
|
|
||||||
"load_5min": 2.08,
|
|
||||||
"load_15min": 2.1,
|
|
||||||
"frequency_mhz": 3638.71,
|
|
||||||
"temperature_celsius": 56.0
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"usage_percent": 27.014532,
|
|
||||||
"total_gb": 23.339516,
|
|
||||||
"used_gb": 6.3050613,
|
|
||||||
"available_gb": 17.034454,
|
|
||||||
"swap_total_gb": 14.634708,
|
|
||||||
"swap_used_gb": 0.17599106,
|
|
||||||
"tmpfs": [
|
|
||||||
{
|
|
||||||
"mount": "/tmp",
|
|
||||||
"usage_percent": 15.095139,
|
|
||||||
"used_gb": 0.30190277,
|
|
||||||
"total_gb": 2.0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"storage": {
|
|
||||||
"drives": [
|
|
||||||
{
|
|
||||||
"name": "nvme0n1",
|
|
||||||
"health": "PASSED",
|
|
||||||
"temperature_celsius": 28.0,
|
|
||||||
"wear_percent": 1.0,
|
|
||||||
"filesystems": [
|
|
||||||
{
|
|
||||||
"mount": "root",
|
|
||||||
"usage_percent": 24.404377,
|
|
||||||
"used_gb": 226.51398,
|
|
||||||
"total_gb": 928.1695
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"mount": "boot",
|
|
||||||
"usage_percent": 10.666672,
|
|
||||||
"used_gb": 0.10645676,
|
|
||||||
"total_gb": 0.9980316
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"pools": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"name": "tailscaled",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 25.59375,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sshd",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 4.3085938,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"backup": {
|
|
||||||
"status": "unknown",
|
|
||||||
"last_run": null,
|
|
||||||
"next_scheduled": null,
|
|
||||||
"total_size_gb": null,
|
|
||||||
"repository_health": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
────────────────────────────────────────────────────────────────────────────────
|
|
||||||
RAW AGENT DATA FROM cmbox:
|
|
||||||
{
|
|
||||||
"hostname": "cmbox",
|
|
||||||
"agent_version": "v0.1.133",
|
|
||||||
"timestamp": 1763936512,
|
|
||||||
"system": {
|
|
||||||
"cpu": {
|
|
||||||
"load_1min": 1.75,
|
|
||||||
"load_5min": 2.08,
|
|
||||||
"load_15min": 2.1,
|
|
||||||
"frequency_mhz": 3638.71,
|
|
||||||
"temperature_celsius": 56.0
|
|
||||||
},
|
|
||||||
"memory": {
|
|
||||||
"usage_percent": 27.014532,
|
|
||||||
"total_gb": 23.339516,
|
|
||||||
"used_gb": 6.3050613,
|
|
||||||
"available_gb": 17.034454,
|
|
||||||
"swap_total_gb": 14.634708,
|
|
||||||
"swap_used_gb": 0.17599106,
|
|
||||||
"tmpfs": [
|
|
||||||
{
|
|
||||||
"mount": "/tmp",
|
|
||||||
"usage_percent": 15.095139,
|
|
||||||
"used_gb": 0.30190277,
|
|
||||||
"total_gb": 2.0
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"storage": {
|
|
||||||
"drives": [
|
|
||||||
{
|
|
||||||
"name": "nvme0n1",
|
|
||||||
"health": "PASSED",
|
|
||||||
"temperature_celsius": 28.0,
|
|
||||||
"wear_percent": 1.0,
|
|
||||||
"filesystems": [
|
|
||||||
{
|
|
||||||
"mount": "root",
|
|
||||||
"usage_percent": 24.404377,
|
|
||||||
"used_gb": 226.51398,
|
|
||||||
"total_gb": 928.1695
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"mount": "boot",
|
|
||||||
"usage_percent": 10.666672,
|
|
||||||
"used_gb": 0.10645676,
|
|
||||||
"total_gb": 0.9980316
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"pools": []
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"services": [
|
|
||||||
{
|
|
||||||
"name": "tailscaled",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 25.59375,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "sshd",
|
|
||||||
"status": "active",
|
|
||||||
"memory_mb": 4.3085938,
|
|
||||||
"disk_gb": 0.0,
|
|
||||||
"user_stopped": false
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"backup": {
|
|
||||||
"status": "unknown",
|
|
||||||
"last_run": null,
|
|
||||||
"next_scheduled": null,
|
|
||||||
"total_size_gb": null,
|
|
||||||
"repository_health": null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
────────────────────────────────────────────────────────────────────────────────
|
|
||||||
Terminated
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.156"
|
version = "0.1.209"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -20,13 +20,12 @@ pub struct Dashboard {
|
|||||||
tui_app: Option<TuiApp>,
|
tui_app: Option<TuiApp>,
|
||||||
terminal: Option<Terminal<CrosstermBackend<io::Stdout>>>,
|
terminal: Option<Terminal<CrosstermBackend<io::Stdout>>>,
|
||||||
headless: bool,
|
headless: bool,
|
||||||
raw_data: bool,
|
|
||||||
initial_commands_sent: std::collections::HashSet<String>,
|
initial_commands_sent: std::collections::HashSet<String>,
|
||||||
config: DashboardConfig,
|
config: DashboardConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dashboard {
|
impl Dashboard {
|
||||||
pub async fn new(config_path: Option<String>, headless: bool, raw_data: bool) -> Result<Self> {
|
pub async fn new(config_path: Option<String>, headless: bool) -> Result<Self> {
|
||||||
info!("Initializing dashboard");
|
info!("Initializing dashboard");
|
||||||
|
|
||||||
// Load configuration - try default path if not specified
|
// Load configuration - try default path if not specified
|
||||||
@@ -120,7 +119,6 @@ impl Dashboard {
|
|||||||
tui_app,
|
tui_app,
|
||||||
terminal,
|
terminal,
|
||||||
headless,
|
headless,
|
||||||
raw_data,
|
|
||||||
initial_commands_sent: std::collections::HashSet::new(),
|
initial_commands_sent: std::collections::HashSet::new(),
|
||||||
config,
|
config,
|
||||||
})
|
})
|
||||||
@@ -205,13 +203,6 @@ impl Dashboard {
|
|||||||
.insert(agent_data.hostname.clone());
|
.insert(agent_data.hostname.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show raw data if requested (before processing)
|
|
||||||
if self.raw_data {
|
|
||||||
println!("RAW AGENT DATA FROM {}:", agent_data.hostname);
|
|
||||||
println!("{}", serde_json::to_string_pretty(&agent_data).unwrap_or_else(|e| format!("Serialization error: {}", e)));
|
|
||||||
println!("{}", "─".repeat(80));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store structured data directly
|
// Store structured data directly
|
||||||
self.metric_store.store_agent_data(agent_data);
|
self.metric_store.store_agent_data(agent_data);
|
||||||
|
|
||||||
@@ -224,7 +215,7 @@ impl Dashboard {
|
|||||||
|
|
||||||
// Update TUI with new metrics (only if not headless)
|
// Update TUI with new metrics (only if not headless)
|
||||||
if let Some(ref mut tui_app) = self.tui_app {
|
if let Some(ref mut tui_app) = self.tui_app {
|
||||||
tui_app.update_metrics(&self.metric_store);
|
tui_app.update_metrics(&mut self.metric_store);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,10 +51,6 @@ struct Cli {
|
|||||||
/// Run in headless mode (no TUI, just logging)
|
/// Run in headless mode (no TUI, just logging)
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
headless: bool,
|
headless: bool,
|
||||||
|
|
||||||
/// Show raw agent data in headless mode
|
|
||||||
#[arg(long)]
|
|
||||||
raw_data: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
@@ -90,7 +86,7 @@ async fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create and run dashboard
|
// Create and run dashboard
|
||||||
let mut dashboard = Dashboard::new(cli.config, cli.headless, cli.raw_data).await?;
|
let mut dashboard = Dashboard::new(cli.config, cli.headless).await?;
|
||||||
|
|
||||||
// Setup graceful shutdown
|
// Setup graceful shutdown
|
||||||
let ctrl_c = async {
|
let ctrl_c = async {
|
||||||
|
|||||||
@@ -5,6 +5,14 @@ use tracing::{debug, info, warn};
|
|||||||
|
|
||||||
use super::MetricDataPoint;
|
use super::MetricDataPoint;
|
||||||
|
|
||||||
|
/// ZMQ communication statistics per host
|
||||||
|
#[derive(Debug, Clone)]
|
||||||
|
pub struct ZmqStats {
|
||||||
|
pub packets_received: u64,
|
||||||
|
pub last_packet_time: Instant,
|
||||||
|
pub last_packet_age_secs: f64,
|
||||||
|
}
|
||||||
|
|
||||||
/// Central metric storage for the dashboard
|
/// Central metric storage for the dashboard
|
||||||
pub struct MetricStore {
|
pub struct MetricStore {
|
||||||
/// Current structured data: hostname -> AgentData
|
/// Current structured data: hostname -> AgentData
|
||||||
@@ -13,6 +21,8 @@ pub struct MetricStore {
|
|||||||
historical_metrics: HashMap<String, Vec<MetricDataPoint>>,
|
historical_metrics: HashMap<String, Vec<MetricDataPoint>>,
|
||||||
/// Last heartbeat timestamp per host
|
/// Last heartbeat timestamp per host
|
||||||
last_heartbeat: HashMap<String, Instant>,
|
last_heartbeat: HashMap<String, Instant>,
|
||||||
|
/// ZMQ communication statistics per host
|
||||||
|
zmq_stats: HashMap<String, ZmqStats>,
|
||||||
/// Configuration
|
/// Configuration
|
||||||
max_metrics_per_host: usize,
|
max_metrics_per_host: usize,
|
||||||
history_retention: Duration,
|
history_retention: Duration,
|
||||||
@@ -24,6 +34,7 @@ impl MetricStore {
|
|||||||
current_agent_data: HashMap::new(),
|
current_agent_data: HashMap::new(),
|
||||||
historical_metrics: HashMap::new(),
|
historical_metrics: HashMap::new(),
|
||||||
last_heartbeat: HashMap::new(),
|
last_heartbeat: HashMap::new(),
|
||||||
|
zmq_stats: HashMap::new(),
|
||||||
max_metrics_per_host,
|
max_metrics_per_host,
|
||||||
history_retention: Duration::from_secs(history_retention_hours * 3600),
|
history_retention: Duration::from_secs(history_retention_hours * 3600),
|
||||||
}
|
}
|
||||||
@@ -44,6 +55,16 @@ impl MetricStore {
|
|||||||
self.last_heartbeat.insert(hostname.clone(), now);
|
self.last_heartbeat.insert(hostname.clone(), now);
|
||||||
debug!("Updated heartbeat for host {}", hostname);
|
debug!("Updated heartbeat for host {}", hostname);
|
||||||
|
|
||||||
|
// Update ZMQ stats
|
||||||
|
let stats = self.zmq_stats.entry(hostname.clone()).or_insert(ZmqStats {
|
||||||
|
packets_received: 0,
|
||||||
|
last_packet_time: now,
|
||||||
|
last_packet_age_secs: 0.0,
|
||||||
|
});
|
||||||
|
stats.packets_received += 1;
|
||||||
|
stats.last_packet_time = now;
|
||||||
|
stats.last_packet_age_secs = 0.0; // Just received
|
||||||
|
|
||||||
// Add to history
|
// Add to history
|
||||||
let host_history = self
|
let host_history = self
|
||||||
.historical_metrics
|
.historical_metrics
|
||||||
@@ -65,6 +86,15 @@ impl MetricStore {
|
|||||||
self.current_agent_data.get(hostname)
|
self.current_agent_data.get(hostname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get ZMQ communication statistics for a host
|
||||||
|
pub fn get_zmq_stats(&mut self, hostname: &str) -> Option<ZmqStats> {
|
||||||
|
let now = Instant::now();
|
||||||
|
self.zmq_stats.get_mut(hostname).map(|stats| {
|
||||||
|
// Update packet age
|
||||||
|
stats.last_packet_age_secs = now.duration_since(stats.last_packet_time).as_secs_f64();
|
||||||
|
stats.clone()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/// Get connected hosts (hosts with recent heartbeats)
|
/// Get connected hosts (hosts with recent heartbeats)
|
||||||
pub fn get_connected_hosts(&self, timeout: Duration) -> Vec<String> {
|
pub fn get_connected_hosts(&self, timeout: Duration) -> Vec<String> {
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ impl TuiApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Update widgets with structured data from store (only for current host)
|
/// Update widgets with structured data from store (only for current host)
|
||||||
pub fn update_metrics(&mut self, metric_store: &MetricStore) {
|
pub fn update_metrics(&mut self, metric_store: &mut MetricStore) {
|
||||||
if let Some(hostname) = self.current_host.clone() {
|
if let Some(hostname) = self.current_host.clone() {
|
||||||
// Get structured data for this host
|
// Get structured data for this host
|
||||||
if let Some(agent_data) = metric_store.get_agent_data(&hostname) {
|
if let Some(agent_data) = metric_store.get_agent_data(&hostname) {
|
||||||
@@ -110,6 +110,14 @@ impl TuiApp {
|
|||||||
host_widgets.system_widget.update_from_agent_data(agent_data);
|
host_widgets.system_widget.update_from_agent_data(agent_data);
|
||||||
host_widgets.services_widget.update_from_agent_data(agent_data);
|
host_widgets.services_widget.update_from_agent_data(agent_data);
|
||||||
|
|
||||||
|
// Update ZMQ stats
|
||||||
|
if let Some(zmq_stats) = metric_store.get_zmq_stats(&hostname) {
|
||||||
|
host_widgets.system_widget.update_zmq_stats(
|
||||||
|
zmq_stats.packets_received,
|
||||||
|
zmq_stats.last_packet_age_secs
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
host_widgets.last_update = Some(Instant::now());
|
host_widgets.last_update = Some(Instant::now());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -225,9 +225,6 @@ impl Layout {
|
|||||||
pub const LEFT_PANEL_WIDTH: u16 = 45;
|
pub const LEFT_PANEL_WIDTH: u16 = 45;
|
||||||
/// Right panel percentage (services)
|
/// Right panel percentage (services)
|
||||||
pub const RIGHT_PANEL_WIDTH: u16 = 55;
|
pub const RIGHT_PANEL_WIDTH: u16 = 55;
|
||||||
/// System vs backup split (equal)
|
|
||||||
pub const SYSTEM_PANEL_HEIGHT: u16 = 50;
|
|
||||||
pub const BACKUP_PANEL_HEIGHT: u16 = 50;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Typography system
|
/// Typography system
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
// This file is intentionally left minimal - CPU functionality is handled by the SystemWidget
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
// This file is intentionally left minimal - Memory functionality is handled by the SystemWidget
|
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
use cm_dashboard_shared::AgentData;
|
use cm_dashboard_shared::AgentData;
|
||||||
|
|
||||||
pub mod cpu;
|
|
||||||
pub mod memory;
|
|
||||||
pub mod services;
|
pub mod services;
|
||||||
pub mod system;
|
pub mod system;
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,12 @@ pub struct ServicesWidget {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct ServiceInfo {
|
struct ServiceInfo {
|
||||||
memory_mb: Option<f32>,
|
|
||||||
disk_gb: Option<f32>,
|
|
||||||
metrics: Vec<(String, f32, Option<String>)>, // (label, value, unit)
|
metrics: Vec<(String, f32, Option<String>)>, // (label, value, unit)
|
||||||
widget_status: Status,
|
widget_status: Status,
|
||||||
|
service_type: String, // "nginx_site", "container", "image", or empty for parent services
|
||||||
|
memory_bytes: Option<u64>,
|
||||||
|
restart_count: Option<u32>,
|
||||||
|
uptime_seconds: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ServicesWidget {
|
impl ServicesWidget {
|
||||||
@@ -51,8 +53,6 @@ impl ServicesWidget {
|
|||||||
if metric_name.starts_with("service_") {
|
if metric_name.starts_with("service_") {
|
||||||
if let Some(end_pos) = metric_name
|
if let Some(end_pos) = metric_name
|
||||||
.rfind("_status")
|
.rfind("_status")
|
||||||
.or_else(|| metric_name.rfind("_memory_mb"))
|
|
||||||
.or_else(|| metric_name.rfind("_disk_gb"))
|
|
||||||
.or_else(|| metric_name.rfind("_latency_ms"))
|
.or_else(|| metric_name.rfind("_latency_ms"))
|
||||||
{
|
{
|
||||||
let service_part = &metric_name[8..end_pos]; // Remove "service_" prefix
|
let service_part = &metric_name[8..end_pos]; // Remove "service_" prefix
|
||||||
@@ -75,36 +75,8 @@ impl ServicesWidget {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format disk size with appropriate units (kB/MB/GB)
|
|
||||||
fn format_disk_size(size_gb: f32) -> String {
|
|
||||||
let size_mb = size_gb * 1024.0; // Convert GB to MB
|
|
||||||
|
|
||||||
if size_mb >= 1024.0 {
|
|
||||||
// Show as GB
|
|
||||||
format!("{:.1}GB", size_gb)
|
|
||||||
} else if size_mb >= 1.0 {
|
|
||||||
// Show as MB
|
|
||||||
format!("{:.0}MB", size_mb)
|
|
||||||
} else if size_mb >= 0.001 {
|
|
||||||
// Convert to kB
|
|
||||||
let size_kb = size_mb * 1024.0;
|
|
||||||
format!("{:.0}kB", size_kb)
|
|
||||||
} else {
|
|
||||||
// Show very small sizes as bytes
|
|
||||||
let size_bytes = size_mb * 1024.0 * 1024.0;
|
|
||||||
format!("{:.0}B", size_bytes)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Format parent service line - returns text without icon for span formatting
|
/// Format parent service line - returns text without icon for span formatting
|
||||||
fn format_parent_service_line(&self, name: &str, info: &ServiceInfo) -> String {
|
fn format_parent_service_line(&self, name: &str, info: &ServiceInfo) -> String {
|
||||||
let memory_str = info
|
|
||||||
.memory_mb
|
|
||||||
.map_or("0M".to_string(), |m| format!("{:.0}M", m));
|
|
||||||
let disk_str = info
|
|
||||||
.disk_gb
|
|
||||||
.map_or("0".to_string(), |d| Self::format_disk_size(d));
|
|
||||||
|
|
||||||
// Truncate long service names to fit layout (account for icon space)
|
// Truncate long service names to fit layout (account for icon space)
|
||||||
let short_name = if name.len() > 22 {
|
let short_name = if name.len() > 22 {
|
||||||
format!("{}...", &name[..19])
|
format!("{}...", &name[..19])
|
||||||
@@ -115,7 +87,7 @@ impl ServicesWidget {
|
|||||||
// Convert Status enum to display text
|
// Convert Status enum to display text
|
||||||
let status_str = match info.widget_status {
|
let status_str = match info.widget_status {
|
||||||
Status::Ok => "active",
|
Status::Ok => "active",
|
||||||
Status::Inactive => "inactive",
|
Status::Inactive => "inactive",
|
||||||
Status::Critical => "failed",
|
Status::Critical => "failed",
|
||||||
Status::Pending => "pending",
|
Status::Pending => "pending",
|
||||||
Status::Warning => "warning",
|
Status::Warning => "warning",
|
||||||
@@ -123,9 +95,43 @@ impl ServicesWidget {
|
|||||||
Status::Offline => "offline",
|
Status::Offline => "offline",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Format memory
|
||||||
|
let memory_str = info.memory_bytes.map_or("-".to_string(), |bytes| {
|
||||||
|
let mb = bytes as f64 / (1024.0 * 1024.0);
|
||||||
|
if mb >= 1000.0 {
|
||||||
|
format!("{:.1}G", mb / 1024.0)
|
||||||
|
} else {
|
||||||
|
format!("{:.0}M", mb)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Format uptime
|
||||||
|
let uptime_str = info.uptime_seconds.map_or("-".to_string(), |secs| {
|
||||||
|
let days = secs / 86400;
|
||||||
|
let hours = (secs % 86400) / 3600;
|
||||||
|
let mins = (secs % 3600) / 60;
|
||||||
|
|
||||||
|
if days > 0 {
|
||||||
|
format!("{}d{}h", days, hours)
|
||||||
|
} else if hours > 0 {
|
||||||
|
format!("{}h{}m", hours, mins)
|
||||||
|
} else {
|
||||||
|
format!("{}m", mins)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Format restarts (show "!" if > 0 to indicate instability)
|
||||||
|
let restart_str = info.restart_count.map_or("-".to_string(), |count| {
|
||||||
|
if count > 0 {
|
||||||
|
format!("!{}", count)
|
||||||
|
} else {
|
||||||
|
"0".to_string()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
format!(
|
format!(
|
||||||
"{:<23} {:<10} {:<8} {:<8}",
|
"{:<23} {:<10} {:<8} {:<8} {:<5}",
|
||||||
short_name, status_str, memory_str, disk_str
|
short_name, status_str, memory_str, uptime_str, restart_str
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +175,7 @@ impl ServicesWidget {
|
|||||||
// Convert Status enum to display text for sub-services
|
// Convert Status enum to display text for sub-services
|
||||||
match info.widget_status {
|
match info.widget_status {
|
||||||
Status::Ok => "active",
|
Status::Ok => "active",
|
||||||
Status::Inactive => "inactive",
|
Status::Inactive => "inactive",
|
||||||
Status::Critical => "failed",
|
Status::Critical => "failed",
|
||||||
Status::Pending => "pending",
|
Status::Pending => "pending",
|
||||||
Status::Warning => "warning",
|
Status::Warning => "warning",
|
||||||
@@ -179,32 +185,62 @@ impl ServicesWidget {
|
|||||||
};
|
};
|
||||||
let tree_symbol = if is_last { "└─" } else { "├─" };
|
let tree_symbol = if is_last { "└─" } else { "├─" };
|
||||||
|
|
||||||
vec![
|
// Docker images use docker whale icon
|
||||||
// Indentation and tree prefix
|
if info.service_type == "image" {
|
||||||
ratatui::text::Span::styled(
|
vec![
|
||||||
format!(" {} ", tree_symbol),
|
// Indentation and tree prefix
|
||||||
Typography::tree(),
|
ratatui::text::Span::styled(
|
||||||
),
|
format!(" {} ", tree_symbol),
|
||||||
// Status icon
|
Typography::tree(),
|
||||||
ratatui::text::Span::styled(
|
),
|
||||||
format!("{} ", icon),
|
// Docker icon (simple character for performance)
|
||||||
Style::default().fg(status_color).bg(Theme::background()),
|
ratatui::text::Span::styled(
|
||||||
),
|
"D ".to_string(),
|
||||||
// Service name
|
Style::default().fg(Theme::highlight()).bg(Theme::background()),
|
||||||
ratatui::text::Span::styled(
|
),
|
||||||
format!("{:<18} ", short_name),
|
// Service name
|
||||||
Style::default()
|
ratatui::text::Span::styled(
|
||||||
.fg(Theme::secondary_text())
|
format!("{:<18} ", short_name),
|
||||||
.bg(Theme::background()),
|
Style::default()
|
||||||
),
|
.fg(Theme::secondary_text())
|
||||||
// Status/latency text
|
.bg(Theme::background()),
|
||||||
ratatui::text::Span::styled(
|
),
|
||||||
status_str,
|
// Status/metrics text
|
||||||
Style::default()
|
ratatui::text::Span::styled(
|
||||||
.fg(Theme::secondary_text())
|
status_str,
|
||||||
.bg(Theme::background()),
|
Style::default()
|
||||||
),
|
.fg(Theme::secondary_text())
|
||||||
]
|
.bg(Theme::background()),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
} else {
|
||||||
|
vec![
|
||||||
|
// Indentation and tree prefix
|
||||||
|
ratatui::text::Span::styled(
|
||||||
|
format!(" {} ", tree_symbol),
|
||||||
|
Typography::tree(),
|
||||||
|
),
|
||||||
|
// Status icon
|
||||||
|
ratatui::text::Span::styled(
|
||||||
|
format!("{} ", icon),
|
||||||
|
Style::default().fg(status_color).bg(Theme::background()),
|
||||||
|
),
|
||||||
|
// Service name
|
||||||
|
ratatui::text::Span::styled(
|
||||||
|
format!("{:<18} ", short_name),
|
||||||
|
Style::default()
|
||||||
|
.fg(Theme::secondary_text())
|
||||||
|
.bg(Theme::background()),
|
||||||
|
),
|
||||||
|
// Status/latency text
|
||||||
|
ratatui::text::Span::styled(
|
||||||
|
status_str,
|
||||||
|
Style::default()
|
||||||
|
.fg(Theme::secondary_text())
|
||||||
|
.bg(Theme::background()),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Move selection up
|
/// Move selection up
|
||||||
@@ -278,13 +314,15 @@ impl Widget for ServicesWidget {
|
|||||||
for service in &agent_data.services {
|
for service in &agent_data.services {
|
||||||
// Store parent service
|
// Store parent service
|
||||||
let parent_info = ServiceInfo {
|
let parent_info = ServiceInfo {
|
||||||
memory_mb: Some(service.memory_mb),
|
|
||||||
disk_gb: Some(service.disk_gb),
|
|
||||||
metrics: Vec::new(), // Parent services don't have custom metrics
|
metrics: Vec::new(), // Parent services don't have custom metrics
|
||||||
widget_status: service.service_status,
|
widget_status: service.service_status,
|
||||||
|
service_type: String::new(), // Parent services have no type
|
||||||
|
memory_bytes: service.memory_bytes,
|
||||||
|
restart_count: service.restart_count,
|
||||||
|
uptime_seconds: service.uptime_seconds,
|
||||||
};
|
};
|
||||||
self.parent_services.insert(service.name.clone(), parent_info);
|
self.parent_services.insert(service.name.clone(), parent_info);
|
||||||
|
|
||||||
// Process sub-services if any
|
// Process sub-services if any
|
||||||
if !service.sub_services.is_empty() {
|
if !service.sub_services.is_empty() {
|
||||||
let mut sub_list = Vec::new();
|
let mut sub_list = Vec::new();
|
||||||
@@ -293,12 +331,14 @@ impl Widget for ServicesWidget {
|
|||||||
let metrics: Vec<(String, f32, Option<String>)> = sub_service.metrics.iter()
|
let metrics: Vec<(String, f32, Option<String>)> = sub_service.metrics.iter()
|
||||||
.map(|m| (m.label.clone(), m.value, m.unit.clone()))
|
.map(|m| (m.label.clone(), m.value, m.unit.clone()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let sub_info = ServiceInfo {
|
let sub_info = ServiceInfo {
|
||||||
memory_mb: None, // Not used for sub-services
|
|
||||||
disk_gb: None, // Not used for sub-services
|
|
||||||
metrics,
|
metrics,
|
||||||
widget_status: sub_service.service_status,
|
widget_status: sub_service.service_status,
|
||||||
|
service_type: sub_service.service_type.clone(),
|
||||||
|
memory_bytes: None, // Sub-services don't have individual metrics yet
|
||||||
|
restart_count: None,
|
||||||
|
uptime_seconds: None,
|
||||||
};
|
};
|
||||||
sub_list.push((sub_service.name.clone(), sub_info));
|
sub_list.push((sub_service.name.clone(), sub_info));
|
||||||
}
|
}
|
||||||
@@ -338,22 +378,16 @@ impl ServicesWidget {
|
|||||||
self.parent_services
|
self.parent_services
|
||||||
.entry(parent_service)
|
.entry(parent_service)
|
||||||
.or_insert(ServiceInfo {
|
.or_insert(ServiceInfo {
|
||||||
memory_mb: None,
|
|
||||||
disk_gb: None,
|
|
||||||
metrics: Vec::new(),
|
metrics: Vec::new(),
|
||||||
widget_status: Status::Unknown,
|
widget_status: Status::Unknown,
|
||||||
|
service_type: String::new(),
|
||||||
|
memory_bytes: None,
|
||||||
|
restart_count: None,
|
||||||
|
uptime_seconds: None,
|
||||||
});
|
});
|
||||||
|
|
||||||
if metric.name.ends_with("_status") {
|
if metric.name.ends_with("_status") {
|
||||||
service_info.widget_status = metric.status;
|
service_info.widget_status = metric.status;
|
||||||
} else if metric.name.ends_with("_memory_mb") {
|
|
||||||
if let Some(memory) = metric.value.as_f32() {
|
|
||||||
service_info.memory_mb = Some(memory);
|
|
||||||
}
|
|
||||||
} else if metric.name.ends_with("_disk_gb") {
|
|
||||||
if let Some(disk) = metric.value.as_f32() {
|
|
||||||
service_info.disk_gb = Some(disk);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(sub_name) => {
|
Some(sub_name) => {
|
||||||
@@ -373,10 +407,12 @@ impl ServicesWidget {
|
|||||||
sub_service_list.push((
|
sub_service_list.push((
|
||||||
sub_name.clone(),
|
sub_name.clone(),
|
||||||
ServiceInfo {
|
ServiceInfo {
|
||||||
memory_mb: None,
|
|
||||||
disk_gb: None,
|
|
||||||
metrics: Vec::new(),
|
metrics: Vec::new(),
|
||||||
widget_status: Status::Unknown,
|
widget_status: Status::Unknown,
|
||||||
|
service_type: String::new(), // Unknown type in legacy path
|
||||||
|
memory_bytes: None,
|
||||||
|
restart_count: None,
|
||||||
|
uptime_seconds: None,
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
&mut sub_service_list.last_mut().unwrap().1
|
&mut sub_service_list.last_mut().unwrap().1
|
||||||
@@ -384,14 +420,6 @@ impl ServicesWidget {
|
|||||||
|
|
||||||
if metric.name.ends_with("_status") {
|
if metric.name.ends_with("_status") {
|
||||||
sub_service_info.widget_status = metric.status;
|
sub_service_info.widget_status = metric.status;
|
||||||
} else if metric.name.ends_with("_memory_mb") {
|
|
||||||
if let Some(memory) = metric.value.as_f32() {
|
|
||||||
sub_service_info.memory_mb = Some(memory);
|
|
||||||
}
|
|
||||||
} else if metric.name.ends_with("_disk_gb") {
|
|
||||||
if let Some(disk) = metric.value.as_f32() {
|
|
||||||
sub_service_info.disk_gb = Some(disk);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -450,8 +478,8 @@ impl ServicesWidget {
|
|||||||
|
|
||||||
// Header
|
// Header
|
||||||
let header = format!(
|
let header = format!(
|
||||||
"{:<25} {:<10} {:<8} {:<8}",
|
"{:<25} {:<10} {:<8} {:<8} {:<5}",
|
||||||
"Service:", "Status:", "RAM:", "Disk:"
|
"Service:", "Status:", "RAM:", "Uptime:", "↻:"
|
||||||
);
|
);
|
||||||
let header_para = Paragraph::new(header).style(Typography::muted());
|
let header_para = Paragraph::new(header).style(Typography::muted());
|
||||||
frame.render_widget(header_para, content_chunks[0]);
|
frame.render_widget(header_para, content_chunks[0]);
|
||||||
|
|||||||
@@ -8,18 +8,25 @@ use ratatui::{
|
|||||||
|
|
||||||
use crate::ui::theme::{StatusIcons, Typography};
|
use crate::ui::theme::{StatusIcons, Typography};
|
||||||
|
|
||||||
/// System widget displaying NixOS info, CPU, RAM, and Storage in unified layout
|
/// System widget displaying NixOS info, Network, CPU, RAM, and Storage in unified layout
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct SystemWidget {
|
pub struct SystemWidget {
|
||||||
// NixOS information
|
// NixOS information
|
||||||
nixos_build: Option<String>,
|
nixos_build: Option<String>,
|
||||||
agent_hash: Option<String>,
|
agent_hash: Option<String>,
|
||||||
|
|
||||||
|
// ZMQ communication stats
|
||||||
|
zmq_packets_received: Option<u64>,
|
||||||
|
zmq_last_packet_age: Option<f64>,
|
||||||
|
|
||||||
|
// Network interfaces
|
||||||
|
network_interfaces: Vec<cm_dashboard_shared::NetworkInterfaceData>,
|
||||||
|
|
||||||
// CPU metrics
|
// CPU metrics
|
||||||
cpu_load_1min: Option<f32>,
|
cpu_load_1min: Option<f32>,
|
||||||
cpu_load_5min: Option<f32>,
|
cpu_load_5min: Option<f32>,
|
||||||
cpu_load_15min: Option<f32>,
|
cpu_load_15min: Option<f32>,
|
||||||
cpu_frequency: Option<f32>,
|
cpu_cstates: Vec<cm_dashboard_shared::CStateInfo>,
|
||||||
cpu_status: Status,
|
cpu_status: Status,
|
||||||
|
|
||||||
// Memory metrics
|
// Memory metrics
|
||||||
@@ -89,10 +96,13 @@ impl SystemWidget {
|
|||||||
Self {
|
Self {
|
||||||
nixos_build: None,
|
nixos_build: None,
|
||||||
agent_hash: None,
|
agent_hash: None,
|
||||||
|
zmq_packets_received: None,
|
||||||
|
zmq_last_packet_age: None,
|
||||||
|
network_interfaces: Vec::new(),
|
||||||
cpu_load_1min: None,
|
cpu_load_1min: None,
|
||||||
cpu_load_5min: None,
|
cpu_load_5min: None,
|
||||||
cpu_load_15min: None,
|
cpu_load_15min: None,
|
||||||
cpu_frequency: None,
|
cpu_cstates: Vec::new(),
|
||||||
cpu_status: Status::Unknown,
|
cpu_status: Status::Unknown,
|
||||||
memory_usage_percent: None,
|
memory_usage_percent: None,
|
||||||
memory_used_gb: None,
|
memory_used_gb: None,
|
||||||
@@ -127,12 +137,18 @@ impl SystemWidget {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format CPU frequency
|
/// Format CPU C-states (idle depth) with percentages
|
||||||
fn format_cpu_frequency(&self) -> String {
|
fn format_cpu_cstate(&self) -> String {
|
||||||
match self.cpu_frequency {
|
if self.cpu_cstates.is_empty() {
|
||||||
Some(freq) => format!("{:.0} MHz", freq),
|
return "—".to_string();
|
||||||
None => "— MHz".to_string(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Format top 3 C-states with percentages: "C10:79% C8:10% C6:8%"
|
||||||
|
self.cpu_cstates
|
||||||
|
.iter()
|
||||||
|
.map(|cs| format!("{}:{:.0}%", cs.name, cs.percent))
|
||||||
|
.collect::<Vec<_>>()
|
||||||
|
.join(" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format memory usage
|
/// Format memory usage
|
||||||
@@ -150,6 +166,12 @@ impl SystemWidget {
|
|||||||
pub fn _get_agent_hash(&self) -> Option<&String> {
|
pub fn _get_agent_hash(&self) -> Option<&String> {
|
||||||
self.agent_hash.as_ref()
|
self.agent_hash.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Update ZMQ communication statistics
|
||||||
|
pub fn update_zmq_stats(&mut self, packets_received: u64, last_packet_age_secs: f64) {
|
||||||
|
self.zmq_packets_received = Some(packets_received);
|
||||||
|
self.zmq_last_packet_age = Some(last_packet_age_secs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use super::Widget;
|
use super::Widget;
|
||||||
@@ -164,12 +186,15 @@ impl Widget for SystemWidget {
|
|||||||
// Extract build version
|
// Extract build version
|
||||||
self.nixos_build = agent_data.build_version.clone();
|
self.nixos_build = agent_data.build_version.clone();
|
||||||
|
|
||||||
|
// Extract network interfaces
|
||||||
|
self.network_interfaces = agent_data.system.network.interfaces.clone();
|
||||||
|
|
||||||
// Extract CPU data directly
|
// Extract CPU data directly
|
||||||
let cpu = &agent_data.system.cpu;
|
let cpu = &agent_data.system.cpu;
|
||||||
self.cpu_load_1min = Some(cpu.load_1min);
|
self.cpu_load_1min = Some(cpu.load_1min);
|
||||||
self.cpu_load_5min = Some(cpu.load_5min);
|
self.cpu_load_5min = Some(cpu.load_5min);
|
||||||
self.cpu_load_15min = Some(cpu.load_15min);
|
self.cpu_load_15min = Some(cpu.load_15min);
|
||||||
self.cpu_frequency = Some(cpu.frequency_mhz);
|
self.cpu_cstates = cpu.cstates.clone();
|
||||||
self.cpu_status = Status::Ok;
|
self.cpu_status = Status::Ok;
|
||||||
|
|
||||||
// Extract memory data directly
|
// Extract memory data directly
|
||||||
@@ -368,12 +393,8 @@ impl SystemWidget {
|
|||||||
// Pool header line with type and health
|
// Pool header line with type and health
|
||||||
let pool_label = if pool.pool_type == "drive" {
|
let pool_label = if pool.pool_type == "drive" {
|
||||||
// For physical drives, show the drive name with temperature and wear percentage if available
|
// For physical drives, show the drive name with temperature and wear percentage if available
|
||||||
// Look for any drive with temp/wear data (physical drives may have drives named after the pool)
|
// Physical drives only have one drive entry
|
||||||
let drive_info = pool.drives.iter()
|
if let Some(drive) = pool.drives.first() {
|
||||||
.find(|d| d.name == pool.name)
|
|
||||||
.or_else(|| pool.drives.first());
|
|
||||||
|
|
||||||
if let Some(drive) = drive_info {
|
|
||||||
let mut drive_details = Vec::new();
|
let mut drive_details = Vec::new();
|
||||||
if let Some(temp) = drive.temperature {
|
if let Some(temp) = drive.temperature {
|
||||||
drive_details.push(format!("T: {}°C", temp as i32));
|
drive_details.push(format!("T: {}°C", temp as i32));
|
||||||
@@ -381,11 +402,11 @@ impl SystemWidget {
|
|||||||
if let Some(wear) = drive.wear_percent {
|
if let Some(wear) = drive.wear_percent {
|
||||||
drive_details.push(format!("W: {}%", wear as i32));
|
drive_details.push(format!("W: {}%", wear as i32));
|
||||||
}
|
}
|
||||||
|
|
||||||
if !drive_details.is_empty() {
|
if !drive_details.is_empty() {
|
||||||
format!("{} {}", pool.name, drive_details.join(" "))
|
format!("{} {}", drive.name, drive_details.join(" "))
|
||||||
} else {
|
} else {
|
||||||
pool.name.clone()
|
drive.name.clone()
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
pool.name.clone()
|
pool.name.clone()
|
||||||
@@ -443,7 +464,9 @@ impl SystemWidget {
|
|||||||
lines.push(Line::from(total_spans));
|
lines.push(Line::from(total_spans));
|
||||||
|
|
||||||
// Data drives - at same level as parity
|
// Data drives - at same level as parity
|
||||||
|
let has_parity = !pool.parity_drives.is_empty();
|
||||||
for (i, drive) in pool.data_drives.iter().enumerate() {
|
for (i, drive) in pool.data_drives.iter().enumerate() {
|
||||||
|
let is_last_data = i == pool.data_drives.len() - 1;
|
||||||
let mut drive_details = Vec::new();
|
let mut drive_details = Vec::new();
|
||||||
if let Some(temp) = drive.temperature {
|
if let Some(temp) = drive.temperature {
|
||||||
drive_details.push(format!("T: {}°C", temp as i32));
|
drive_details.push(format!("T: {}°C", temp as i32));
|
||||||
@@ -458,16 +481,19 @@ impl SystemWidget {
|
|||||||
format!("Data_{}: {}", i + 1, drive.name)
|
format!("Data_{}: {}", i + 1, drive.name)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Last data drive uses └─ if there's no parity, otherwise ├─
|
||||||
|
let tree_symbol = if is_last_data && !has_parity { " └─ " } else { " ├─ " };
|
||||||
let mut data_spans = vec![
|
let mut data_spans = vec![
|
||||||
Span::styled(" ├─ ", Typography::tree()),
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
];
|
];
|
||||||
data_spans.extend(StatusIcons::create_status_spans(drive.status.clone(), &drive_text));
|
data_spans.extend(StatusIcons::create_status_spans(drive.status.clone(), &drive_text));
|
||||||
lines.push(Line::from(data_spans));
|
lines.push(Line::from(data_spans));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parity drives - last item
|
// Parity drives - last item(s)
|
||||||
if !pool.parity_drives.is_empty() {
|
if !pool.parity_drives.is_empty() {
|
||||||
for drive in &pool.parity_drives {
|
for (i, drive) in pool.parity_drives.iter().enumerate() {
|
||||||
|
let is_last = i == pool.parity_drives.len() - 1;
|
||||||
let mut drive_details = Vec::new();
|
let mut drive_details = Vec::new();
|
||||||
if let Some(temp) = drive.temperature {
|
if let Some(temp) = drive.temperature {
|
||||||
drive_details.push(format!("T: {}°C", temp as i32));
|
drive_details.push(format!("T: {}°C", temp as i32));
|
||||||
@@ -482,8 +508,9 @@ impl SystemWidget {
|
|||||||
format!("Parity: {}", drive.name)
|
format!("Parity: {}", drive.name)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||||
let mut parity_spans = vec![
|
let mut parity_spans = vec![
|
||||||
Span::styled(" └─ ", Typography::tree()),
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
];
|
];
|
||||||
parity_spans.extend(StatusIcons::create_status_spans(drive.status.clone(), &drive_text));
|
parity_spans.extend(StatusIcons::create_status_spans(drive.status.clone(), &drive_text));
|
||||||
lines.push(Line::from(parity_spans));
|
lines.push(Line::from(parity_spans));
|
||||||
@@ -506,55 +533,6 @@ fn truncate_serial(serial: &str) -> String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper function to render a drive in a MergerFS pool
|
|
||||||
fn render_mergerfs_drive<'a>(drive: &StorageDrive, tree_symbol: &'a str, lines: &mut Vec<Line<'a>>) {
|
|
||||||
let mut drive_details = Vec::new();
|
|
||||||
if let Some(temp) = drive.temperature {
|
|
||||||
drive_details.push(format!("T: {}°C", temp as i32));
|
|
||||||
}
|
|
||||||
if let Some(wear) = drive.wear_percent {
|
|
||||||
drive_details.push(format!("W: {}%", wear as i32));
|
|
||||||
}
|
|
||||||
|
|
||||||
let drive_text = if !drive_details.is_empty() {
|
|
||||||
format!("{} {}", drive.name, drive_details.join(" "))
|
|
||||||
} else {
|
|
||||||
drive.name.clone()
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut drive_spans = vec![
|
|
||||||
Span::styled(tree_symbol, Typography::tree()),
|
|
||||||
];
|
|
||||||
drive_spans.extend(StatusIcons::create_status_spans(drive.status.clone(), &drive_text));
|
|
||||||
lines.push(Line::from(drive_spans));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Helper function to render a drive in a storage pool
|
|
||||||
fn render_pool_drive(drive: &StorageDrive, is_last: bool, lines: &mut Vec<Line<'_>>) {
|
|
||||||
let tree_symbol = if is_last { " └─" } else { " ├─" };
|
|
||||||
|
|
||||||
let mut drive_details = Vec::new();
|
|
||||||
if let Some(temp) = drive.temperature {
|
|
||||||
drive_details.push(format!("T: {}°C", temp as i32));
|
|
||||||
}
|
|
||||||
if let Some(wear) = drive.wear_percent {
|
|
||||||
drive_details.push(format!("W: {}%", wear as i32));
|
|
||||||
}
|
|
||||||
|
|
||||||
let drive_text = if !drive_details.is_empty() {
|
|
||||||
format!("● {} {}", drive.name, drive_details.join(" "))
|
|
||||||
} else {
|
|
||||||
format!("● {}", drive.name)
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut drive_spans = vec![
|
|
||||||
Span::styled(tree_symbol, Typography::tree()),
|
|
||||||
Span::raw(" "),
|
|
||||||
];
|
|
||||||
drive_spans.extend(StatusIcons::create_status_spans(drive.status.clone(), &drive_text));
|
|
||||||
lines.push(Line::from(drive_spans));
|
|
||||||
}
|
|
||||||
|
|
||||||
impl SystemWidget {
|
impl SystemWidget {
|
||||||
/// Render backup section for display
|
/// Render backup section for display
|
||||||
fn render_backup(&self) -> Vec<Line<'_>> {
|
fn render_backup(&self) -> Vec<Line<'_>> {
|
||||||
@@ -620,45 +598,205 @@ impl SystemWidget {
|
|||||||
lines
|
lines
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format time ago from timestamp
|
/// Compress IPv4 addresses from same subnet
|
||||||
fn format_time_ago(&self, timestamp: u64) -> String {
|
/// Example: "192.168.30.1, 192.168.30.100" -> "192.168.30.1, 100"
|
||||||
let now = chrono::Utc::now().timestamp() as u64;
|
fn compress_ipv4_addresses(addresses: &[String]) -> String {
|
||||||
let seconds_ago = now.saturating_sub(timestamp);
|
if addresses.is_empty() {
|
||||||
|
return String::new();
|
||||||
let hours = seconds_ago / 3600;
|
|
||||||
let minutes = (seconds_ago % 3600) / 60;
|
|
||||||
|
|
||||||
if hours > 0 {
|
|
||||||
format!("{}h ago", hours)
|
|
||||||
} else if minutes > 0 {
|
|
||||||
format!("{}m ago", minutes)
|
|
||||||
} else {
|
|
||||||
"now".to_string()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if addresses.len() == 1 {
|
||||||
|
return addresses[0].clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut result = Vec::new();
|
||||||
|
let mut last_prefix = String::new();
|
||||||
|
|
||||||
|
for addr in addresses {
|
||||||
|
let parts: Vec<&str> = addr.split('.').collect();
|
||||||
|
if parts.len() == 4 {
|
||||||
|
let prefix = format!("{}.{}.{}", parts[0], parts[1], parts[2]);
|
||||||
|
|
||||||
|
if prefix == last_prefix {
|
||||||
|
// Same subnet, show only last octet
|
||||||
|
result.push(parts[3].to_string());
|
||||||
|
} else {
|
||||||
|
// Different subnet, show full IP
|
||||||
|
result.push(addr.clone());
|
||||||
|
last_prefix = prefix;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Invalid IP format, show as-is
|
||||||
|
result.push(addr.clone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
result.join(", ")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Format time until from future timestamp
|
/// Render network section for display with physical/virtual grouping
|
||||||
fn format_time_until(&self, timestamp: u64) -> String {
|
fn render_network(&self) -> Vec<Line<'_>> {
|
||||||
let now = chrono::Utc::now().timestamp() as u64;
|
let mut lines = Vec::new();
|
||||||
if timestamp <= now {
|
|
||||||
return "overdue".to_string();
|
if self.network_interfaces.is_empty() {
|
||||||
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
let seconds_until = timestamp - now;
|
// Separate physical and virtual interfaces
|
||||||
let hours = seconds_until / 3600;
|
let physical: Vec<_> = self.network_interfaces.iter().filter(|i| i.is_physical).collect();
|
||||||
let minutes = (seconds_until % 3600) / 60;
|
let virtual_interfaces: Vec<_> = self.network_interfaces.iter().filter(|i| !i.is_physical).collect();
|
||||||
|
|
||||||
if hours > 0 {
|
// Find standalone virtual interfaces (those without a parent)
|
||||||
format!("in {}h", hours)
|
let mut standalone_virtual: Vec<_> = virtual_interfaces.iter()
|
||||||
} else if minutes > 0 {
|
.filter(|i| i.parent_interface.is_none())
|
||||||
format!("in {}m", minutes)
|
.collect();
|
||||||
} else {
|
|
||||||
"soon".to_string()
|
// Sort standalone virtual: VLANs first (by VLAN ID), then others alphabetically
|
||||||
|
standalone_virtual.sort_by(|a, b| {
|
||||||
|
match (a.vlan_id, b.vlan_id) {
|
||||||
|
(Some(vlan_a), Some(vlan_b)) => vlan_a.cmp(&vlan_b),
|
||||||
|
(Some(_), None) => std::cmp::Ordering::Less,
|
||||||
|
(None, Some(_)) => std::cmp::Ordering::Greater,
|
||||||
|
(None, None) => a.name.cmp(&b.name),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Render physical interfaces with their children
|
||||||
|
for (phy_idx, interface) in physical.iter().enumerate() {
|
||||||
|
let is_last_physical = phy_idx == physical.len() - 1 && standalone_virtual.is_empty();
|
||||||
|
|
||||||
|
// Physical interface header with status icon
|
||||||
|
let mut header_spans = vec![];
|
||||||
|
header_spans.extend(StatusIcons::create_status_spans(
|
||||||
|
interface.link_status.clone(),
|
||||||
|
&format!("{}:", interface.name)
|
||||||
|
));
|
||||||
|
lines.push(Line::from(header_spans));
|
||||||
|
|
||||||
|
// Find child interfaces for this physical interface
|
||||||
|
let mut children: Vec<_> = virtual_interfaces.iter()
|
||||||
|
.filter(|vi| {
|
||||||
|
if let Some(parent) = &vi.parent_interface {
|
||||||
|
parent == &interface.name
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// Sort children: VLANs first (by VLAN ID), then others alphabetically
|
||||||
|
children.sort_by(|a, b| {
|
||||||
|
match (a.vlan_id, b.vlan_id) {
|
||||||
|
(Some(vlan_a), Some(vlan_b)) => vlan_a.cmp(&vlan_b),
|
||||||
|
(Some(_), None) => std::cmp::Ordering::Less,
|
||||||
|
(None, Some(_)) => std::cmp::Ordering::Greater,
|
||||||
|
(None, None) => a.name.cmp(&b.name),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Count total items under this physical interface (IPs + children)
|
||||||
|
let ip_count = interface.ipv4_addresses.len() + interface.ipv6_addresses.len();
|
||||||
|
let total_children = ip_count + children.len();
|
||||||
|
let mut child_index = 0;
|
||||||
|
|
||||||
|
// IPv4 addresses on the physical interface itself
|
||||||
|
for ipv4 in &interface.ipv4_addresses {
|
||||||
|
child_index += 1;
|
||||||
|
let is_last = child_index == total_children && is_last_physical;
|
||||||
|
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||||
|
lines.push(Line::from(vec![
|
||||||
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
|
Span::styled(format!("ip: {}", ipv4), Typography::secondary()),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// IPv6 addresses on the physical interface itself
|
||||||
|
for ipv6 in &interface.ipv6_addresses {
|
||||||
|
child_index += 1;
|
||||||
|
let is_last = child_index == total_children && is_last_physical;
|
||||||
|
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||||
|
lines.push(Line::from(vec![
|
||||||
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
|
Span::styled(format!("ip: {}", ipv6), Typography::secondary()),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Child virtual interfaces (VLANs, etc.)
|
||||||
|
for child in children {
|
||||||
|
child_index += 1;
|
||||||
|
let is_last = child_index == total_children && is_last_physical;
|
||||||
|
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||||
|
|
||||||
|
let ip_text = if !child.ipv4_addresses.is_empty() {
|
||||||
|
Self::compress_ipv4_addresses(&child.ipv4_addresses)
|
||||||
|
} else if !child.ipv6_addresses.is_empty() {
|
||||||
|
child.ipv6_addresses.join(", ")
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Format: "name (vlan X): IP" or "name: IP"
|
||||||
|
let child_text = if let Some(vlan_id) = child.vlan_id {
|
||||||
|
if !ip_text.is_empty() {
|
||||||
|
format!("{} (vlan {}): {}", child.name, vlan_id, ip_text)
|
||||||
|
} else {
|
||||||
|
format!("{} (vlan {}):", child.name, vlan_id)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if !ip_text.is_empty() {
|
||||||
|
format!("{}: {}", child.name, ip_text)
|
||||||
|
} else {
|
||||||
|
format!("{}:", child.name)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
lines.push(Line::from(vec![
|
||||||
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
|
Span::styled(child_text, Typography::secondary()),
|
||||||
|
]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render standalone virtual interfaces (those without a parent)
|
||||||
|
for (virt_idx, interface) in standalone_virtual.iter().enumerate() {
|
||||||
|
let is_last = virt_idx == standalone_virtual.len() - 1;
|
||||||
|
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||||
|
|
||||||
|
// Virtual interface with IPs
|
||||||
|
let ip_text = if !interface.ipv4_addresses.is_empty() {
|
||||||
|
Self::compress_ipv4_addresses(&interface.ipv4_addresses)
|
||||||
|
} else if !interface.ipv6_addresses.is_empty() {
|
||||||
|
interface.ipv6_addresses.join(", ")
|
||||||
|
} else {
|
||||||
|
String::new()
|
||||||
|
};
|
||||||
|
|
||||||
|
// Format: "name (vlan X): IP" or "name: IP"
|
||||||
|
let interface_text = if let Some(vlan_id) = interface.vlan_id {
|
||||||
|
if !ip_text.is_empty() {
|
||||||
|
format!("{} (vlan {}): {}", interface.name, vlan_id, ip_text)
|
||||||
|
} else {
|
||||||
|
format!("{} (vlan {}):", interface.name, vlan_id)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if !ip_text.is_empty() {
|
||||||
|
format!("{}: {}", interface.name, ip_text)
|
||||||
|
} else {
|
||||||
|
format!("{}:", interface.name)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
lines.push(Line::from(vec![
|
||||||
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
|
Span::styled(interface_text, Typography::secondary()),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
|
||||||
|
lines
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Render system widget
|
/// Render system widget
|
||||||
pub fn render(&mut self, frame: &mut Frame, area: Rect, hostname: &str, config: Option<&crate::config::DashboardConfig>) {
|
pub fn render(&mut self, frame: &mut Frame, area: Rect, hostname: &str, _config: Option<&crate::config::DashboardConfig>) {
|
||||||
let mut lines = Vec::new();
|
let mut lines = Vec::new();
|
||||||
|
|
||||||
// NixOS section
|
// NixOS section
|
||||||
@@ -675,41 +813,42 @@ impl SystemWidget {
|
|||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled(format!("Agent: {}", agent_version_text), Typography::secondary())
|
Span::styled(format!("Agent: {}", agent_version_text), Typography::secondary())
|
||||||
]));
|
]));
|
||||||
|
|
||||||
// Display detected connection IP
|
// ZMQ communication stats
|
||||||
if let Some(config) = config {
|
if let (Some(packets), Some(age)) = (self.zmq_packets_received, self.zmq_last_packet_age) {
|
||||||
if let Some(host_details) = config.hosts.get(hostname) {
|
let age_text = if age < 1.0 {
|
||||||
let detected_ip = host_details.get_connection_ip(hostname);
|
format!("{:.0}ms ago", age * 1000.0)
|
||||||
lines.push(Line::from(vec![
|
} else {
|
||||||
Span::styled(format!("IP: {}", detected_ip), Typography::secondary())
|
format!("{:.1}s ago", age)
|
||||||
]));
|
};
|
||||||
}
|
lines.push(Line::from(vec![
|
||||||
|
Span::styled(format!("ZMQ: {} pkts, last {}", packets, age_text), Typography::secondary())
|
||||||
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// CPU section
|
// CPU section
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled("CPU:", Typography::widget_title())
|
Span::styled("CPU:", Typography::widget_title())
|
||||||
]));
|
]));
|
||||||
|
|
||||||
let load_text = self.format_cpu_load();
|
let load_text = self.format_cpu_load();
|
||||||
let cpu_spans = StatusIcons::create_status_spans(
|
let cpu_spans = StatusIcons::create_status_spans(
|
||||||
self.cpu_status.clone(),
|
self.cpu_status.clone(),
|
||||||
&format!("Load: {}", load_text)
|
&format!("Load: {}", load_text)
|
||||||
);
|
);
|
||||||
lines.push(Line::from(cpu_spans));
|
lines.push(Line::from(cpu_spans));
|
||||||
|
|
||||||
let freq_text = self.format_cpu_frequency();
|
let cstate_text = self.format_cpu_cstate();
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled(" └─ ", Typography::tree()),
|
Span::styled(" └─ ", Typography::tree()),
|
||||||
Span::styled(format!("Freq: {}", freq_text), Typography::secondary())
|
Span::styled(format!("C-state: {}", cstate_text), Typography::secondary())
|
||||||
]));
|
]));
|
||||||
|
|
||||||
// RAM section
|
// RAM section
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled("RAM:", Typography::widget_title())
|
Span::styled("RAM:", Typography::widget_title())
|
||||||
]));
|
]));
|
||||||
|
|
||||||
let memory_text = self.format_memory_usage();
|
let memory_text = self.format_memory_usage();
|
||||||
let memory_spans = StatusIcons::create_status_spans(
|
let memory_spans = StatusIcons::create_status_spans(
|
||||||
self.memory_status.clone(),
|
self.memory_status.clone(),
|
||||||
@@ -721,16 +860,16 @@ impl SystemWidget {
|
|||||||
for (i, tmpfs) in self.tmpfs_mounts.iter().enumerate() {
|
for (i, tmpfs) in self.tmpfs_mounts.iter().enumerate() {
|
||||||
let is_last = i == self.tmpfs_mounts.len() - 1;
|
let is_last = i == self.tmpfs_mounts.len() - 1;
|
||||||
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||||
|
|
||||||
let usage_text = if tmpfs.total_gb > 0.0 {
|
let usage_text = if tmpfs.total_gb > 0.0 {
|
||||||
format!("{:.0}% {:.1}GB/{:.1}GB",
|
format!("{:.0}% {:.1}GB/{:.1}GB",
|
||||||
tmpfs.usage_percent,
|
tmpfs.usage_percent,
|
||||||
tmpfs.used_gb,
|
tmpfs.used_gb,
|
||||||
tmpfs.total_gb)
|
tmpfs.total_gb)
|
||||||
} else {
|
} else {
|
||||||
"— —/—".to_string()
|
"— —/—".to_string()
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut tmpfs_spans = vec![
|
let mut tmpfs_spans = vec![
|
||||||
Span::styled(tree_symbol, Typography::tree()),
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
];
|
];
|
||||||
@@ -741,6 +880,16 @@ impl SystemWidget {
|
|||||||
lines.push(Line::from(tmpfs_spans));
|
lines.push(Line::from(tmpfs_spans));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Network section
|
||||||
|
if !self.network_interfaces.is_empty() {
|
||||||
|
lines.push(Line::from(vec![
|
||||||
|
Span::styled("Network:", Typography::widget_title())
|
||||||
|
]));
|
||||||
|
|
||||||
|
let network_lines = self.render_network();
|
||||||
|
lines.extend(network_lines);
|
||||||
|
}
|
||||||
|
|
||||||
// Storage section
|
// Storage section
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled("Storage:", Typography::widget_title())
|
Span::styled("Storage:", Typography::widget_title())
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.156"
|
version = "0.1.209"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -16,18 +16,44 @@ pub struct AgentData {
|
|||||||
/// System-level monitoring data
|
/// System-level monitoring data
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct SystemData {
|
pub struct SystemData {
|
||||||
|
pub network: NetworkData,
|
||||||
pub cpu: CpuData,
|
pub cpu: CpuData,
|
||||||
pub memory: MemoryData,
|
pub memory: MemoryData,
|
||||||
pub storage: StorageData,
|
pub storage: StorageData,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Network interface monitoring data
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct NetworkData {
|
||||||
|
pub interfaces: Vec<NetworkInterfaceData>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Individual network interface data
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct NetworkInterfaceData {
|
||||||
|
pub name: String,
|
||||||
|
pub ipv4_addresses: Vec<String>,
|
||||||
|
pub ipv6_addresses: Vec<String>,
|
||||||
|
pub is_physical: bool,
|
||||||
|
pub link_status: Status,
|
||||||
|
pub parent_interface: Option<String>,
|
||||||
|
pub vlan_id: Option<u16>,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// CPU C-state usage information
|
||||||
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
pub struct CStateInfo {
|
||||||
|
pub name: String,
|
||||||
|
pub percent: f32,
|
||||||
|
}
|
||||||
|
|
||||||
/// CPU monitoring data
|
/// CPU monitoring data
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct CpuData {
|
pub struct CpuData {
|
||||||
pub load_1min: f32,
|
pub load_1min: f32,
|
||||||
pub load_5min: f32,
|
pub load_5min: f32,
|
||||||
pub load_15min: f32,
|
pub load_15min: f32,
|
||||||
pub frequency_mhz: f32,
|
pub cstates: Vec<CStateInfo>, // C-state usage percentages (C1, C6, C10, etc.) - indicates CPU idle depth distribution
|
||||||
pub temperature_celsius: Option<f32>,
|
pub temperature_celsius: Option<f32>,
|
||||||
pub load_status: Status,
|
pub load_status: Status,
|
||||||
pub temperature_status: Status,
|
pub temperature_status: Status,
|
||||||
@@ -117,11 +143,15 @@ pub struct PoolDriveData {
|
|||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct ServiceData {
|
pub struct ServiceData {
|
||||||
pub name: String,
|
pub name: String,
|
||||||
pub memory_mb: f32,
|
|
||||||
pub disk_gb: f32,
|
|
||||||
pub user_stopped: bool,
|
pub user_stopped: bool,
|
||||||
pub service_status: Status,
|
pub service_status: Status,
|
||||||
pub sub_services: Vec<SubServiceData>,
|
pub sub_services: Vec<SubServiceData>,
|
||||||
|
/// Memory usage in bytes (from MemoryCurrent)
|
||||||
|
pub memory_bytes: Option<u64>,
|
||||||
|
/// Number of service restarts (from NRestarts)
|
||||||
|
pub restart_count: Option<u32>,
|
||||||
|
/// Uptime in seconds (calculated from ExecMainStartTimestamp)
|
||||||
|
pub uptime_seconds: Option<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sub-service data (nginx sites, docker containers, etc.)
|
/// Sub-service data (nginx sites, docker containers, etc.)
|
||||||
@@ -130,6 +160,9 @@ pub struct SubServiceData {
|
|||||||
pub name: String,
|
pub name: String,
|
||||||
pub service_status: Status,
|
pub service_status: Status,
|
||||||
pub metrics: Vec<SubServiceMetric>,
|
pub metrics: Vec<SubServiceMetric>,
|
||||||
|
/// Type of sub-service: "nginx_site", "container", "image"
|
||||||
|
#[serde(default)]
|
||||||
|
pub service_type: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Individual metric for a sub-service
|
/// Individual metric for a sub-service
|
||||||
@@ -171,11 +204,14 @@ impl AgentData {
|
|||||||
build_version: None,
|
build_version: None,
|
||||||
timestamp: chrono::Utc::now().timestamp() as u64,
|
timestamp: chrono::Utc::now().timestamp() as u64,
|
||||||
system: SystemData {
|
system: SystemData {
|
||||||
|
network: NetworkData {
|
||||||
|
interfaces: Vec::new(),
|
||||||
|
},
|
||||||
cpu: CpuData {
|
cpu: CpuData {
|
||||||
load_1min: 0.0,
|
load_1min: 0.0,
|
||||||
load_5min: 0.0,
|
load_5min: 0.0,
|
||||||
load_15min: 0.0,
|
load_15min: 0.0,
|
||||||
frequency_mhz: 0.0,
|
cstates: Vec::new(),
|
||||||
temperature_celsius: None,
|
temperature_celsius: None,
|
||||||
load_status: Status::Unknown,
|
load_status: Status::Unknown,
|
||||||
temperature_status: Status::Unknown,
|
temperature_status: Status::Unknown,
|
||||||
|
|||||||
Reference in New Issue
Block a user