Add network interface collection and display
Some checks failed
Build and Release / build-and-release (push) Failing after 1m32s
Some checks failed
Build and Release / build-and-release (push) Failing after 1m32s
Extend NixOS collector to gather network interfaces using ip command JSON output. Display all interfaces with IPv4 and IPv6 addresses in Network section above CPU metrics. Filters out loopback and link-local addresses. Version bump to 0.1.161
This commit is contained in:
@@ -8,13 +8,16 @@ use ratatui::{
|
||||
|
||||
use crate::ui::theme::{StatusIcons, Typography};
|
||||
|
||||
/// System widget displaying NixOS info, CPU, RAM, and Storage in unified layout
|
||||
/// System widget displaying NixOS info, Network, CPU, RAM, and Storage in unified layout
|
||||
#[derive(Clone)]
|
||||
pub struct SystemWidget {
|
||||
// NixOS information
|
||||
nixos_build: Option<String>,
|
||||
agent_hash: Option<String>,
|
||||
|
||||
|
||||
// Network interfaces
|
||||
network_interfaces: Vec<cm_dashboard_shared::NetworkInterfaceData>,
|
||||
|
||||
// CPU metrics
|
||||
cpu_load_1min: Option<f32>,
|
||||
cpu_load_5min: Option<f32>,
|
||||
@@ -89,6 +92,7 @@ impl SystemWidget {
|
||||
Self {
|
||||
nixos_build: None,
|
||||
agent_hash: None,
|
||||
network_interfaces: Vec::new(),
|
||||
cpu_load_1min: None,
|
||||
cpu_load_5min: None,
|
||||
cpu_load_15min: None,
|
||||
@@ -164,6 +168,9 @@ impl Widget for SystemWidget {
|
||||
// Extract build version
|
||||
self.nixos_build = agent_data.build_version.clone();
|
||||
|
||||
// Extract network interfaces
|
||||
self.network_interfaces = agent_data.system.network.interfaces.clone();
|
||||
|
||||
// Extract CPU data directly
|
||||
let cpu = &agent_data.system.cpu;
|
||||
self.cpu_load_1min = Some(cpu.load_1min);
|
||||
@@ -573,8 +580,46 @@ impl SystemWidget {
|
||||
lines
|
||||
}
|
||||
|
||||
/// Render system widget
|
||||
pub fn render(&mut self, frame: &mut Frame, area: Rect, hostname: &str, config: Option<&crate::config::DashboardConfig>) {
|
||||
/// Render network section for display
|
||||
fn render_network(&self) -> Vec<Line<'_>> {
|
||||
let mut lines = Vec::new();
|
||||
|
||||
if self.network_interfaces.is_empty() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
for (i, interface) in self.network_interfaces.iter().enumerate() {
|
||||
let is_last = i == self.network_interfaces.len() - 1;
|
||||
let tree_symbol = if is_last { " └─ " } else { " ├─ " };
|
||||
|
||||
// Show interface name
|
||||
let mut interface_text = format!("{}: ", interface.name);
|
||||
|
||||
// Add IPv4 addresses
|
||||
if !interface.ipv4_addresses.is_empty() {
|
||||
interface_text.push_str(&interface.ipv4_addresses.join(", "));
|
||||
}
|
||||
|
||||
// Add IPv6 addresses
|
||||
if !interface.ipv6_addresses.is_empty() {
|
||||
if !interface.ipv4_addresses.is_empty() {
|
||||
interface_text.push_str(", ");
|
||||
}
|
||||
interface_text.push_str(&interface.ipv6_addresses.join(", "));
|
||||
}
|
||||
|
||||
let mut spans = vec![
|
||||
Span::styled(tree_symbol, Typography::tree()),
|
||||
];
|
||||
spans.extend(StatusIcons::create_status_spans(Status::Ok, &interface_text));
|
||||
lines.push(Line::from(spans));
|
||||
}
|
||||
|
||||
lines
|
||||
}
|
||||
|
||||
/// Render system widget
|
||||
pub fn render(&mut self, frame: &mut Frame, area: Rect, hostname: &str, _config: Option<&crate::config::DashboardConfig>) {
|
||||
let mut lines = Vec::new();
|
||||
|
||||
// NixOS section
|
||||
@@ -591,17 +636,16 @@ impl SystemWidget {
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(format!("Agent: {}", agent_version_text), Typography::secondary())
|
||||
]));
|
||||
|
||||
// Display detected connection IP
|
||||
if let Some(config) = config {
|
||||
if let Some(host_details) = config.hosts.get(hostname) {
|
||||
let detected_ip = host_details.get_connection_ip(hostname);
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(format!("IP: {}", detected_ip), 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
|
||||
lines.push(Line::from(vec![
|
||||
|
||||
Reference in New Issue
Block a user