diff --git a/Cargo.lock b/Cargo.lock index 63db345..994842e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d" [[package]] name = "cm-dashboard" -version = "0.1.168" +version = "0.1.169" dependencies = [ "anyhow", "chrono", @@ -301,7 +301,7 @@ dependencies = [ [[package]] name = "cm-dashboard-agent" -version = "0.1.168" +version = "0.1.169" dependencies = [ "anyhow", "async-trait", @@ -324,7 +324,7 @@ dependencies = [ [[package]] name = "cm-dashboard-shared" -version = "0.1.168" +version = "0.1.169" dependencies = [ "chrono", "serde", diff --git a/agent/Cargo.toml b/agent/Cargo.toml index cfad3d1..f41240f 100644 --- a/agent/Cargo.toml +++ b/agent/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-agent" -version = "0.1.168" +version = "0.1.169" edition = "2021" [dependencies] diff --git a/agent/src/collectors/network.rs b/agent/src/collectors/network.rs index 1da0d01..f35b360 100644 --- a/agent/src/collectors/network.rs +++ b/agent/src/collectors/network.rs @@ -62,11 +62,19 @@ impl NetworkCollector { for iface in ifaces { let name = iface["ifname"].as_str().unwrap_or("").to_string(); - // Skip loopback and empty names - if name.is_empty() || name == "lo" { + // 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(); @@ -90,14 +98,15 @@ impl NetworkCollector { } } - // Only add interfaces that have at least one IP address - // This filters out ifb*, dummy interfaces, etc. that have no IPs - if ipv4_addresses.is_empty() && ipv6_addresses.is_empty() { + // 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; } - // Determine if physical and get status - let is_physical = Self::is_physical_interface(&name); let link_status = if is_physical { Self::get_link_status(&name) } else { @@ -105,12 +114,12 @@ impl NetworkCollector { }; interfaces.push(NetworkInterfaceData { - name, + name: interface_name, ipv4_addresses, ipv6_addresses, is_physical, link_status, - parent_interface: None, + parent_interface, }); } } diff --git a/dashboard/Cargo.toml b/dashboard/Cargo.toml index 66e1f29..2e7f300 100644 --- a/dashboard/Cargo.toml +++ b/dashboard/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard" -version = "0.1.168" +version = "0.1.169" edition = "2021" [dependencies] diff --git a/dashboard/src/ui/widgets/system.rs b/dashboard/src/ui/widgets/system.rs index a972458..89d6d1f 100644 --- a/dashboard/src/ui/widgets/system.rs +++ b/dashboard/src/ui/widgets/system.rs @@ -628,9 +628,14 @@ impl SystemWidget { 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(); - // Render physical interfaces + // Find standalone virtual interfaces (those without a parent) + let standalone_virtual: Vec<_> = virtual_interfaces.iter() + .filter(|i| i.parent_interface.is_none()) + .collect(); + + // Render physical interfaces with their children for (phy_idx, interface) in physical.iter().enumerate() { - let is_last_physical = phy_idx == physical.len() - 1 && virtual_interfaces.is_empty(); + let is_last_physical = phy_idx == physical.len() - 1 && standalone_virtual.is_empty(); // Physical interface header with status icon let mut header_spans = vec![]; @@ -640,36 +645,74 @@ impl SystemWidget { )); lines.push(Line::from(header_spans)); - // Show IPs nested under the interface - let ip_count = interface.ipv4_addresses.len() + interface.ipv6_addresses.len(); - let mut ip_index = 0; + // Find child interfaces for this physical interface + let children: Vec<_> = virtual_interfaces.iter() + .filter(|vi| { + if let Some(parent) = &vi.parent_interface { + parent == &interface.name + } else { + false + } + }) + .collect(); - // IPv4 addresses + // 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 { - ip_index += 1; - let is_last_ip = ip_index == ip_count && is_last_physical; - let tree_symbol = if is_last_ip { " └─ " } else { " ├─ " }; + 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 + // IPv6 addresses on the physical interface itself for ipv6 in &interface.ipv6_addresses { - ip_index += 1; - let is_last_ip = ip_index == ip_count && is_last_physical; - let tree_symbol = if is_last_ip { " └─ " } else { " ├─ " }; + 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() + }; + + let child_text = 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 virtual_interfaces.iter().enumerate() { - let is_last = virt_idx == virtual_interfaces.len() - 1; + 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 diff --git a/shared/Cargo.toml b/shared/Cargo.toml index b195174..7d65ed4 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "cm-dashboard-shared" -version = "0.1.168" +version = "0.1.169" edition = "2021" [dependencies]