Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 407bc9dbc2 | |||
| 3c278351c9 | |||
| 8da4522d85 | |||
| 5b1e39cfca |
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard"
|
||||
version = "0.1.261"
|
||||
version = "0.1.265"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@@ -301,7 +301,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.261"
|
||||
version = "0.1.265"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
@@ -325,7 +325,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard-shared"
|
||||
version = "0.1.261"
|
||||
version = "0.1.265"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"serde",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.262"
|
||||
version = "0.1.266"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -217,14 +217,15 @@ impl SystemdCollector {
|
||||
}
|
||||
|
||||
if service_name == "tailscaled" && status_info.active_state == "active" {
|
||||
// Add Tailscale connection method as sub-service
|
||||
if let Some(conn_method) = self.get_tailscale_connection_method() {
|
||||
// Add Tailscale peers with their connection methods as sub-services
|
||||
let peers = self.get_tailscale_peers();
|
||||
for (peer_name, conn_method) in peers {
|
||||
let metrics = Vec::new();
|
||||
sub_services.push(SubServiceData {
|
||||
name: format!("Connection: {}", conn_method),
|
||||
name: format!("{}: {}", peer_name, conn_method),
|
||||
service_status: Status::Info,
|
||||
metrics,
|
||||
service_type: "tailscale_connection".to_string(),
|
||||
service_type: "tailscale_peer".to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -936,50 +937,77 @@ impl SystemdCollector {
|
||||
None
|
||||
}
|
||||
|
||||
/// Get Tailscale connection method (direct, relay, or proxy)
|
||||
fn get_tailscale_connection_method(&self) -> Option<String> {
|
||||
/// Get Tailscale connected peers with their connection methods
|
||||
/// Returns a list of (device_name, connection_method) tuples
|
||||
fn get_tailscale_peers(&self) -> Vec<(String, String)> {
|
||||
match Command::new("timeout")
|
||||
.args(["2", "tailscale", "status", "--json"])
|
||||
.args(["2", "tailscale", "status"])
|
||||
.output()
|
||||
{
|
||||
Ok(output) if output.status.success() => {
|
||||
let json_str = String::from_utf8_lossy(&output.stdout);
|
||||
let status_output = String::from_utf8_lossy(&output.stdout);
|
||||
let mut peers = Vec::new();
|
||||
|
||||
if let Ok(json_data) = serde_json::from_str::<serde_json::Value>(&json_str) {
|
||||
// Look for the self peer (current node) in the peer list
|
||||
if let Some(peers) = json_data["Peer"].as_object() {
|
||||
// Find the first active peer connection to determine connection method
|
||||
for (_peer_id, peer_data) in peers {
|
||||
if peer_data["Active"].as_bool().unwrap_or(false) {
|
||||
// Check if using relay
|
||||
let relay_node = peer_data["Relay"].as_str().unwrap_or("");
|
||||
if !relay_node.is_empty() {
|
||||
return Some("relay".to_string());
|
||||
// Get current hostname to filter it out
|
||||
let current_hostname = gethostname::gethostname()
|
||||
.to_string_lossy()
|
||||
.to_string();
|
||||
|
||||
// Parse tailscale status output
|
||||
// Format: IP hostname user os status
|
||||
// Example: 100.110.98.3 wslbox cm@ linux active; direct 192.168.30.227:53757
|
||||
// Note: First line is always the current host, skip it
|
||||
for (idx, line) in status_output.lines().enumerate() {
|
||||
if idx == 0 {
|
||||
continue; // Skip first line (current host)
|
||||
}
|
||||
|
||||
// Check if using direct connection
|
||||
if let Some(endpoints) = peer_data["CurAddr"].as_str() {
|
||||
if !endpoints.is_empty() {
|
||||
return Some("direct".to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let parts: Vec<&str> = line.split_whitespace().collect();
|
||||
if parts.len() < 5 {
|
||||
continue; // Skip invalid lines
|
||||
}
|
||||
|
||||
// Check if using proxy from backend state
|
||||
if let Some(backend_state) = json_data["BackendState"].as_str() {
|
||||
if backend_state == "Running" {
|
||||
// If we're running but have no direct or relay, might be proxy
|
||||
// This is a fallback heuristic
|
||||
return Some("unknown".to_string());
|
||||
}
|
||||
}
|
||||
// parts[0] = IP
|
||||
// parts[1] = hostname
|
||||
// parts[2] = user
|
||||
// parts[3] = OS
|
||||
// parts[4+] = status (e.g., "active;", "direct", "192.168.30.227:53757" or "idle;" or "offline")
|
||||
|
||||
let hostname = parts[1];
|
||||
|
||||
// Skip if this is the current host (double-check in case format changes)
|
||||
if hostname == current_hostname {
|
||||
continue;
|
||||
}
|
||||
|
||||
None
|
||||
let status_parts = &parts[4..];
|
||||
|
||||
// Determine connection method from status
|
||||
let connection_method = if status_parts.is_empty() {
|
||||
continue; // Skip if no status
|
||||
} else {
|
||||
let status_str = status_parts.join(" ");
|
||||
if status_str.contains("offline") {
|
||||
continue; // Skip offline peers
|
||||
} else if status_str.contains("direct") {
|
||||
"direct"
|
||||
} else if status_str.contains("relay") {
|
||||
"relay"
|
||||
} else if status_str.contains("idle") {
|
||||
"idle"
|
||||
} else if status_str.contains("active") {
|
||||
"active"
|
||||
} else {
|
||||
continue; // Skip unknown status
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
|
||||
peers.push((hostname.to_string(), connection_method.to_string()));
|
||||
}
|
||||
|
||||
peers
|
||||
}
|
||||
_ => Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard"
|
||||
version = "0.1.262"
|
||||
version = "0.1.266"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -138,11 +138,12 @@ impl Dashboard {
|
||||
let metrics_check_interval = Duration::from_millis(100); // Check for metrics every 100ms
|
||||
let mut last_heartbeat_check = Instant::now();
|
||||
let heartbeat_check_interval = Duration::from_secs(1); // Check for host connectivity every 1 second
|
||||
let mut needs_render = true; // Track if we need to render
|
||||
|
||||
loop {
|
||||
// Handle terminal events (keyboard and mouse input) only if not headless
|
||||
if !self.headless {
|
||||
match event::poll(Duration::from_millis(50)) {
|
||||
match event::poll(Duration::from_millis(200)) {
|
||||
Ok(true) => {
|
||||
match event::read() {
|
||||
Ok(event) => {
|
||||
@@ -152,6 +153,7 @@ impl Dashboard {
|
||||
// Handle keyboard input
|
||||
match tui_app.handle_input(event) {
|
||||
Ok(_) => {
|
||||
needs_render = true;
|
||||
// Check if we should quit
|
||||
if tui_app.should_quit() {
|
||||
info!("Quit requested, exiting dashboard");
|
||||
@@ -168,10 +170,11 @@ impl Dashboard {
|
||||
if let Err(e) = self.handle_mouse_event(mouse_event) {
|
||||
error!("Error handling mouse event: {}", e);
|
||||
}
|
||||
needs_render = true;
|
||||
}
|
||||
Event::Resize(_width, _height) => {
|
||||
// Terminal was resized - just continue and re-render
|
||||
// The next render will automatically use the new size
|
||||
// Terminal was resized - mark for re-render
|
||||
needs_render = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -189,38 +192,6 @@ impl Dashboard {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Render UI immediately after handling input for responsive feedback
|
||||
if let Some(ref mut terminal) = self.terminal {
|
||||
if let Some(ref mut tui_app) = self.tui_app {
|
||||
// Clear and autoresize terminal to handle any resize events
|
||||
if let Err(e) = terminal.autoresize() {
|
||||
warn!("Error autoresizing terminal: {}", e);
|
||||
}
|
||||
|
||||
// Check minimum terminal size to prevent panics
|
||||
let size = terminal.size().unwrap_or_default();
|
||||
if size.width < 90 || size.height < 15 {
|
||||
// Terminal too small, show error message
|
||||
let msg_text = format!("Terminal too small\n\nMinimum: 90x15\nCurrent: {}x{}", size.width, size.height);
|
||||
let _ = terminal.draw(|frame| {
|
||||
use ratatui::widgets::{Paragraph, Block, Borders};
|
||||
use ratatui::layout::Alignment;
|
||||
let msg = Paragraph::new(msg_text.clone())
|
||||
.alignment(Alignment::Center)
|
||||
.block(Block::default().borders(Borders::ALL));
|
||||
frame.render_widget(msg, frame.size());
|
||||
});
|
||||
} else if let Err(e) = terminal.draw(|frame| {
|
||||
let (title_area, system_area, services_area) = tui_app.render(frame, &self.metric_store);
|
||||
self.title_area = title_area;
|
||||
self.system_area = system_area;
|
||||
self.services_area = services_area;
|
||||
}) {
|
||||
error!("Error rendering TUI after input: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check for new metrics
|
||||
@@ -259,6 +230,8 @@ impl Dashboard {
|
||||
if let Some(ref mut tui_app) = self.tui_app {
|
||||
tui_app.update_metrics(&mut self.metric_store);
|
||||
}
|
||||
|
||||
needs_render = true; // New metrics received, need to render
|
||||
}
|
||||
|
||||
// Also check for command output messages
|
||||
@@ -287,10 +260,11 @@ impl Dashboard {
|
||||
tui_app.update_hosts(connected_hosts);
|
||||
}
|
||||
last_heartbeat_check = Instant::now();
|
||||
needs_render = true; // Heartbeat check happened, may have changed hosts
|
||||
}
|
||||
|
||||
// Render TUI (only if not headless)
|
||||
if !self.headless {
|
||||
// Render TUI only when needed (not headless and something changed)
|
||||
if !self.headless && needs_render {
|
||||
if let Some(ref mut terminal) = self.terminal {
|
||||
if let Some(ref mut tui_app) = self.tui_app {
|
||||
// Clear and autoresize terminal to handle any resize events
|
||||
@@ -322,10 +296,8 @@ impl Dashboard {
|
||||
}
|
||||
}
|
||||
}
|
||||
needs_render = false; // Reset flag after rendering
|
||||
}
|
||||
|
||||
// Small sleep to prevent excessive CPU usage
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
|
||||
info!("Dashboard main loop ended");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-shared"
|
||||
version = "0.1.262"
|
||||
version = "0.1.266"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
Reference in New Issue
Block a user