Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| a7755f02ae | |||
| b886fb2045 | |||
| cfb02e1763 | |||
| 5b53ca3d52 | |||
| 92a30913b4 | |||
| a288a8ef9a | |||
| c65d596099 | |||
| 98ed17947d | |||
| 1cb6abf58a | |||
| 477724b4f4 | |||
| 7a3ed17952 | |||
| 7e1962a168 | |||
| 5bb7d6cf57 | |||
| 7a0dc27846 | |||
| 5bc250a738 | |||
| 5c3ac8b15e | |||
| bdfff942f7 | |||
| 47ab1e387d | |||
| 966ba27b1e | |||
| 6c6c9144bd | |||
| 3fdcec8047 | |||
| 1fcaf4a670 | |||
| 885e19f7fd | |||
| a7b69b8ae7 | |||
| 2d290f40b2 | |||
| ad1fcaa27b | |||
| 60ab4d4f9e |
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -279,7 +279,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard"
|
||||
version = "0.1.226"
|
||||
version = "0.1.253"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"chrono",
|
||||
@@ -301,7 +301,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.226"
|
||||
version = "0.1.253"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-trait",
|
||||
@@ -325,7 +325,7 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "cm-dashboard-shared"
|
||||
version = "0.1.226"
|
||||
version = "0.1.253"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"serde",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-agent"
|
||||
version = "0.1.227"
|
||||
version = "0.1.254"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use anyhow::Result;
|
||||
use gethostname::gethostname;
|
||||
use std::time::Duration;
|
||||
use std::time::{Duration, Instant};
|
||||
use tokio::time::interval;
|
||||
use tracing::{debug, error, info};
|
||||
|
||||
@@ -19,13 +19,22 @@ use crate::collectors::{
|
||||
use crate::notifications::NotificationManager;
|
||||
use cm_dashboard_shared::AgentData;
|
||||
|
||||
/// Wrapper for collectors with timing information
|
||||
struct TimedCollector {
|
||||
collector: Box<dyn Collector>,
|
||||
interval: Duration,
|
||||
last_collection: Option<Instant>,
|
||||
name: String,
|
||||
}
|
||||
|
||||
pub struct Agent {
|
||||
hostname: String,
|
||||
config: AgentConfig,
|
||||
zmq_handler: ZmqHandler,
|
||||
collectors: Vec<Box<dyn Collector>>,
|
||||
collectors: Vec<TimedCollector>,
|
||||
notification_manager: NotificationManager,
|
||||
previous_status: Option<SystemStatus>,
|
||||
cached_agent_data: AgentData,
|
||||
}
|
||||
|
||||
/// Track system component status for change detection
|
||||
@@ -55,36 +64,78 @@ impl Agent {
|
||||
config.zmq.publisher_port
|
||||
);
|
||||
|
||||
// Initialize collectors
|
||||
let mut collectors: Vec<Box<dyn Collector>> = Vec::new();
|
||||
// Initialize collectors with timing information
|
||||
let mut collectors: Vec<TimedCollector> = Vec::new();
|
||||
|
||||
// Add enabled collectors
|
||||
if config.collectors.cpu.enabled {
|
||||
collectors.push(Box::new(CpuCollector::new(config.collectors.cpu.clone())));
|
||||
collectors.push(TimedCollector {
|
||||
collector: Box::new(CpuCollector::new(config.collectors.cpu.clone())),
|
||||
interval: Duration::from_secs(config.collectors.cpu.interval_seconds),
|
||||
last_collection: None,
|
||||
name: "CPU".to_string(),
|
||||
});
|
||||
info!("CPU collector initialized with {}s interval", config.collectors.cpu.interval_seconds);
|
||||
}
|
||||
|
||||
if config.collectors.memory.enabled {
|
||||
collectors.push(Box::new(MemoryCollector::new(config.collectors.memory.clone())));
|
||||
collectors.push(TimedCollector {
|
||||
collector: Box::new(MemoryCollector::new(config.collectors.memory.clone())),
|
||||
interval: Duration::from_secs(config.collectors.memory.interval_seconds),
|
||||
last_collection: None,
|
||||
name: "Memory".to_string(),
|
||||
});
|
||||
info!("Memory collector initialized with {}s interval", config.collectors.memory.interval_seconds);
|
||||
}
|
||||
|
||||
if config.collectors.disk.enabled {
|
||||
collectors.push(Box::new(DiskCollector::new(config.collectors.disk.clone())));
|
||||
collectors.push(TimedCollector {
|
||||
collector: Box::new(DiskCollector::new(config.collectors.disk.clone())),
|
||||
interval: Duration::from_secs(config.collectors.disk.interval_seconds),
|
||||
last_collection: None,
|
||||
name: "Disk".to_string(),
|
||||
});
|
||||
info!("Disk collector initialized with {}s interval", config.collectors.disk.interval_seconds);
|
||||
}
|
||||
|
||||
if config.collectors.systemd.enabled {
|
||||
collectors.push(Box::new(SystemdCollector::new(config.collectors.systemd.clone())));
|
||||
collectors.push(TimedCollector {
|
||||
collector: Box::new(SystemdCollector::new(config.collectors.systemd.clone())),
|
||||
interval: Duration::from_secs(config.collectors.systemd.interval_seconds),
|
||||
last_collection: None,
|
||||
name: "Systemd".to_string(),
|
||||
});
|
||||
info!("Systemd collector initialized with {}s interval", config.collectors.systemd.interval_seconds);
|
||||
}
|
||||
|
||||
if config.collectors.backup.enabled {
|
||||
collectors.push(Box::new(BackupCollector::new()));
|
||||
collectors.push(TimedCollector {
|
||||
collector: Box::new(BackupCollector::new()),
|
||||
interval: Duration::from_secs(config.collectors.backup.interval_seconds),
|
||||
last_collection: None,
|
||||
name: "Backup".to_string(),
|
||||
});
|
||||
info!("Backup collector initialized with {}s interval", config.collectors.backup.interval_seconds);
|
||||
}
|
||||
|
||||
if config.collectors.network.enabled {
|
||||
collectors.push(Box::new(NetworkCollector::new(config.collectors.network.clone())));
|
||||
collectors.push(TimedCollector {
|
||||
collector: Box::new(NetworkCollector::new(config.collectors.network.clone())),
|
||||
interval: Duration::from_secs(config.collectors.network.interval_seconds),
|
||||
last_collection: None,
|
||||
name: "Network".to_string(),
|
||||
});
|
||||
info!("Network collector initialized with {}s interval", config.collectors.network.interval_seconds);
|
||||
}
|
||||
|
||||
if config.collectors.nixos.enabled {
|
||||
collectors.push(Box::new(NixOSCollector::new(config.collectors.nixos.clone())));
|
||||
collectors.push(TimedCollector {
|
||||
collector: Box::new(NixOSCollector::new(config.collectors.nixos.clone())),
|
||||
interval: Duration::from_secs(config.collectors.nixos.interval_seconds),
|
||||
last_collection: None,
|
||||
name: "NixOS".to_string(),
|
||||
});
|
||||
info!("NixOS collector initialized with {}s interval", config.collectors.nixos.interval_seconds);
|
||||
}
|
||||
|
||||
info!("Initialized {} collectors", collectors.len());
|
||||
@@ -93,6 +144,9 @@ impl Agent {
|
||||
let notification_manager = NotificationManager::new(&config.notifications, &hostname)?;
|
||||
info!("Notification manager initialized");
|
||||
|
||||
// Initialize cached agent data
|
||||
let cached_agent_data = AgentData::new(hostname.clone(), env!("CARGO_PKG_VERSION").to_string());
|
||||
|
||||
Ok(Self {
|
||||
hostname,
|
||||
config,
|
||||
@@ -100,6 +154,7 @@ impl Agent {
|
||||
collectors,
|
||||
notification_manager,
|
||||
previous_status: None,
|
||||
cached_agent_data,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -149,24 +204,47 @@ impl Agent {
|
||||
async fn collect_and_broadcast(&mut self) -> Result<()> {
|
||||
debug!("Starting structured data collection");
|
||||
|
||||
// Initialize empty AgentData
|
||||
let mut agent_data = AgentData::new(self.hostname.clone(), env!("CARGO_PKG_VERSION").to_string());
|
||||
// Collect data from collectors whose intervals have elapsed
|
||||
// Update cached_agent_data with new data
|
||||
let now = Instant::now();
|
||||
for timed_collector in &mut self.collectors {
|
||||
let should_collect = match timed_collector.last_collection {
|
||||
None => true, // First collection
|
||||
Some(last_time) => now.duration_since(last_time) >= timed_collector.interval,
|
||||
};
|
||||
|
||||
// Collect data from all collectors
|
||||
for collector in &self.collectors {
|
||||
if let Err(e) = collector.collect_structured(&mut agent_data).await {
|
||||
error!("Collector failed: {}", e);
|
||||
// Continue with other collectors even if one fails
|
||||
if should_collect {
|
||||
if let Err(e) = timed_collector.collector.collect_structured(&mut self.cached_agent_data).await {
|
||||
error!("Collector {} failed: {}", timed_collector.name, e);
|
||||
// Update last_collection time even on failure to prevent immediate retries
|
||||
timed_collector.last_collection = Some(now);
|
||||
} else {
|
||||
timed_collector.last_collection = Some(now);
|
||||
debug!(
|
||||
"Collected from {} ({}s interval)",
|
||||
timed_collector.name,
|
||||
timed_collector.interval.as_secs()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Update timestamp on cached data
|
||||
self.cached_agent_data.timestamp = std::time::SystemTime::now()
|
||||
.duration_since(std::time::UNIX_EPOCH)
|
||||
.unwrap()
|
||||
.as_secs();
|
||||
|
||||
// Clone for notification check (to avoid borrow issues)
|
||||
let agent_data_snapshot = self.cached_agent_data.clone();
|
||||
|
||||
// Check for status changes and send notifications
|
||||
if let Err(e) = self.check_status_changes_and_notify(&agent_data).await {
|
||||
if let Err(e) = self.check_status_changes_and_notify(&agent_data_snapshot).await {
|
||||
error!("Failed to check status changes: {}", e);
|
||||
}
|
||||
|
||||
// Broadcast the structured data via ZMQ
|
||||
if let Err(e) = self.zmq_handler.publish_agent_data(&agent_data).await {
|
||||
// Broadcast the cached structured data via ZMQ
|
||||
if let Err(e) = self.zmq_handler.publish_agent_data(&agent_data_snapshot).await {
|
||||
error!("Failed to broadcast agent data: {}", e);
|
||||
} else {
|
||||
debug!("Successfully broadcast structured agent data");
|
||||
|
||||
@@ -119,6 +119,71 @@ impl CpuCollector {
|
||||
utils::parse_u64(content.trim())
|
||||
}
|
||||
|
||||
/// Collect static CPU information from /proc/cpuinfo (only once at startup)
|
||||
async fn collect_cpu_info(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
||||
let content = utils::read_proc_file("/proc/cpuinfo")?;
|
||||
|
||||
let mut model_name: Option<String> = None;
|
||||
let mut core_count: u32 = 0;
|
||||
|
||||
for line in content.lines() {
|
||||
if line.starts_with("model name") {
|
||||
if let Some(colon_pos) = line.find(':') {
|
||||
let full_name = line[colon_pos + 1..].trim();
|
||||
// Extract just the model number (e.g., "i7-9700" from "Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz")
|
||||
let model = Self::extract_cpu_model(full_name);
|
||||
if model_name.is_none() {
|
||||
model_name = Some(model);
|
||||
}
|
||||
}
|
||||
} else if line.starts_with("processor") {
|
||||
core_count += 1;
|
||||
}
|
||||
}
|
||||
|
||||
agent_data.system.cpu.model_name = model_name;
|
||||
if core_count > 0 {
|
||||
agent_data.system.cpu.core_count = Some(core_count);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Extract CPU model number from full model name
|
||||
/// Examples:
|
||||
/// - "Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz" -> "i7-9700"
|
||||
/// - "12th Gen Intel(R) Core(TM) i7-12700K" -> "i7-12700K"
|
||||
/// - "AMD Ryzen 9 5950X 16-Core Processor" -> "Ryzen 9 5950X"
|
||||
fn extract_cpu_model(full_name: &str) -> String {
|
||||
// Look for Intel Core patterns (both old and new gen): i3, i5, i7, i9
|
||||
// Match pattern like "i7-12700K" or "i7-9700"
|
||||
for prefix in &["i3-", "i5-", "i7-", "i9-"] {
|
||||
if let Some(pos) = full_name.find(prefix) {
|
||||
// Find end of model number (until space or end of string)
|
||||
let after_prefix = &full_name[pos..];
|
||||
let end = after_prefix.find(' ').unwrap_or(after_prefix.len());
|
||||
return after_prefix[..end].to_string();
|
||||
}
|
||||
}
|
||||
|
||||
// Look for AMD Ryzen pattern
|
||||
if let Some(pos) = full_name.find("Ryzen") {
|
||||
// Extract "Ryzen X XXXX" pattern
|
||||
let after_ryzen = &full_name[pos..];
|
||||
let parts: Vec<&str> = after_ryzen.split_whitespace().collect();
|
||||
if parts.len() >= 3 {
|
||||
return format!("{} {} {}", parts[0], parts[1], parts[2]);
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: return first 15 characters or full name if shorter
|
||||
if full_name.len() > 15 {
|
||||
full_name[..15].to_string()
|
||||
} else {
|
||||
full_name.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
/// Collect CPU C-state (idle depth) and populate AgentData with top 3 C-states by usage
|
||||
async fn collect_cstate(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
||||
// Read C-state usage from first CPU (representative of overall system)
|
||||
@@ -192,6 +257,11 @@ impl Collector for CpuCollector {
|
||||
debug!("Collecting CPU metrics");
|
||||
let start = std::time::Instant::now();
|
||||
|
||||
// Collect static CPU info (only once at startup)
|
||||
if agent_data.system.cpu.model_name.is_none() || agent_data.system.cpu.core_count.is_none() {
|
||||
self.collect_cpu_info(agent_data).await?;
|
||||
}
|
||||
|
||||
// Collect load averages (always available)
|
||||
self.collect_load_averages(agent_data).await?;
|
||||
|
||||
@@ -212,8 +282,8 @@ impl Collector for CpuCollector {
|
||||
);
|
||||
}
|
||||
|
||||
// Calculate status using thresholds
|
||||
agent_data.system.cpu.load_status = self.calculate_load_status(agent_data.system.cpu.load_1min);
|
||||
// Calculate status using thresholds (use 5-minute average for stability)
|
||||
agent_data.system.cpu.load_status = self.calculate_load_status(agent_data.system.cpu.load_5min);
|
||||
agent_data.system.cpu.temperature_status = if let Some(temp) = agent_data.system.cpu.temperature_celsius {
|
||||
self.calculate_temperature_status(temp)
|
||||
} else {
|
||||
|
||||
@@ -66,6 +66,10 @@ impl DiskCollector {
|
||||
|
||||
/// Collect all storage data and populate AgentData
|
||||
async fn collect_storage_data(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
||||
// Clear drives and pools to prevent duplicates when updating cached data
|
||||
agent_data.system.storage.drives.clear();
|
||||
agent_data.system.storage.pools.clear();
|
||||
|
||||
// Step 1: Get mount points and their backing devices
|
||||
let mount_devices = self.get_mount_devices().await?;
|
||||
|
||||
|
||||
@@ -200,6 +200,9 @@ impl Collector for MemoryCollector {
|
||||
debug!("Collecting memory metrics");
|
||||
let start = std::time::Instant::now();
|
||||
|
||||
// Clear tmpfs list to prevent duplicates when updating cached data
|
||||
agent_data.system.memory.tmpfs.clear();
|
||||
|
||||
// Parse memory info from /proc/meminfo
|
||||
let info = self.parse_meminfo().await?;
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ use cm_dashboard_shared::{AgentData, ServiceData, SubServiceData, SubServiceMetr
|
||||
use std::process::Command;
|
||||
use std::sync::RwLock;
|
||||
use std::time::Instant;
|
||||
use tracing::debug;
|
||||
use tracing::{debug, info};
|
||||
|
||||
use super::{Collector, CollectorError};
|
||||
use crate::config::SystemdConfig;
|
||||
@@ -142,23 +142,68 @@ impl SystemdCollector {
|
||||
|
||||
// Add Docker images
|
||||
let docker_images = self.get_docker_images();
|
||||
for (image_name, image_status, image_size_mb) in docker_images {
|
||||
let mut metrics = Vec::new();
|
||||
metrics.push(SubServiceMetric {
|
||||
label: "size".to_string(),
|
||||
value: image_size_mb,
|
||||
unit: Some("MB".to_string()),
|
||||
});
|
||||
for (image_name, _image_status, image_size_mb) in docker_images {
|
||||
let metrics = Vec::new();
|
||||
|
||||
sub_services.push(SubServiceData {
|
||||
name: image_name.to_string(),
|
||||
service_status: self.calculate_service_status(&image_name, &image_status),
|
||||
name: format!("{} size: {:.1} MB", image_name, image_size_mb),
|
||||
service_status: Status::Info, // Informational only, no status icon
|
||||
metrics,
|
||||
service_type: "image".to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if service_name == "openvpn-vpn-download" && status_info.active_state == "active" {
|
||||
// Add VPN route
|
||||
if let Some(external_ip) = self.get_vpn_external_ip() {
|
||||
let metrics = Vec::new();
|
||||
|
||||
sub_services.push(SubServiceData {
|
||||
name: format!("route: {}", external_ip),
|
||||
service_status: Status::Info,
|
||||
metrics,
|
||||
service_type: "vpn_route".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
// Add torrent stats
|
||||
if let Some((active_count, download_mbps, upload_mbps)) = self.get_qbittorrent_stats() {
|
||||
let metrics = Vec::new();
|
||||
|
||||
sub_services.push(SubServiceData {
|
||||
name: format!("{} active, ↓ {:.1} MB/s, ↑ {:.1} MB/s", active_count, download_mbps, upload_mbps),
|
||||
service_status: Status::Info,
|
||||
metrics,
|
||||
service_type: "torrent_stats".to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if service_name == "nftables" && status_info.active_state == "active" {
|
||||
let (tcp_ports, udp_ports) = self.get_nftables_open_ports();
|
||||
|
||||
if !tcp_ports.is_empty() {
|
||||
let metrics = Vec::new();
|
||||
sub_services.push(SubServiceData {
|
||||
name: format!("TCP: {}", tcp_ports),
|
||||
service_status: Status::Info,
|
||||
metrics,
|
||||
service_type: "firewall_port".to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
if !udp_ports.is_empty() {
|
||||
let metrics = Vec::new();
|
||||
sub_services.push(SubServiceData {
|
||||
name: format!("UDP: {}", udp_ports),
|
||||
service_status: Status::Info,
|
||||
metrics,
|
||||
service_type: "firewall_port".to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Create complete service data
|
||||
let service_data = ServiceData {
|
||||
name: service_name.clone(),
|
||||
@@ -836,11 +881,221 @@ impl SystemdCollector {
|
||||
_ => value, // Assume bytes if no unit
|
||||
}
|
||||
}
|
||||
|
||||
/// Get VPN external IP by querying through the vpn namespace
|
||||
fn get_vpn_external_ip(&self) -> Option<String> {
|
||||
let output = Command::new("timeout")
|
||||
.args(&[
|
||||
"5",
|
||||
"sudo",
|
||||
"ip",
|
||||
"netns",
|
||||
"exec",
|
||||
"vpn",
|
||||
"curl",
|
||||
"-s",
|
||||
"--max-time",
|
||||
"4",
|
||||
"https://ifconfig.me"
|
||||
])
|
||||
.output()
|
||||
.ok()?;
|
||||
|
||||
if output.status.success() {
|
||||
let ip = String::from_utf8_lossy(&output.stdout).trim().to_string();
|
||||
if !ip.is_empty() && ip.contains('.') {
|
||||
return Some(ip);
|
||||
}
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
/// Get nftables open ports grouped by protocol
|
||||
/// Returns: (tcp_ports_string, udp_ports_string)
|
||||
fn get_nftables_open_ports(&self) -> (String, String) {
|
||||
let output = Command::new("timeout")
|
||||
.args(&["3", "sudo", "nft", "list", "ruleset"])
|
||||
.output();
|
||||
|
||||
let output = match output {
|
||||
Ok(out) if out.status.success() => out,
|
||||
Ok(out) => {
|
||||
info!("nft command failed with status: {:?}, stderr: {}",
|
||||
out.status, String::from_utf8_lossy(&out.stderr));
|
||||
return (String::new(), String::new());
|
||||
}
|
||||
Err(e) => {
|
||||
info!("Failed to execute nft command: {}", e);
|
||||
return (String::new(), String::new());
|
||||
}
|
||||
};
|
||||
|
||||
let output_str = match String::from_utf8(output.stdout) {
|
||||
Ok(s) => s,
|
||||
Err(_) => {
|
||||
info!("Failed to parse nft output as UTF-8");
|
||||
return (String::new(), String::new());
|
||||
}
|
||||
};
|
||||
|
||||
let mut tcp_ports = std::collections::HashSet::new();
|
||||
let mut udp_ports = std::collections::HashSet::new();
|
||||
|
||||
// Parse nftables output for WAN incoming accept rules with dport
|
||||
// Looking for patterns like: tcp dport 22 accept or tcp dport { 22, 80, 443 } accept
|
||||
// Only include rules in input_wan chain
|
||||
let mut in_wan_chain = false;
|
||||
|
||||
for line in output_str.lines() {
|
||||
let line = line.trim();
|
||||
|
||||
// Track if we're in the input_wan chain
|
||||
if line.contains("chain input_wan") {
|
||||
in_wan_chain = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Reset when exiting chain (closing brace) or entering other chains
|
||||
if line == "}" || (line.starts_with("chain ") && !line.contains("input_wan")) {
|
||||
in_wan_chain = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Only process rules in input_wan chain
|
||||
if !in_wan_chain {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Skip if not an accept rule
|
||||
if !line.contains("accept") {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Parse TCP ports
|
||||
if line.contains("tcp dport") {
|
||||
for port in self.extract_ports_from_nft_rule(line) {
|
||||
tcp_ports.insert(port);
|
||||
}
|
||||
}
|
||||
|
||||
// Parse UDP ports
|
||||
if line.contains("udp dport") {
|
||||
for port in self.extract_ports_from_nft_rule(line) {
|
||||
udp_ports.insert(port);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort and format
|
||||
let mut tcp_vec: Vec<u16> = tcp_ports.into_iter().collect();
|
||||
let mut udp_vec: Vec<u16> = udp_ports.into_iter().collect();
|
||||
tcp_vec.sort();
|
||||
udp_vec.sort();
|
||||
|
||||
let tcp_str = tcp_vec.iter().map(|p| p.to_string()).collect::<Vec<_>>().join(", ");
|
||||
let udp_str = udp_vec.iter().map(|p| p.to_string()).collect::<Vec<_>>().join(", ");
|
||||
|
||||
info!("nftables WAN ports - TCP: '{}', UDP: '{}'", tcp_str, udp_str);
|
||||
|
||||
(tcp_str, udp_str)
|
||||
}
|
||||
|
||||
/// Extract port numbers from nftables rule line
|
||||
/// Returns vector of ports (handles both single ports and sets)
|
||||
fn extract_ports_from_nft_rule(&self, line: &str) -> Vec<u16> {
|
||||
let mut ports = Vec::new();
|
||||
|
||||
// Pattern: "tcp dport 22 accept" or "tcp dport { 22, 80, 443 } accept"
|
||||
if let Some(dport_pos) = line.find("dport") {
|
||||
let after_dport = &line[dport_pos + 5..].trim();
|
||||
|
||||
// Handle port sets like { 22, 80, 443 }
|
||||
if after_dport.starts_with('{') {
|
||||
if let Some(end_brace) = after_dport.find('}') {
|
||||
let ports_str = &after_dport[1..end_brace];
|
||||
// Parse each port in the set
|
||||
for port_str in ports_str.split(',') {
|
||||
if let Ok(port) = port_str.trim().parse::<u16>() {
|
||||
ports.push(port);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Single port
|
||||
if let Some(port_str) = after_dport.split_whitespace().next() {
|
||||
if let Ok(port) = port_str.parse::<u16>() {
|
||||
ports.push(port);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ports
|
||||
}
|
||||
|
||||
/// Get aggregate qBittorrent torrent statistics
|
||||
/// Returns: (active_count, download_mbps, upload_mbps)
|
||||
fn get_qbittorrent_stats(&self) -> Option<(u32, f32, f32)> {
|
||||
// Query qBittorrent API through VPN namespace
|
||||
let output = Command::new("timeout")
|
||||
.args(&[
|
||||
"5",
|
||||
"sudo",
|
||||
"ip",
|
||||
"netns",
|
||||
"exec",
|
||||
"vpn",
|
||||
"curl",
|
||||
"-s",
|
||||
"--max-time",
|
||||
"4",
|
||||
"http://localhost:8080/api/v2/torrents/info"
|
||||
])
|
||||
.output()
|
||||
.ok()?;
|
||||
|
||||
if !output.status.success() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let output_str = String::from_utf8_lossy(&output.stdout);
|
||||
let torrents: Vec<serde_json::Value> = serde_json::from_str(&output_str).ok()?;
|
||||
|
||||
let mut active_count = 0u32;
|
||||
let mut total_download_bps = 0.0f64;
|
||||
let mut total_upload_bps = 0.0f64;
|
||||
|
||||
for torrent in torrents {
|
||||
let state = torrent["state"].as_str().unwrap_or("");
|
||||
let dlspeed = torrent["dlspeed"].as_f64().unwrap_or(0.0);
|
||||
let upspeed = torrent["upspeed"].as_f64().unwrap_or(0.0);
|
||||
|
||||
// States: downloading, uploading, stalledDL, stalledUP, queuedDL, queuedUP, pausedDL, pausedUP
|
||||
// Count as active if downloading or uploading (seeding)
|
||||
if state.contains("downloading") || state.contains("uploading") ||
|
||||
state == "stalledDL" || state == "stalledUP" {
|
||||
active_count += 1;
|
||||
}
|
||||
|
||||
total_download_bps += dlspeed;
|
||||
total_upload_bps += upspeed;
|
||||
}
|
||||
|
||||
// qBittorrent returns bytes/s, convert to MB/s
|
||||
let download_mbps = (total_download_bps / 1024.0 / 1024.0) as f32;
|
||||
let upload_mbps = (total_upload_bps / 1024.0 / 1024.0) as f32;
|
||||
|
||||
Some((active_count, download_mbps, upload_mbps))
|
||||
}
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl Collector for SystemdCollector {
|
||||
async fn collect_structured(&self, agent_data: &mut AgentData) -> Result<(), CollectorError> {
|
||||
// Clear services to prevent duplicates when updating cached data
|
||||
agent_data.services.clear();
|
||||
|
||||
// Use cached complete data if available and fresh
|
||||
if let Some(cached_complete_services) = self.get_cached_complete_services() {
|
||||
for service_data in cached_complete_services {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard"
|
||||
version = "0.1.227"
|
||||
version = "0.1.254"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -110,14 +110,6 @@ impl TuiApp {
|
||||
host_widgets.system_widget.update_from_agent_data(agent_data);
|
||||
host_widgets.services_widget.update_from_agent_data(agent_data);
|
||||
|
||||
// Update ZMQ stats
|
||||
if let Some(zmq_stats) = metric_store.get_zmq_stats(&hostname) {
|
||||
host_widgets.system_widget.update_zmq_stats(
|
||||
zmq_stats.packets_received,
|
||||
zmq_stats.last_packet_age_secs
|
||||
);
|
||||
}
|
||||
|
||||
host_widgets.last_update = Some(Instant::now());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,6 +142,7 @@ impl Theme {
|
||||
/// Get color for status level
|
||||
pub fn status_color(status: Status) -> Color {
|
||||
match status {
|
||||
Status::Info => Self::muted_text(), // Gray for informational data
|
||||
Status::Ok => Self::success(),
|
||||
Status::Inactive => Self::muted_text(), // Gray for inactive services in service list
|
||||
Status::Pending => Self::highlight(), // Blue for pending
|
||||
@@ -240,6 +241,7 @@ impl StatusIcons {
|
||||
/// Get status icon symbol
|
||||
pub fn get_icon(status: Status) -> &'static str {
|
||||
match status {
|
||||
Status::Info => "", // No icon for informational data
|
||||
Status::Ok => "●",
|
||||
Status::Inactive => "○", // Empty circle for inactive services
|
||||
Status::Pending => "◉", // Hollow circle for pending
|
||||
@@ -254,6 +256,7 @@ impl StatusIcons {
|
||||
pub fn create_status_spans(status: Status, text: &str) -> Vec<ratatui::text::Span<'static>> {
|
||||
let icon = Self::get_icon(status);
|
||||
let status_color = match status {
|
||||
Status::Info => Theme::muted_text(), // Gray for info
|
||||
Status::Ok => Theme::success(), // Green
|
||||
Status::Inactive => Theme::muted_text(), // Gray for inactive services
|
||||
Status::Pending => Theme::highlight(), // Blue
|
||||
|
||||
@@ -22,10 +22,25 @@ struct ColumnVisibility {
|
||||
}
|
||||
|
||||
impl ColumnVisibility {
|
||||
/// Calculate actual width needed for all columns
|
||||
const NAME_WIDTH: u16 = 23;
|
||||
const STATUS_WIDTH: u16 = 10;
|
||||
const RAM_WIDTH: u16 = 8;
|
||||
const UPTIME_WIDTH: u16 = 8;
|
||||
const RESTARTS_WIDTH: u16 = 5;
|
||||
const COLUMN_SPACING: u16 = 1; // Space between columns
|
||||
|
||||
/// Determine which columns to show based on available width
|
||||
/// Priority order: Name > Status > RAM > Uptime > Restarts
|
||||
fn from_width(width: u16) -> Self {
|
||||
if width >= 80 {
|
||||
// Full layout: Name (25) + Status (10) + RAM (8) + Uptime (8) + Restarts (5) = 56 chars
|
||||
// Calculate cumulative widths for each configuration
|
||||
let minimal = Self::NAME_WIDTH + Self::COLUMN_SPACING + Self::STATUS_WIDTH; // 34
|
||||
let with_ram = minimal + Self::COLUMN_SPACING + Self::RAM_WIDTH; // 43
|
||||
let with_uptime = with_ram + Self::COLUMN_SPACING + Self::UPTIME_WIDTH; // 52
|
||||
let full = with_uptime + Self::COLUMN_SPACING + Self::RESTARTS_WIDTH; // 58
|
||||
|
||||
if width >= full {
|
||||
// Show all columns
|
||||
Self {
|
||||
show_name: true,
|
||||
show_status: true,
|
||||
@@ -33,8 +48,8 @@ impl ColumnVisibility {
|
||||
show_uptime: true,
|
||||
show_restarts: true,
|
||||
}
|
||||
} else if width >= 60 {
|
||||
// Hide restarts: Name (25) + Status (10) + RAM (8) + Uptime (8) = 51 chars
|
||||
} else if width >= with_uptime {
|
||||
// Hide restarts
|
||||
Self {
|
||||
show_name: true,
|
||||
show_status: true,
|
||||
@@ -42,8 +57,8 @@ impl ColumnVisibility {
|
||||
show_uptime: true,
|
||||
show_restarts: false,
|
||||
}
|
||||
} else if width >= 45 {
|
||||
// Hide uptime and restarts: Name (25) + Status (10) + RAM (8) = 43 chars
|
||||
} else if width >= with_ram {
|
||||
// Hide uptime and restarts
|
||||
Self {
|
||||
show_name: true,
|
||||
show_status: true,
|
||||
@@ -52,7 +67,7 @@ impl ColumnVisibility {
|
||||
show_restarts: false,
|
||||
}
|
||||
} else {
|
||||
// Minimal: Name (25) + Status (10) = 35 chars
|
||||
// Minimal: Name + Status only
|
||||
Self {
|
||||
show_name: true,
|
||||
show_status: true,
|
||||
@@ -130,15 +145,18 @@ impl ServicesWidget {
|
||||
|
||||
/// Format parent service line - returns text without icon for span formatting
|
||||
fn format_parent_service_line(&self, name: &str, info: &ServiceInfo, columns: ColumnVisibility) -> String {
|
||||
// Truncate long service names to fit layout (account for icon space)
|
||||
let short_name = if name.len() > 22 {
|
||||
format!("{}...", &name[..19])
|
||||
// Truncate long service names to fit layout
|
||||
// NAME_WIDTH - 3 chars for "..." = max displayable chars
|
||||
let max_name_len = (ColumnVisibility::NAME_WIDTH - 3) as usize;
|
||||
let short_name = if name.len() > max_name_len {
|
||||
format!("{}...", &name[..max_name_len.saturating_sub(3)])
|
||||
} else {
|
||||
name.to_string()
|
||||
};
|
||||
|
||||
// Convert Status enum to display text
|
||||
let status_str = match info.widget_status {
|
||||
Status::Info => "", // Shouldn't happen for parent services
|
||||
Status::Ok => "active",
|
||||
Status::Inactive => "inactive",
|
||||
Status::Critical => "failed",
|
||||
@@ -185,19 +203,19 @@ impl ServicesWidget {
|
||||
// Build format string based on column visibility
|
||||
let mut parts = Vec::new();
|
||||
if columns.show_name {
|
||||
parts.push(format!("{:<23}", short_name));
|
||||
parts.push(format!("{:<width$}", short_name, width = ColumnVisibility::NAME_WIDTH as usize));
|
||||
}
|
||||
if columns.show_status {
|
||||
parts.push(format!("{:<10}", status_str));
|
||||
parts.push(format!("{:<width$}", status_str, width = ColumnVisibility::STATUS_WIDTH as usize));
|
||||
}
|
||||
if columns.show_ram {
|
||||
parts.push(format!("{:<8}", memory_str));
|
||||
parts.push(format!("{:<width$}", memory_str, width = ColumnVisibility::RAM_WIDTH as usize));
|
||||
}
|
||||
if columns.show_uptime {
|
||||
parts.push(format!("{:<8}", uptime_str));
|
||||
parts.push(format!("{:<width$}", uptime_str, width = ColumnVisibility::UPTIME_WIDTH as usize));
|
||||
}
|
||||
if columns.show_restarts {
|
||||
parts.push(format!("{:<5}", restart_str));
|
||||
parts.push(format!("{:<width$}", restart_str, width = ColumnVisibility::RESTARTS_WIDTH as usize));
|
||||
}
|
||||
|
||||
parts.join(" ")
|
||||
@@ -212,9 +230,12 @@ impl ServicesWidget {
|
||||
info: &ServiceInfo,
|
||||
is_last: bool,
|
||||
) -> Vec<ratatui::text::Span<'static>> {
|
||||
// Informational sub-services (Status::Info) can use more width since they don't show columns
|
||||
let max_width = if info.widget_status == Status::Info { 50 } else { 18 };
|
||||
|
||||
// Truncate long sub-service names to fit layout (accounting for indentation)
|
||||
let short_name = if name.len() > 18 {
|
||||
format!("{}...", &name[..15])
|
||||
let short_name = if name.len() > max_width {
|
||||
format!("{}...", &name[..(max_width.saturating_sub(3))])
|
||||
} else {
|
||||
name.to_string()
|
||||
};
|
||||
@@ -222,6 +243,7 @@ impl ServicesWidget {
|
||||
// Get status icon and text
|
||||
let icon = StatusIcons::get_icon(info.widget_status);
|
||||
let status_color = match info.widget_status {
|
||||
Status::Info => Theme::muted_text(),
|
||||
Status::Ok => Theme::success(),
|
||||
Status::Inactive => Theme::muted_text(),
|
||||
Status::Pending => Theme::highlight(),
|
||||
@@ -242,6 +264,7 @@ impl ServicesWidget {
|
||||
} else {
|
||||
// Convert Status enum to display text for sub-services
|
||||
match info.widget_status {
|
||||
Status::Info => "",
|
||||
Status::Ok => "active",
|
||||
Status::Inactive => "inactive",
|
||||
Status::Critical => "failed",
|
||||
@@ -253,34 +276,34 @@ impl ServicesWidget {
|
||||
};
|
||||
let tree_symbol = if is_last { "└─" } else { "├─" };
|
||||
|
||||
// Docker images use docker whale icon
|
||||
if info.service_type == "image" {
|
||||
vec![
|
||||
if info.widget_status == Status::Info {
|
||||
// Informational data - no status icon, show metrics if available
|
||||
let mut spans = vec![
|
||||
// Indentation and tree prefix
|
||||
ratatui::text::Span::styled(
|
||||
format!(" {} ", tree_symbol),
|
||||
Typography::tree(),
|
||||
),
|
||||
// Docker icon (simple character for performance)
|
||||
// Service name (no icon) - no fixed width padding for Info status
|
||||
ratatui::text::Span::styled(
|
||||
"D ".to_string(),
|
||||
Style::default().fg(Theme::highlight()).bg(Theme::background()),
|
||||
),
|
||||
// Service name
|
||||
ratatui::text::Span::styled(
|
||||
format!("{:<18} ", short_name),
|
||||
short_name,
|
||||
Style::default()
|
||||
.fg(Theme::secondary_text())
|
||||
.bg(Theme::background()),
|
||||
),
|
||||
// Status/metrics text
|
||||
ratatui::text::Span::styled(
|
||||
];
|
||||
|
||||
// Add metrics if available (e.g., Docker image size)
|
||||
if !status_str.is_empty() {
|
||||
spans.push(ratatui::text::Span::styled(
|
||||
status_str,
|
||||
Style::default()
|
||||
.fg(Theme::secondary_text())
|
||||
.bg(Theme::background()),
|
||||
),
|
||||
]
|
||||
));
|
||||
}
|
||||
|
||||
spans
|
||||
} else {
|
||||
vec![
|
||||
// Indentation and tree prefix
|
||||
@@ -550,19 +573,19 @@ impl ServicesWidget {
|
||||
// Build header based on visible columns
|
||||
let mut header_parts = Vec::new();
|
||||
if columns.show_name {
|
||||
header_parts.push(format!("{:<25}", "Service:"));
|
||||
header_parts.push(format!("{:<width$}", "Service:", width = ColumnVisibility::NAME_WIDTH as usize));
|
||||
}
|
||||
if columns.show_status {
|
||||
header_parts.push(format!("{:<10}", "Status:"));
|
||||
header_parts.push(format!("{:<width$}", "Status:", width = ColumnVisibility::STATUS_WIDTH as usize));
|
||||
}
|
||||
if columns.show_ram {
|
||||
header_parts.push(format!("{:<8}", "RAM:"));
|
||||
header_parts.push(format!("{:<width$}", "RAM:", width = ColumnVisibility::RAM_WIDTH as usize));
|
||||
}
|
||||
if columns.show_uptime {
|
||||
header_parts.push(format!("{:<8}", "Uptime:"));
|
||||
header_parts.push(format!("{:<width$}", "Uptime:", width = ColumnVisibility::UPTIME_WIDTH as usize));
|
||||
}
|
||||
if columns.show_restarts {
|
||||
header_parts.push(format!("{:<5}", "↻:"));
|
||||
header_parts.push(format!("{:<width$}", "↻:", width = ColumnVisibility::RESTARTS_WIDTH as usize));
|
||||
}
|
||||
let header = header_parts.join(" ");
|
||||
|
||||
|
||||
@@ -15,10 +15,6 @@ pub struct SystemWidget {
|
||||
nixos_build: Option<String>,
|
||||
agent_hash: Option<String>,
|
||||
|
||||
// ZMQ communication stats
|
||||
zmq_packets_received: Option<u64>,
|
||||
zmq_last_packet_age: Option<f64>,
|
||||
|
||||
// Network interfaces
|
||||
network_interfaces: Vec<cm_dashboard_shared::NetworkInterfaceData>,
|
||||
|
||||
@@ -27,6 +23,8 @@ pub struct SystemWidget {
|
||||
cpu_load_5min: Option<f32>,
|
||||
cpu_load_15min: Option<f32>,
|
||||
cpu_cstates: Vec<cm_dashboard_shared::CStateInfo>,
|
||||
cpu_model_name: Option<String>,
|
||||
cpu_core_count: Option<u32>,
|
||||
cpu_status: Status,
|
||||
|
||||
// Memory metrics
|
||||
@@ -90,13 +88,13 @@ impl SystemWidget {
|
||||
Self {
|
||||
nixos_build: None,
|
||||
agent_hash: None,
|
||||
zmq_packets_received: None,
|
||||
zmq_last_packet_age: None,
|
||||
network_interfaces: Vec::new(),
|
||||
cpu_load_1min: None,
|
||||
cpu_load_5min: None,
|
||||
cpu_load_15min: None,
|
||||
cpu_cstates: Vec::new(),
|
||||
cpu_model_name: None,
|
||||
cpu_core_count: None,
|
||||
cpu_status: Status::Unknown,
|
||||
memory_usage_percent: None,
|
||||
memory_used_gb: None,
|
||||
@@ -155,12 +153,6 @@ impl SystemWidget {
|
||||
pub fn _get_agent_hash(&self) -> Option<&String> {
|
||||
self.agent_hash.as_ref()
|
||||
}
|
||||
|
||||
/// Update ZMQ communication statistics
|
||||
pub fn update_zmq_stats(&mut self, packets_received: u64, last_packet_age_secs: f64) {
|
||||
self.zmq_packets_received = Some(packets_received);
|
||||
self.zmq_last_packet_age = Some(last_packet_age_secs);
|
||||
}
|
||||
}
|
||||
|
||||
use super::Widget;
|
||||
@@ -184,6 +176,8 @@ impl Widget for SystemWidget {
|
||||
self.cpu_load_5min = Some(cpu.load_5min);
|
||||
self.cpu_load_15min = Some(cpu.load_15min);
|
||||
self.cpu_cstates = cpu.cstates.clone();
|
||||
self.cpu_model_name = cpu.model_name.clone();
|
||||
self.cpu_core_count = cpu.core_count;
|
||||
self.cpu_status = Status::Ok;
|
||||
|
||||
// Extract memory data directly
|
||||
@@ -805,18 +799,6 @@ impl SystemWidget {
|
||||
Span::styled(format!("Agent: {}", agent_version_text), Typography::secondary())
|
||||
]));
|
||||
|
||||
// ZMQ communication stats
|
||||
if let (Some(packets), Some(age)) = (self.zmq_packets_received, self.zmq_last_packet_age) {
|
||||
let age_text = if age < 1.0 {
|
||||
format!("{:.0}ms ago", age * 1000.0)
|
||||
} else {
|
||||
format!("{:.1}s ago", age)
|
||||
};
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(format!("ZMQ: {} pkts, last {}", packets, age_text), Typography::secondary())
|
||||
]));
|
||||
}
|
||||
|
||||
// CPU section
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled("CPU:", Typography::widget_title())
|
||||
@@ -830,11 +812,31 @@ impl SystemWidget {
|
||||
lines.push(Line::from(cpu_spans));
|
||||
|
||||
let cstate_text = self.format_cpu_cstate();
|
||||
let has_cpu_info = self.cpu_model_name.is_some() || self.cpu_core_count.is_some();
|
||||
let cstate_tree = if has_cpu_info { " ├─ " } else { " └─ " };
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(" └─ ", Typography::tree()),
|
||||
Span::styled(cstate_tree, Typography::tree()),
|
||||
Span::styled(format!("C-state: {}", cstate_text), Typography::secondary())
|
||||
]));
|
||||
|
||||
// CPU model and core count (if available)
|
||||
if let (Some(model), Some(cores)) = (&self.cpu_model_name, self.cpu_core_count) {
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(" └─ ", Typography::tree()),
|
||||
Span::styled(format!("{} ({} cores)", model, cores), Typography::secondary())
|
||||
]));
|
||||
} else if let Some(model) = &self.cpu_model_name {
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(" └─ ", Typography::tree()),
|
||||
Span::styled(model.clone(), Typography::secondary())
|
||||
]));
|
||||
} else if let Some(cores) = self.cpu_core_count {
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled(" └─ ", Typography::tree()),
|
||||
Span::styled(format!("{} cores", cores), Typography::secondary())
|
||||
]));
|
||||
}
|
||||
|
||||
// RAM section
|
||||
lines.push(Line::from(vec![
|
||||
Span::styled("RAM:", Typography::widget_title())
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "cm-dashboard-shared"
|
||||
version = "0.1.227"
|
||||
version = "0.1.254"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
|
||||
@@ -57,6 +57,11 @@ pub struct CpuData {
|
||||
pub temperature_celsius: Option<f32>,
|
||||
pub load_status: Status,
|
||||
pub temperature_status: Status,
|
||||
// Static CPU information (collected once at startup)
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub model_name: Option<String>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub core_count: Option<u32>,
|
||||
}
|
||||
|
||||
/// Memory monitoring data
|
||||
@@ -219,6 +224,8 @@ impl AgentData {
|
||||
temperature_celsius: None,
|
||||
load_status: Status::Unknown,
|
||||
temperature_status: Status::Unknown,
|
||||
model_name: None,
|
||||
core_count: None,
|
||||
},
|
||||
memory: MemoryData {
|
||||
usage_percent: 0.0,
|
||||
|
||||
@@ -82,11 +82,12 @@ impl MetricValue {
|
||||
/// Health status for metrics
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum Status {
|
||||
Inactive, // Lowest priority
|
||||
Info, // Lowest priority - informational data with no status (no icon)
|
||||
Inactive, //
|
||||
Unknown, //
|
||||
Offline, //
|
||||
Pending, //
|
||||
Ok, // 5th place - good status has higher priority than unknown states
|
||||
Ok, // Good status has higher priority than unknown states
|
||||
Warning, //
|
||||
Critical, // Highest priority
|
||||
}
|
||||
@@ -223,6 +224,17 @@ impl HysteresisThresholds {
|
||||
Status::Ok
|
||||
}
|
||||
}
|
||||
Status::Info => {
|
||||
// Informational data shouldn't be used with hysteresis calculations
|
||||
// Treat like Unknown if it somehow ends up here
|
||||
if value >= self.critical_high {
|
||||
Status::Critical
|
||||
} else if value >= self.warning_high {
|
||||
Status::Warning
|
||||
} else {
|
||||
Status::Ok
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user