Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3d38a7a984 | |||
| b0ee0242bd | |||
| 8f9e9eabca | |||
| 937f4ad427 | |||
| 8aefab83ae |
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.168"
|
version = "0.1.173"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -301,7 +301,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.168"
|
version = "0.1.173"
|
||||||
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.168"
|
version = "0.1.173"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.168"
|
version = "0.1.173"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|
||||||
@@ -90,27 +155,32 @@ impl NetworkCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only add interfaces that have at least one IP address
|
// Determine if physical and get status
|
||||||
// This filters out ifb*, dummy interfaces, etc. that have no IPs
|
let is_physical = Self::is_physical_interface(&interface_name);
|
||||||
if ipv4_addresses.is_empty() && ipv6_addresses.is_empty() {
|
|
||||||
|
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine if physical and get status
|
|
||||||
let is_physical = Self::is_physical_interface(&name);
|
|
||||||
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,
|
parent_interface,
|
||||||
|
vlan_id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -124,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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -757,8 +757,9 @@ impl SystemdCollector {
|
|||||||
let mut containers = Vec::new();
|
let mut containers = Vec::new();
|
||||||
|
|
||||||
// Check if docker is available (use sudo for permissions)
|
// Check if docker is available (use sudo for permissions)
|
||||||
|
// Use -a to show ALL containers (running and stopped)
|
||||||
let output = Command::new("sudo")
|
let output = Command::new("sudo")
|
||||||
.args(&["docker", "ps", "--format", "{{.Names}},{{.Status}}"])
|
.args(&["docker", "ps", "-a", "--format", "{{.Names}},{{.Status}}"])
|
||||||
.output();
|
.output();
|
||||||
|
|
||||||
let output = match output {
|
let output = match output {
|
||||||
@@ -783,10 +784,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()));
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.168"
|
version = "0.1.173"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -628,9 +628,24 @@ 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
|
// Find standalone virtual interfaces (those without a parent)
|
||||||
|
let mut standalone_virtual: Vec<_> = virtual_interfaces.iter()
|
||||||
|
.filter(|i| i.parent_interface.is_none())
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
// Sort standalone virtual: VLANs first (by VLAN ID), then others alphabetically
|
||||||
|
standalone_virtual.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),
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Render physical interfaces with their children
|
||||||
for (phy_idx, interface) in physical.iter().enumerate() {
|
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
|
// Physical interface header with status icon
|
||||||
let mut header_spans = vec![];
|
let mut header_spans = vec![];
|
||||||
@@ -640,36 +655,93 @@ impl SystemWidget {
|
|||||||
));
|
));
|
||||||
lines.push(Line::from(header_spans));
|
lines.push(Line::from(header_spans));
|
||||||
|
|
||||||
// Show IPs nested under the interface
|
// Find child interfaces for this physical interface
|
||||||
let ip_count = interface.ipv4_addresses.len() + interface.ipv6_addresses.len();
|
let mut children: Vec<_> = virtual_interfaces.iter()
|
||||||
let mut ip_index = 0;
|
.filter(|vi| {
|
||||||
|
if let Some(parent) = &vi.parent_interface {
|
||||||
|
parent == &interface.name
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
// IPv4 addresses
|
// 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 {
|
for ipv4 in &interface.ipv4_addresses {
|
||||||
ip_index += 1;
|
child_index += 1;
|
||||||
let is_last_ip = ip_index == ip_count && is_last_physical;
|
let is_last = child_index == total_children && is_last_physical;
|
||||||
let tree_symbol = if is_last_ip { " └─ " } else { " ├─ " };
|
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled(tree_symbol, Typography::tree()),
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
Span::styled(format!("ip: {}", ipv4), Typography::secondary()),
|
Span::styled(format!("ip: {}", ipv4), Typography::secondary()),
|
||||||
]));
|
]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// IPv6 addresses
|
// IPv6 addresses on the physical interface itself
|
||||||
for ipv6 in &interface.ipv6_addresses {
|
for ipv6 in &interface.ipv6_addresses {
|
||||||
ip_index += 1;
|
child_index += 1;
|
||||||
let is_last_ip = ip_index == ip_count && is_last_physical;
|
let is_last = child_index == total_children && is_last_physical;
|
||||||
let tree_symbol = if is_last_ip { " └─ " } else { " ├─ " };
|
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled(tree_symbol, Typography::tree()),
|
Span::styled(tree_symbol, Typography::tree()),
|
||||||
Span::styled(format!("ip: {}", ipv6), Typography::secondary()),
|
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 standalone virtual interfaces (those without a parent)
|
// Render standalone virtual interfaces (those without a parent)
|
||||||
for (virt_idx, interface) in virtual_interfaces.iter().enumerate() {
|
for (virt_idx, interface) in standalone_virtual.iter().enumerate() {
|
||||||
let is_last = virt_idx == 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 { " ├─ " };
|
||||||
|
|
||||||
// Virtual interface with IPs
|
// Virtual interface with IPs
|
||||||
@@ -681,10 +753,19 @@ impl SystemWidget {
|
|||||||
String::new()
|
String::new()
|
||||||
};
|
};
|
||||||
|
|
||||||
let interface_text = if !ip_text.is_empty() {
|
// Format: "name (vlan X): IP" or "name: IP"
|
||||||
format!("{}: {}", interface.name, ip_text)
|
let interface_text = if let Some(vlan_id) = interface.vlan_id {
|
||||||
|
if !ip_text.is_empty() {
|
||||||
|
format!("{} (vlan {}): {}", interface.name, vlan_id, ip_text)
|
||||||
|
} else {
|
||||||
|
format!("{} (vlan {}):", interface.name, vlan_id)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
format!("{}:", interface.name)
|
if !ip_text.is_empty() {
|
||||||
|
format!("{}: {}", interface.name, ip_text)
|
||||||
|
} else {
|
||||||
|
format!("{}:", interface.name)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.168"
|
version = "0.1.173"
|
||||||
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