Remove hardcoded defaults and migrate dashboard config to NixOS
- Remove all unused configuration options from dashboard config module - Eliminate hardcoded defaults - dashboard now requires config file like agent - Keep only actually used config: zmq.subscriber_ports and hosts.predefined_hosts - Remove unused get_host_metrics function from metric store - Clean up missing module imports (hosts, utils) - Make dashboard fail fast if no configuration provided - Align dashboard config approach with agent configuration pattern
This commit is contained in:
parent
a6d2a2f086
commit
3d2b37b26c
@ -11,7 +11,6 @@ mod config;
|
|||||||
mod metrics;
|
mod metrics;
|
||||||
mod notifications;
|
mod notifications;
|
||||||
mod status;
|
mod status;
|
||||||
mod utils;
|
|
||||||
|
|
||||||
use agent::Agent;
|
use agent::Agent;
|
||||||
|
|
||||||
|
|||||||
@ -28,11 +28,14 @@ impl Dashboard {
|
|||||||
pub async fn new(config_path: Option<String>, headless: bool) -> Result<Self> {
|
pub async fn new(config_path: Option<String>, headless: bool) -> Result<Self> {
|
||||||
info!("Initializing dashboard");
|
info!("Initializing dashboard");
|
||||||
|
|
||||||
// Load configuration
|
// Load configuration - config file is required
|
||||||
let config = if let Some(path) = config_path {
|
let config = match config_path {
|
||||||
DashboardConfig::load_from_file(&path)?
|
Some(path) => DashboardConfig::load_from_file(&path)?,
|
||||||
} else {
|
None => {
|
||||||
DashboardConfig::default()
|
error!("Configuration file is required. Use --config to specify path.");
|
||||||
|
error!("Dashboard configuration must be provided - no hardcoded defaults allowed.");
|
||||||
|
return Err(anyhow::anyhow!("Missing required configuration file"));
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Initialize ZMQ consumer
|
// Initialize ZMQ consumer
|
||||||
|
|||||||
@ -6,58 +6,19 @@ use std::path::Path;
|
|||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct DashboardConfig {
|
pub struct DashboardConfig {
|
||||||
pub zmq: ZmqConfig,
|
pub zmq: ZmqConfig,
|
||||||
pub ui: UiConfig,
|
|
||||||
pub hosts: HostsConfig,
|
pub hosts: HostsConfig,
|
||||||
pub metrics: MetricsConfig,
|
|
||||||
pub widgets: WidgetsConfig,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// ZMQ consumer configuration
|
/// ZMQ consumer configuration
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct ZmqConfig {
|
pub struct ZmqConfig {
|
||||||
pub subscriber_ports: Vec<u16>,
|
pub subscriber_ports: Vec<u16>,
|
||||||
pub connection_timeout_ms: u64,
|
|
||||||
pub reconnect_interval_ms: u64,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// UI configuration
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct UiConfig {
|
|
||||||
pub refresh_rate_ms: u64,
|
|
||||||
pub theme: String,
|
|
||||||
pub preserve_layout: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Hosts configuration
|
/// Hosts configuration
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub struct HostsConfig {
|
pub struct HostsConfig {
|
||||||
pub auto_discovery: bool,
|
|
||||||
pub predefined_hosts: Vec<String>,
|
pub predefined_hosts: Vec<String>,
|
||||||
pub default_host: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Metrics configuration
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct MetricsConfig {
|
|
||||||
pub history_retention_hours: u64,
|
|
||||||
pub max_metrics_per_host: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Widget configuration
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct WidgetsConfig {
|
|
||||||
pub cpu: WidgetConfig,
|
|
||||||
pub memory: WidgetConfig,
|
|
||||||
pub storage: WidgetConfig,
|
|
||||||
pub services: WidgetConfig,
|
|
||||||
pub backup: WidgetConfig,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Individual widget configuration
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
|
||||||
pub struct WidgetConfig {
|
|
||||||
pub enabled: bool,
|
|
||||||
pub metrics: Vec<String>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DashboardConfig {
|
impl DashboardConfig {
|
||||||
@ -71,104 +32,18 @@ impl DashboardConfig {
|
|||||||
|
|
||||||
impl Default for DashboardConfig {
|
impl Default for DashboardConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
panic!("Dashboard configuration must be loaded from file - no hardcoded defaults allowed")
|
||||||
zmq: ZmqConfig::default(),
|
|
||||||
ui: UiConfig::default(),
|
|
||||||
hosts: HostsConfig::default(),
|
|
||||||
metrics: MetricsConfig::default(),
|
|
||||||
widgets: WidgetsConfig::default(),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for ZmqConfig {
|
impl Default for ZmqConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
panic!("Dashboard configuration must be loaded from file - no hardcoded defaults allowed")
|
||||||
subscriber_ports: vec![6130],
|
|
||||||
connection_timeout_ms: 15000,
|
|
||||||
reconnect_interval_ms: 5000,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for UiConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
refresh_rate_ms: 100,
|
|
||||||
theme: "default".to_string(),
|
|
||||||
preserve_layout: true,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for HostsConfig {
|
impl Default for HostsConfig {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
panic!("Dashboard configuration must be loaded from file - no hardcoded defaults allowed")
|
||||||
auto_discovery: true,
|
|
||||||
predefined_hosts: vec![
|
|
||||||
"cmbox".to_string(),
|
|
||||||
"labbox".to_string(),
|
|
||||||
"simonbox".to_string(),
|
|
||||||
"steambox".to_string(),
|
|
||||||
"srv01".to_string(),
|
|
||||||
"srv02".to_string(),
|
|
||||||
],
|
|
||||||
default_host: Some("cmbox".to_string()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for MetricsConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
history_retention_hours: 24,
|
|
||||||
max_metrics_per_host: 10000,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Default for WidgetsConfig {
|
|
||||||
fn default() -> Self {
|
|
||||||
Self {
|
|
||||||
cpu: WidgetConfig {
|
|
||||||
enabled: true,
|
|
||||||
metrics: vec![
|
|
||||||
"cpu_load_1min".to_string(),
|
|
||||||
"cpu_load_5min".to_string(),
|
|
||||||
"cpu_load_15min".to_string(),
|
|
||||||
"cpu_temperature_celsius".to_string(),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
memory: WidgetConfig {
|
|
||||||
enabled: true,
|
|
||||||
metrics: vec![
|
|
||||||
"memory_usage_percent".to_string(),
|
|
||||||
"memory_total_gb".to_string(),
|
|
||||||
"memory_available_gb".to_string(),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
storage: WidgetConfig {
|
|
||||||
enabled: true,
|
|
||||||
metrics: vec![
|
|
||||||
"disk_nvme0_temperature_celsius".to_string(),
|
|
||||||
"disk_nvme0_wear_percent".to_string(),
|
|
||||||
"disk_nvme0_usage_percent".to_string(),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
services: WidgetConfig {
|
|
||||||
enabled: true,
|
|
||||||
metrics: vec![
|
|
||||||
"service_ssh_status".to_string(),
|
|
||||||
"service_ssh_memory_mb".to_string(),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
backup: WidgetConfig {
|
|
||||||
enabled: true,
|
|
||||||
metrics: vec![
|
|
||||||
"backup_status".to_string(),
|
|
||||||
"backup_last_run_timestamp".to_string(),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,10 +6,8 @@ use tracing_subscriber::EnvFilter;
|
|||||||
mod app;
|
mod app;
|
||||||
mod communication;
|
mod communication;
|
||||||
mod config;
|
mod config;
|
||||||
mod hosts;
|
|
||||||
mod metrics;
|
mod metrics;
|
||||||
mod ui;
|
mod ui;
|
||||||
mod utils;
|
|
||||||
|
|
||||||
use app::Dashboard;
|
use app::Dashboard;
|
||||||
|
|
||||||
@ -22,7 +20,7 @@ struct Cli {
|
|||||||
#[arg(short, long, action = clap::ArgAction::Count)]
|
#[arg(short, long, action = clap::ArgAction::Count)]
|
||||||
verbose: u8,
|
verbose: u8,
|
||||||
|
|
||||||
/// Configuration file path
|
/// Configuration file path (required)
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
config: Option<String>,
|
config: Option<String>,
|
||||||
|
|
||||||
|
|||||||
@ -78,11 +78,6 @@ impl MetricStore {
|
|||||||
self.current_metrics.get(hostname)?.get(metric_name)
|
self.current_metrics.get(hostname)?.get(metric_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get all current metrics for a host
|
|
||||||
#[allow(dead_code)]
|
|
||||||
pub fn get_host_metrics(&self, hostname: &str) -> Option<&HashMap<String, Metric>> {
|
|
||||||
self.current_metrics.get(hostname)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get all current metrics for a host as a vector
|
/// Get all current metrics for a host as a vector
|
||||||
pub fn get_metrics_for_host(&self, hostname: &str) -> Vec<&Metric> {
|
pub fn get_metrics_for_host(&self, hostname: &str) -> Vec<&Metric> {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user