Implement multi-host autoconnect with consolidated host configuration
- Add DEFAULT_HOSTS constant in config.rs for centralized host management - Update ZMQ endpoint generation to connect to all configured hosts - Implement graceful connection handling for unreachable endpoints - Dashboard now auto-discovers and connects to available agents on cmbox, labbox, simonbox, steambox, srv01
This commit is contained in:
parent
c8655bf852
commit
dca3642e46
@ -8,7 +8,7 @@ use crossterm::event::{KeyCode, KeyEvent, KeyEventKind};
|
||||
use gethostname::gethostname;
|
||||
|
||||
use crate::config;
|
||||
use crate::data::config::{AppConfig, DataSourceKind, HostTarget, ZmqConfig};
|
||||
use crate::data::config::{AppConfig, DataSourceKind, HostTarget, ZmqConfig, DEFAULT_HOSTS};
|
||||
use crate::data::history::MetricsHistory;
|
||||
use crate::data::metrics::{BackupMetrics, ServiceMetrics, SmartMetrics, SystemMetrics};
|
||||
|
||||
@ -420,10 +420,7 @@ impl App {
|
||||
fn select_hosts(host: Option<&String>, _config: Option<&AppConfig>) -> Vec<HostTarget> {
|
||||
let mut targets = Vec::new();
|
||||
|
||||
// Known CMTEC infrastructure hosts for auto-discovery
|
||||
let known_hosts = vec![
|
||||
"cmbox", "labbox", "simonbox", "steambox", "srv01"
|
||||
];
|
||||
// Use default hosts for auto-discovery
|
||||
|
||||
if let Some(filter) = host {
|
||||
// If specific host requested, only connect to that one
|
||||
@ -437,8 +434,8 @@ impl App {
|
||||
targets.push(HostTarget::from_name(local.clone()));
|
||||
}
|
||||
|
||||
// Add all known hosts for auto-discovery
|
||||
for hostname in known_hosts {
|
||||
// Add all default hosts for auto-discovery
|
||||
for hostname in DEFAULT_HOSTS {
|
||||
if targets
|
||||
.iter()
|
||||
.any(|existing| existing.name.eq_ignore_ascii_case(hostname))
|
||||
@ -562,7 +559,18 @@ impl App {
|
||||
.unwrap_or(default);
|
||||
|
||||
let endpoints = if zmq_config.endpoints.is_empty() {
|
||||
ZmqConfig::default().endpoints
|
||||
// Generate endpoints for all default hosts
|
||||
let mut endpoints = Vec::new();
|
||||
|
||||
// Always include localhost
|
||||
endpoints.push("tcp://127.0.0.1:6130".to_string());
|
||||
|
||||
// Add endpoint for each default host
|
||||
for host in DEFAULT_HOSTS {
|
||||
endpoints.push(format!("tcp://{}:6130", host));
|
||||
}
|
||||
|
||||
endpoints
|
||||
} else {
|
||||
zmq_config.endpoints.clone()
|
||||
};
|
||||
|
||||
@ -129,10 +129,22 @@ const fn default_tick_rate_ms() -> u64 {
|
||||
500
|
||||
}
|
||||
|
||||
/// Default hosts for auto-discovery
|
||||
pub const DEFAULT_HOSTS: &[&str] = &[
|
||||
"cmbox", "labbox", "simonbox", "steambox", "srv01"
|
||||
];
|
||||
|
||||
fn default_data_source_config() -> DataSourceConfig {
|
||||
DataSourceConfig::default()
|
||||
}
|
||||
|
||||
fn default_zmq_endpoints() -> Vec<String> {
|
||||
vec!["tcp://127.0.0.1:6130".to_string()]
|
||||
// Default endpoints include localhost and all known CMTEC hosts
|
||||
let mut endpoints = vec!["tcp://127.0.0.1:6130".to_string()];
|
||||
|
||||
for host in DEFAULT_HOSTS {
|
||||
endpoints.push(format!("tcp://{}:6130", host));
|
||||
}
|
||||
|
||||
endpoints
|
||||
}
|
||||
|
||||
@ -249,12 +249,25 @@ fn metrics_blocking_loop(
|
||||
.set_rcvtimeo(1_000)
|
||||
.context("failed to configure ZMQ receive timeout")?;
|
||||
|
||||
let mut connected_endpoints = 0;
|
||||
for endpoint in context.endpoints() {
|
||||
debug!(%endpoint, "connecting to ZMQ endpoint");
|
||||
socket
|
||||
.connect(endpoint)
|
||||
.with_context(|| format!("failed to connect to {endpoint}"))?;
|
||||
debug!(%endpoint, "attempting to connect to ZMQ endpoint");
|
||||
match socket.connect(endpoint) {
|
||||
Ok(()) => {
|
||||
debug!(%endpoint, "successfully connected to ZMQ endpoint");
|
||||
connected_endpoints += 1;
|
||||
}
|
||||
Err(error) => {
|
||||
warn!(%endpoint, %error, "failed to connect to ZMQ endpoint, continuing with others");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if connected_endpoints == 0 {
|
||||
return Err(anyhow!("failed to connect to any ZMQ endpoints"));
|
||||
}
|
||||
|
||||
debug!("connected to {}/{} ZMQ endpoints", connected_endpoints, context.endpoints().len());
|
||||
|
||||
if let Some(prefix) = context.subscription() {
|
||||
socket
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user