Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cac836601b | |||
| bd22ce265b | |||
| bbc8b7b1cb | |||
| 5dd8cadef3 | |||
| fefe30ec51 | |||
| fb40cce748 | |||
| eaa057b284 | |||
| f23a1b5cec | |||
| 3f98f68b51 | |||
| 3d38a7a984 | |||
| b0ee0242bd | |||
| 8f9e9eabca | |||
| 937f4ad427 | |||
| 8aefab83ae | |||
| 748a9f3a3b | |||
| 5c6b11c794 | |||
| 9f0aa5f806 |
@@ -304,6 +304,12 @@ 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
|
||||||
|
|||||||
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.165"
|
version = "0.1.181"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -301,7 +301,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.165"
|
version = "0.1.181"
|
||||||
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.165"
|
version = "0.1.181"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.165"
|
version = "0.1.182"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -386,7 +386,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 {
|
||||||
@@ -413,23 +413,24 @@ 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 direct smartctl (no sudo) - service has CAP_SYS_RAWIO capability
|
||||||
.args(&["smartctl", "-a", &format!("/dev/{}", drive_name)])
|
// For NVMe drives, specify device type explicitly
|
||||||
.output()
|
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 = cmd.output()
|
||||||
.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(),
|
||||||
|
|||||||
@@ -49,10 +49,67 @@ impl NetworkCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get the primary physical interface (the one with default route)
|
||||||
|
fn get_primary_physical_interface() -> Option<String> {
|
||||||
|
match Command::new("ip").args(["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
|
/// Collect network interfaces using ip command
|
||||||
async fn collect_interfaces(&self) -> Vec<NetworkInterfaceData> {
|
async fn collect_interfaces(&self) -> Vec<NetworkInterfaceData> {
|
||||||
let mut interfaces = Vec::new();
|
let mut interfaces = Vec::new();
|
||||||
|
|
||||||
|
// Parse VLAN configuration
|
||||||
|
let vlan_map = Self::parse_vlan_config();
|
||||||
|
|
||||||
match Command::new("ip").args(["-j", "addr"]).output() {
|
match Command::new("ip").args(["-j", "addr"]).output() {
|
||||||
Ok(output) if output.status.success() => {
|
Ok(output) if output.status.success() => {
|
||||||
let json_str = String::from_utf8_lossy(&output.stdout);
|
let json_str = String::from_utf8_lossy(&output.stdout);
|
||||||
@@ -62,11 +119,19 @@ impl NetworkCollector {
|
|||||||
for iface in ifaces {
|
for iface in ifaces {
|
||||||
let name = iface["ifname"].as_str().unwrap_or("").to_string();
|
let name = iface["ifname"].as_str().unwrap_or("").to_string();
|
||||||
|
|
||||||
// Skip loopback and empty names
|
// Skip loopback, empty names, and ifb* interfaces
|
||||||
if name.is_empty() || name == "lo" {
|
if name.is_empty() || name == "lo" || name.starts_with("ifb") {
|
||||||
continue;
|
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 ipv4_addresses = Vec::new();
|
||||||
let mut ipv6_addresses = Vec::new();
|
let mut ipv6_addresses = Vec::new();
|
||||||
|
|
||||||
@@ -91,20 +156,31 @@ impl NetworkCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Determine if physical and get status
|
// Determine if physical and get status
|
||||||
let is_physical = Self::is_physical_interface(&name);
|
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 {
|
let link_status = if is_physical {
|
||||||
Self::get_link_status(&name)
|
Self::get_link_status(&name)
|
||||||
} else {
|
} else {
|
||||||
Status::Unknown // Virtual interfaces don't have meaningful link status
|
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 {
|
interfaces.push(NetworkInterfaceData {
|
||||||
name,
|
name: interface_name,
|
||||||
ipv4_addresses,
|
ipv4_addresses,
|
||||||
ipv6_addresses,
|
ipv6_addresses,
|
||||||
is_physical,
|
is_physical,
|
||||||
link_status,
|
link_status,
|
||||||
parent_interface: None, // TODO: Implement virtual interface parent detection
|
parent_interface,
|
||||||
|
vlan_id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -118,6 +194,17 @@ impl NetworkCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 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
|
interfaces
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,13 +123,30 @@ impl SystemdCollector {
|
|||||||
// 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,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add Docker images
|
||||||
|
let docker_images = self.get_docker_images();
|
||||||
|
for (image_name, image_status, image_size) in docker_images {
|
||||||
|
let mut metrics = Vec::new();
|
||||||
|
metrics.push(SubServiceMetric {
|
||||||
|
label: "size".to_string(),
|
||||||
|
value: 0.0, // Size as string in name instead
|
||||||
|
unit: None,
|
||||||
|
});
|
||||||
|
|
||||||
|
sub_services.push(SubServiceData {
|
||||||
|
name: format!("{} ({})", image_name, image_size),
|
||||||
|
service_status: self.calculate_service_status(&image_name, &image_status),
|
||||||
|
metrics,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create complete service data
|
// Create complete service data
|
||||||
@@ -151,7 +168,7 @@ impl SystemdCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update cached state
|
// Update cached state
|
||||||
{
|
{
|
||||||
let mut state = self.state.write().unwrap();
|
let mut state = self.state.write().unwrap();
|
||||||
@@ -756,9 +773,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 (use sudo for permissions)
|
// Check if docker is available (cm-agent user is in docker group)
|
||||||
let output = Command::new("sudo")
|
// Use -a to show ALL containers (running and stopped)
|
||||||
.args(&["docker", "ps", "--format", "{{.Names}},{{.Status}}"])
|
let output = Command::new("docker")
|
||||||
|
.args(&["ps", "-a", "--format", "{{.Names}},{{.Status}}"])
|
||||||
.output();
|
.output();
|
||||||
|
|
||||||
let output = match output {
|
let output = match output {
|
||||||
@@ -783,10 +801,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()));
|
||||||
@@ -795,6 +813,55 @@ impl SystemdCollector {
|
|||||||
|
|
||||||
containers
|
containers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Get docker images as sub-services
|
||||||
|
fn get_docker_images(&self) -> Vec<(String, String, String)> {
|
||||||
|
let mut images = Vec::new();
|
||||||
|
// Check if docker is available (cm-agent user is in docker group)
|
||||||
|
let output = Command::new("docker")
|
||||||
|
.args(&["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 = parts[1].trim();
|
||||||
|
|
||||||
|
// Skip <none>:<none> images (dangling images)
|
||||||
|
if image_name.contains("<none>") {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
images.push((
|
||||||
|
format!("image_{}", image_name),
|
||||||
|
"active".to_string(), // Images are always "active" (present)
|
||||||
|
size.to_string()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
images
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.165"
|
version = "0.1.182"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -628,60 +628,146 @@ impl SystemWidget {
|
|||||||
let physical: Vec<_> = self.network_interfaces.iter().filter(|i| i.is_physical).collect();
|
let physical: Vec<_> = self.network_interfaces.iter().filter(|i| i.is_physical).collect();
|
||||||
let virtual_interfaces: Vec<_> = self.network_interfaces.iter().filter(|i| !i.is_physical).collect();
|
let virtual_interfaces: Vec<_> = self.network_interfaces.iter().filter(|i| !i.is_physical).collect();
|
||||||
|
|
||||||
// Render physical interfaces first
|
// Find standalone virtual interfaces (those without a parent)
|
||||||
for (i, interface) in physical.iter().enumerate() {
|
let mut standalone_virtual: Vec<_> = virtual_interfaces.iter()
|
||||||
let is_last = i == physical.len() - 1 && virtual_interfaces.is_empty();
|
.filter(|i| i.parent_interface.is_none())
|
||||||
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
.collect();
|
||||||
|
|
||||||
// Show interface name with IPs
|
// Sort standalone virtual: VLANs first (by VLAN ID), then others alphabetically
|
||||||
let mut interface_text = format!("{}: ", interface.name);
|
standalone_virtual.sort_by(|a, b| {
|
||||||
|
match (a.vlan_id, b.vlan_id) {
|
||||||
// Add compressed IPv4 addresses
|
(Some(vlan_a), Some(vlan_b)) => vlan_a.cmp(&vlan_b),
|
||||||
if !interface.ipv4_addresses.is_empty() {
|
(Some(_), None) => std::cmp::Ordering::Less,
|
||||||
interface_text.push_str(&Self::compress_ipv4_addresses(&interface.ipv4_addresses));
|
(None, Some(_)) => std::cmp::Ordering::Greater,
|
||||||
|
(None, None) => a.name.cmp(&b.name),
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Add IPv6 addresses (no compression for now)
|
// Render physical interfaces with their children
|
||||||
if !interface.ipv6_addresses.is_empty() {
|
for (phy_idx, interface) in physical.iter().enumerate() {
|
||||||
if !interface.ipv4_addresses.is_empty() {
|
let is_last_physical = phy_idx == physical.len() - 1 && standalone_virtual.is_empty();
|
||||||
interface_text.push_str(", ");
|
|
||||||
}
|
|
||||||
interface_text.push_str(&interface.ipv6_addresses.join(", "));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Physical interfaces show status icon
|
// Physical interface header with status icon
|
||||||
let mut spans = vec![
|
let mut header_spans = vec![];
|
||||||
Span::styled(tree_symbol, Typography::tree()),
|
header_spans.extend(StatusIcons::create_status_spans(
|
||||||
];
|
|
||||||
spans.extend(StatusIcons::create_status_spans(
|
|
||||||
interface.link_status.clone(),
|
interface.link_status.clone(),
|
||||||
&interface_text
|
&format!("{}:", interface.name)
|
||||||
));
|
));
|
||||||
lines.push(Line::from(spans));
|
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 virtual interfaces
|
// Render standalone virtual interfaces (those without a parent)
|
||||||
for (i, interface) in virtual_interfaces.iter().enumerate() {
|
for (virt_idx, interface) in standalone_virtual.iter().enumerate() {
|
||||||
let is_last = i == virtual_interfaces.len() - 1;
|
let is_last = virt_idx == standalone_virtual.len() - 1;
|
||||||
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||||
|
|
||||||
// Show interface name with IPs
|
// Virtual interface with IPs
|
||||||
let mut interface_text = format!("{}: ", interface.name);
|
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()
|
||||||
|
};
|
||||||
|
|
||||||
// Add compressed IPv4 addresses
|
// Format: "name (vlan X): IP" or "name: IP"
|
||||||
if !interface.ipv4_addresses.is_empty() {
|
let interface_text = if let Some(vlan_id) = interface.vlan_id {
|
||||||
interface_text.push_str(&Self::compress_ipv4_addresses(&interface.ipv4_addresses));
|
if !ip_text.is_empty() {
|
||||||
}
|
format!("{} (vlan {}): {}", interface.name, vlan_id, ip_text)
|
||||||
|
} else {
|
||||||
// Add IPv6 addresses (no compression for now)
|
format!("{} (vlan {}):", interface.name, vlan_id)
|
||||||
if !interface.ipv6_addresses.is_empty() {
|
|
||||||
if !interface.ipv4_addresses.is_empty() {
|
|
||||||
interface_text.push_str(", ");
|
|
||||||
}
|
}
|
||||||
interface_text.push_str(&interface.ipv6_addresses.join(", "));
|
} else {
|
||||||
}
|
if !ip_text.is_empty() {
|
||||||
|
format!("{}: {}", interface.name, ip_text)
|
||||||
|
} else {
|
||||||
|
format!("{}:", interface.name)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Virtual interfaces don't show status icon
|
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled(tree_symbol, Typography::tree()),
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
Span::styled(interface_text, Typography::secondary()),
|
Span::styled(interface_text, Typography::secondary()),
|
||||||
@@ -710,28 +796,18 @@ impl SystemWidget {
|
|||||||
Span::styled(format!("Agent: {}", agent_version_text), Typography::secondary())
|
Span::styled(format!("Agent: {}", agent_version_text), Typography::secondary())
|
||||||
]));
|
]));
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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 freq_text = self.format_cpu_frequency();
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled(" └─ ", Typography::tree()),
|
Span::styled(" └─ ", Typography::tree()),
|
||||||
@@ -742,7 +818,7 @@ impl SystemWidget {
|
|||||||
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(),
|
||||||
@@ -754,16 +830,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()),
|
||||||
];
|
];
|
||||||
@@ -774,6 +850,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.165"
|
version = "0.1.182"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ pub struct NetworkInterfaceData {
|
|||||||
pub is_physical: bool,
|
pub is_physical: bool,
|
||||||
pub link_status: Status,
|
pub link_status: Status,
|
||||||
pub parent_interface: Option<String>,
|
pub parent_interface: Option<String>,
|
||||||
|
pub vlan_id: Option<u16>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// CPU monitoring data
|
/// CPU monitoring data
|
||||||
|
|||||||
Reference in New Issue
Block a user