cm-dashboard/agent/src/config/validation.rs
Christoffer Martinsson 8a36472a3d Implement real-time process monitoring and fix UI hardcoded data
This commit addresses several key issues identified during development:

Major Changes:
- Replace hardcoded top CPU/RAM process display with real system data
- Add intelligent process monitoring to CpuCollector using ps command
- Fix disk metrics permission issues in systemd collector
- Optimize service collection to focus on status, memory, and disk only
- Update dashboard widgets to display live process information

Process Monitoring Implementation:
- Added collect_top_cpu_process() and collect_top_ram_process() methods
- Implemented ps-based monitoring with accurate CPU percentages
- Added filtering to prevent self-monitoring artifacts (ps commands)
- Enhanced error handling and validation for process data
- Dashboard now shows realistic values like "claude (PID 2974) 11.0%"

Service Collection Optimization:
- Removed CPU monitoring from systemd collector for efficiency
- Enhanced service directory permission error logging
- Simplified services widget to show essential metrics only
- Fixed service-to-directory mapping accuracy

UI and Dashboard Improvements:
- Reorganized dashboard layout with btop-inspired multi-panel design
- Updated system panel to include real top CPU/RAM process display
- Enhanced widget formatting and data presentation
- Removed placeholder/hardcoded data throughout the interface

Technical Details:
- Updated agent/src/collectors/cpu.rs with process monitoring
- Modified dashboard/src/ui/mod.rs for real-time process display
- Enhanced systemd collector error handling and disk metrics
- Updated CLAUDE.md documentation with implementation details
2025-10-16 23:55:05 +02:00

114 lines
4.0 KiB
Rust

use anyhow::{bail, Result};
use crate::config::AgentConfig;
pub fn validate_config(config: &AgentConfig) -> Result<()> {
// Validate ZMQ configuration
if config.zmq.publisher_port == 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() {
bail!("ZMQ bind address cannot be empty");
}
if config.zmq.timeout_ms == 0 {
bail!("ZMQ timeout cannot be 0");
}
// Validate collection interval
if config.collection_interval_seconds == 0 {
bail!("Collection interval cannot be 0");
}
// Validate CPU thresholds
if config.collectors.cpu.enabled {
if config.collectors.cpu.load_warning_threshold <= 0.0 {
bail!("CPU load warning threshold must be positive");
}
if config.collectors.cpu.load_critical_threshold <= config.collectors.cpu.load_warning_threshold {
bail!("CPU load critical threshold must be greater than warning threshold");
}
if config.collectors.cpu.temperature_warning_threshold <= 0.0 {
bail!("CPU temperature warning threshold must be positive");
}
if config.collectors.cpu.temperature_critical_threshold <= config.collectors.cpu.temperature_warning_threshold {
bail!("CPU temperature critical threshold must be greater than warning threshold");
}
}
// Validate memory thresholds
if config.collectors.memory.enabled {
if config.collectors.memory.usage_warning_percent <= 0.0 || config.collectors.memory.usage_warning_percent > 100.0 {
bail!("Memory usage warning threshold must be between 0 and 100");
}
if config.collectors.memory.usage_critical_percent <= config.collectors.memory.usage_warning_percent
|| config.collectors.memory.usage_critical_percent > 100.0 {
bail!("Memory usage critical threshold must be between warning threshold and 100");
}
}
// Validate disk thresholds
if config.collectors.disk.enabled {
if config.collectors.disk.usage_warning_percent <= 0.0 || config.collectors.disk.usage_warning_percent > 100.0 {
bail!("Disk usage warning threshold must be between 0 and 100");
}
if config.collectors.disk.usage_critical_percent <= config.collectors.disk.usage_warning_percent
|| config.collectors.disk.usage_critical_percent > 100.0 {
bail!("Disk usage critical threshold must be between warning threshold and 100");
}
}
// Validate SMTP configuration
if config.notifications.enabled {
if config.notifications.smtp_host.is_empty() {
bail!("SMTP host cannot be empty when notifications are enabled");
}
if config.notifications.smtp_port == 0 {
bail!("SMTP port cannot be 0");
}
if config.notifications.from_email.is_empty() {
bail!("From email cannot be empty when notifications are enabled");
}
if config.notifications.to_email.is_empty() {
bail!("To email cannot be empty when notifications are enabled");
}
// Basic email validation
if !config.notifications.from_email.contains('@') {
bail!("From email must contain @ symbol");
}
if !config.notifications.to_email.contains('@') {
bail!("To email must contain @ symbol");
}
}
// Validate cache configuration
if config.cache.enabled {
if config.cache.default_ttl_seconds == 0 {
bail!("Cache TTL cannot be 0");
}
if config.cache.max_entries == 0 {
bail!("Cache max entries cannot be 0");
}
}
Ok(())
}