Implement UUID-based disk detection for CMTEC infrastructure

Replace df-based auto-discovery with UUID-based detection using NixOS
hardware configuration data. Each host now has predefined filesystem
configurations with predictable metric names.

- Add FilesystemConfig struct with UUID, mount point, and filesystem type
- Remove auto_discover and devices fields from DiskConfig
- Add host-specific UUID defaults for cmbox, srv01, srv02, simonbox, steambox
- Remove legacy get_mounted_disks() df-based detection method
- Update DiskCollector to use UUID resolution via /dev/disk/by-uuid/
- Generate predictable metric names: disk_root_*, disk_boot_*, etc.
- Maintain fallback for labbox/wslbox (no UUIDs configured yet)

Provides consistent metric names across reboots and reliable detection
aligned with NixOS deployments without dependency on mount order.
This commit is contained in:
2025-10-20 09:50:10 +02:00
parent f67779be9d
commit e7200fb1b0
3 changed files with 519 additions and 284 deletions

View File

@@ -1,5 +1,6 @@
use anyhow::Result;
use cm_dashboard_shared::CacheConfig;
use gethostname::gethostname;
use serde::{Deserialize, Serialize};
use std::path::Path;
@@ -69,8 +70,17 @@ pub struct DiskConfig {
pub interval_seconds: u64,
pub usage_warning_percent: f32,
pub usage_critical_percent: f32,
pub auto_discover: bool,
pub devices: Vec<String>,
pub filesystems: Vec<FilesystemConfig>,
}
/// Filesystem configuration entry
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FilesystemConfig {
pub name: String, // Human-readable name (e.g., "root", "boot", "home")
pub uuid: String, // UUID for /dev/disk/by-uuid/ resolution
pub mount_point: String, // Expected mount point (e.g., "/", "/boot")
pub fs_type: String, // Filesystem type (e.g., "ext4", "vfat")
pub monitor: bool, // Whether to monitor this filesystem
}
/// Process collector configuration
@@ -121,7 +131,6 @@ pub struct NetworkConfig {
pub auto_discover: bool,
}
/// Notification configuration
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NotificationConfig {
@@ -137,7 +146,7 @@ impl AgentConfig {
pub fn load_from_file<P: AsRef<Path>>(path: P) -> Result<Self> {
loader::load_config(path)
}
pub fn validate(&self) -> Result<()> {
validation::validate_config(self)
}
@@ -208,13 +217,130 @@ impl Default for MemoryConfig {
impl Default for DiskConfig {
fn default() -> Self {
let hostname = gethostname::gethostname().to_string_lossy().to_string();
let filesystems = get_default_filesystems_for_host(&hostname);
Self {
enabled: true,
interval_seconds: DEFAULT_DISK_INTERVAL_SECONDS,
usage_warning_percent: DEFAULT_DISK_WARNING_PERCENT,
usage_critical_percent: DEFAULT_DISK_CRITICAL_PERCENT,
auto_discover: true,
devices: Vec::new(),
filesystems,
}
}
}
/// Get default filesystem configurations for known CMTEC hosts
fn get_default_filesystems_for_host(hostname: &str) -> Vec<FilesystemConfig> {
match hostname {
"cmbox" => vec![
FilesystemConfig {
name: "root".to_string(),
uuid: "4cade5ce-85a5-4a03-83c8-dfd1d3888d79".to_string(),
mount_point: "/".to_string(),
fs_type: "ext4".to_string(),
monitor: true,
},
FilesystemConfig {
name: "boot".to_string(),
uuid: "AB4D-62EC".to_string(),
mount_point: "/boot".to_string(),
fs_type: "vfat".to_string(),
monitor: true,
},
],
"srv02" => vec![
FilesystemConfig {
name: "root".to_string(),
uuid: "5a880608-c79f-458f-a031-30206aa27ca7".to_string(),
mount_point: "/".to_string(),
fs_type: "ext4".to_string(),
monitor: true,
},
FilesystemConfig {
name: "boot".to_string(),
uuid: "6B2E-2AD9".to_string(),
mount_point: "/boot".to_string(),
fs_type: "vfat".to_string(),
monitor: true,
},
],
"simonbox" => vec![
FilesystemConfig {
name: "root".to_string(),
uuid: "b74284a9-2899-4f71-bdb0-fd07dc4baab3".to_string(),
mount_point: "/".to_string(),
fs_type: "ext4".to_string(),
monitor: true,
},
FilesystemConfig {
name: "boot".to_string(),
uuid: "F6A3-AD2B".to_string(),
mount_point: "/boot".to_string(),
fs_type: "vfat".to_string(),
monitor: true,
},
FilesystemConfig {
name: "steampool_1".to_string(),
uuid: "09300cb7-0938-4dba-8a42-7a7aaf60db51".to_string(),
mount_point: "/steampool_1".to_string(),
fs_type: "ext4".to_string(),
monitor: true,
},
FilesystemConfig {
name: "steampool_2".to_string(),
uuid: "a2d61a41-3f2a-4760-b62e-5eb8caf50d1a".to_string(),
mount_point: "/steampool_2".to_string(),
fs_type: "ext4".to_string(),
monitor: true,
},
],
"steambox" => vec![
FilesystemConfig {
name: "root".to_string(),
uuid: "4514ca9f-2d0a-40df-b14b-e342f39c3e6a".to_string(),
mount_point: "/".to_string(),
fs_type: "ext4".to_string(),
monitor: true,
},
FilesystemConfig {
name: "boot".to_string(),
uuid: "8FD2-1B13".to_string(),
mount_point: "/boot".to_string(),
fs_type: "vfat".to_string(),
monitor: true,
},
FilesystemConfig {
name: "steampool".to_string(),
uuid: "0ebe8abb-bbe7-4224-947b-86bf38981f60".to_string(),
mount_point: "/mnt/steampool".to_string(),
fs_type: "ext4".to_string(),
monitor: true,
},
],
"srv01" => vec![
FilesystemConfig {
name: "root".to_string(),
uuid: "cd98df34-03a3-4d68-8338-d90d2920f9f8".to_string(),
mount_point: "/".to_string(),
fs_type: "ext4".to_string(),
monitor: true,
},
FilesystemConfig {
name: "boot".to_string(),
uuid: "13E1-4DDE".to_string(),
mount_point: "/boot".to_string(),
fs_type: "vfat".to_string(),
monitor: true,
},
],
// labbox and wslbox have no UUIDs configured yet
"labbox" | "wslbox" => {
Vec::new()
},
_ => {
// Unknown hosts use auto-discovery
Vec::new()
}
}
}
@@ -277,7 +403,6 @@ impl Default for NetworkConfig {
}
}
impl Default for NotificationConfig {
fn default() -> Self {
Self {
@@ -289,4 +414,4 @@ impl Default for NotificationConfig {
rate_limit_minutes: DEFAULT_NOTIFICATION_RATE_LIMIT_MINUTES,
}
}
}
}