Add Tailscale connection method monitoring
All checks were successful
Build and Release / build-and-release (push) Successful in 1m25s

Add connection_method field to NetworkInterfaceData to track whether
Tailscale is using direct P2P, DERP relay, or HTTP proxy connections.
The connection method is displayed as a sub-service under tailscaled
service, following the same pattern as VPN routes and firewall ports.

Query tailscale status --json to determine active connection type and
display as informational sub-service when tailscaled is active.
This commit is contained in:
Christoffer Martinsson 2025-12-08 21:01:47 +01:00
parent bc9015e96b
commit 49f9504429
7 changed files with 68 additions and 6 deletions

6
Cargo.lock generated
View File

@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
[[package]]
name = "cm-dashboard"
version = "0.1.259"
version = "0.1.260"
dependencies = [
"anyhow",
"chrono",
@ -301,7 +301,7 @@ dependencies = [
[[package]]
name = "cm-dashboard-agent"
version = "0.1.259"
version = "0.1.260"
dependencies = [
"anyhow",
"async-trait",
@ -325,7 +325,7 @@ dependencies = [
[[package]]
name = "cm-dashboard-shared"
version = "0.1.259"
version = "0.1.260"
dependencies = [
"chrono",
"serde",

View File

@ -1,6 +1,6 @@
[package]
name = "cm-dashboard-agent"
version = "0.1.260"
version = "0.1.261"
edition = "2021"
[dependencies]

View File

@ -181,6 +181,7 @@ impl NetworkCollector {
link_status,
parent_interface,
vlan_id,
connection_method: None,
});
}
}

View File

@ -216,6 +216,19 @@ 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() {
let metrics = Vec::new();
sub_services.push(SubServiceData {
name: format!("Connection: {}", conn_method),
service_status: Status::Info,
metrics,
service_type: "tailscale_connection".to_string(),
});
}
}
// Create complete service data
let service_data = ServiceData {
name: service_name.clone(),
@ -923,6 +936,53 @@ impl SystemdCollector {
None
}
/// Get Tailscale connection method (direct, relay, or proxy)
fn get_tailscale_connection_method(&self) -> Option<String> {
match Command::new("timeout")
.args(["2", "tailscale", "status", "--json"])
.output()
{
Ok(output) if output.status.success() => {
let json_str = String::from_utf8_lossy(&output.stdout);
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());
}
// Check if using direct connection
if let Some(endpoints) = peer_data["CurAddr"].as_str() {
if !endpoints.is_empty() {
return Some("direct".to_string());
}
}
}
}
}
// 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());
}
}
}
None
}
_ => None,
}
}
/// Get nftables open ports grouped by protocol
/// Returns: (tcp_ports_string, udp_ports_string)
fn get_nftables_open_ports(&self) -> (String, String) {

View File

@ -1,6 +1,6 @@
[package]
name = "cm-dashboard"
version = "0.1.260"
version = "0.1.261"
edition = "2021"
[dependencies]

View File

@ -1,6 +1,6 @@
[package]
name = "cm-dashboard-shared"
version = "0.1.260"
version = "0.1.261"
edition = "2021"
[dependencies]

View File

@ -38,6 +38,7 @@ pub struct NetworkInterfaceData {
pub link_status: Status,
pub parent_interface: Option<String>,
pub vlan_id: Option<u16>,
pub connection_method: Option<String>, // For Tailscale: "direct", "relay", or "proxy"
}
/// CPU C-state usage information