Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c8f800a1e5 | |||
| fc6b3424cf | |||
| 35e06c6734 | |||
| 783d233319 | |||
| 6509a2b91a | |||
| 52f8c40b86 | |||
| a86b5ba8f9 | |||
| 1b964545be |
6
Cargo.lock
generated
6
Cargo.lock
generated
@@ -270,7 +270,7 @@ checksum = "a1d728cc89cf3aee9ff92b05e62b19ee65a02b5702cff7d5a377e32c6ae29d8d"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.33"
|
version = "0.1.40"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -291,7 +291,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.33"
|
version = "0.1.40"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"async-trait",
|
"async-trait",
|
||||||
@@ -314,7 +314,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.33"
|
version = "0.1.40"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-agent"
|
name = "cm-dashboard-agent"
|
||||||
version = "0.1.34"
|
version = "0.1.42"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -37,6 +37,22 @@ impl NixOSCollector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Get configuration hash from deployed nix store system
|
/// Get configuration hash from deployed nix store system
|
||||||
|
/// Get git commit hash from rebuild process
|
||||||
|
fn get_git_commit(&self) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
|
let commit_file = "/var/lib/cm-dashboard/git-commit";
|
||||||
|
match std::fs::read_to_string(commit_file) {
|
||||||
|
Ok(content) => {
|
||||||
|
let commit_hash = content.trim();
|
||||||
|
if commit_hash.len() >= 7 {
|
||||||
|
Ok(commit_hash.to_string())
|
||||||
|
} else {
|
||||||
|
Err("Git commit hash too short".into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Err(e) => Err(format!("Failed to read git commit file: {}", e).into())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_config_hash(&self) -> Result<String, Box<dyn std::error::Error>> {
|
fn get_config_hash(&self) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
// Read the symlink target of /run/current-system to get nix store path
|
// Read the symlink target of /run/current-system to get nix store path
|
||||||
let output = Command::new("readlink")
|
let output = Command::new("readlink")
|
||||||
@@ -74,25 +90,25 @@ impl Collector for NixOSCollector {
|
|||||||
let mut metrics = Vec::new();
|
let mut metrics = Vec::new();
|
||||||
let timestamp = chrono::Utc::now().timestamp() as u64;
|
let timestamp = chrono::Utc::now().timestamp() as u64;
|
||||||
|
|
||||||
// Collect NixOS build information (config hash)
|
// Collect git commit information (shows what's actually deployed)
|
||||||
match self.get_config_hash() {
|
match self.get_git_commit() {
|
||||||
Ok(config_hash) => {
|
Ok(git_commit) => {
|
||||||
metrics.push(Metric {
|
metrics.push(Metric {
|
||||||
name: "system_nixos_build".to_string(),
|
name: "system_nixos_build".to_string(),
|
||||||
value: MetricValue::String(config_hash),
|
value: MetricValue::String(git_commit),
|
||||||
unit: None,
|
unit: None,
|
||||||
description: Some("NixOS deployed configuration hash".to_string()),
|
description: Some("Git commit hash of deployed configuration".to_string()),
|
||||||
status: Status::Ok,
|
status: Status::Ok,
|
||||||
timestamp,
|
timestamp,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!("Failed to get config hash: {}", e);
|
debug!("Failed to get git commit: {}", e);
|
||||||
metrics.push(Metric {
|
metrics.push(Metric {
|
||||||
name: "system_nixos_build".to_string(),
|
name: "system_nixos_build".to_string(),
|
||||||
value: MetricValue::String("unknown".to_string()),
|
value: MetricValue::String("unknown".to_string()),
|
||||||
unit: None,
|
unit: None,
|
||||||
description: Some("NixOS config hash (failed to detect)".to_string()),
|
description: Some("Git commit hash (failed to detect)".to_string()),
|
||||||
status: Status::Unknown,
|
status: Status::Unknown,
|
||||||
timestamp,
|
timestamp,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -555,10 +555,8 @@ impl SystemdCollector {
|
|||||||
for (site_name, url) in &sites {
|
for (site_name, url) in &sites {
|
||||||
match self.check_site_latency(url) {
|
match self.check_site_latency(url) {
|
||||||
Ok(latency_ms) => {
|
Ok(latency_ms) => {
|
||||||
let status = if latency_ms < 500.0 {
|
let status = if latency_ms < self.config.nginx_latency_critical_ms {
|
||||||
Status::Ok
|
Status::Ok
|
||||||
} else if latency_ms < 2000.0 {
|
|
||||||
Status::Warning
|
|
||||||
} else {
|
} else {
|
||||||
Status::Critical
|
Status::Critical
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -108,6 +108,7 @@ pub struct SystemdConfig {
|
|||||||
pub nginx_check_interval_seconds: u64,
|
pub nginx_check_interval_seconds: u64,
|
||||||
pub http_timeout_seconds: u64,
|
pub http_timeout_seconds: u64,
|
||||||
pub http_connect_timeout_seconds: u64,
|
pub http_connect_timeout_seconds: u64,
|
||||||
|
pub nginx_latency_critical_ms: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -83,6 +83,13 @@ pub fn validate_config(config: &AgentConfig) -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Validate systemd configuration
|
||||||
|
if config.collectors.systemd.enabled {
|
||||||
|
if config.collectors.systemd.nginx_latency_critical_ms <= 0.0 {
|
||||||
|
bail!("Nginx latency critical threshold must be positive");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Validate SMTP configuration
|
// Validate SMTP configuration
|
||||||
if config.notifications.enabled {
|
if config.notifications.enabled {
|
||||||
if config.notifications.smtp_host.is_empty() {
|
if config.notifications.smtp_host.is_empty() {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard"
|
name = "cm-dashboard"
|
||||||
version = "0.1.34"
|
version = "0.1.42"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use app::Dashboard;
|
|||||||
|
|
||||||
/// Get hardcoded version
|
/// Get hardcoded version
|
||||||
fn get_version() -> &'static str {
|
fn get_version() -> &'static str {
|
||||||
"v0.1.33"
|
"v0.1.42"
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check if running inside tmux session
|
/// Check if running inside tmux session
|
||||||
|
|||||||
@@ -244,16 +244,23 @@ impl TuiApp {
|
|||||||
KeyCode::Char('r') => {
|
KeyCode::Char('r') => {
|
||||||
// System rebuild command - works on any panel for current host
|
// System rebuild command - works on any panel for current host
|
||||||
if let Some(hostname) = self.current_host.clone() {
|
if let Some(hostname) = self.current_host.clone() {
|
||||||
// Launch tmux popup with SSH using config values
|
// Create command that shows CM Dashboard logo and then rebuilds
|
||||||
let ssh_command = format!(
|
let logo_and_rebuild = format!(
|
||||||
"ssh -tt {}@{} 'bash -ic {}'",
|
r"cat << 'EOF'
|
||||||
|
NixOS System Rebuild
|
||||||
|
Target: {}
|
||||||
|
|
||||||
|
EOF
|
||||||
|
ssh -tt {}@{} 'bash -ic {}'",
|
||||||
|
hostname,
|
||||||
self.config.ssh.rebuild_user,
|
self.config.ssh.rebuild_user,
|
||||||
hostname,
|
hostname,
|
||||||
self.config.ssh.rebuild_alias
|
self.config.ssh.rebuild_alias
|
||||||
);
|
);
|
||||||
|
|
||||||
std::process::Command::new("tmux")
|
std::process::Command::new("tmux")
|
||||||
.arg("display-popup")
|
.arg("display-popup")
|
||||||
.arg(&ssh_command)
|
.arg(&logo_and_rebuild)
|
||||||
.spawn()
|
.spawn()
|
||||||
.ok(); // Ignore errors, tmux will handle them
|
.ok(); // Ignore errors, tmux will handle them
|
||||||
}
|
}
|
||||||
@@ -536,48 +543,87 @@ impl TuiApp {
|
|||||||
|
|
||||||
if self.available_hosts.is_empty() {
|
if self.available_hosts.is_empty() {
|
||||||
let title_text = "cm-dashboard • no hosts discovered";
|
let title_text = "cm-dashboard • no hosts discovered";
|
||||||
let title = Paragraph::new(title_text).style(Typography::title());
|
let title = Paragraph::new(title_text)
|
||||||
|
.style(Style::default().fg(Theme::background()).bg(Theme::status_color(Status::Unknown)));
|
||||||
frame.render_widget(title, area);
|
frame.render_widget(title, area);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create spans for each host with status indicators
|
// Calculate worst-case status across all hosts
|
||||||
let mut spans = vec![Span::styled("cm-dashboard • ", Typography::title())];
|
let mut worst_status = Status::Ok;
|
||||||
|
for host in &self.available_hosts {
|
||||||
|
let host_status = self.calculate_host_status(host, metric_store);
|
||||||
|
worst_status = Status::aggregate(&[worst_status, host_status]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use the worst status color as background
|
||||||
|
let background_color = Theme::status_color(worst_status);
|
||||||
|
|
||||||
|
// Split the title bar into left and right sections
|
||||||
|
let chunks = Layout::default()
|
||||||
|
.direction(Direction::Horizontal)
|
||||||
|
.constraints([Constraint::Length(15), Constraint::Min(0)])
|
||||||
|
.split(area);
|
||||||
|
|
||||||
|
// Left side: "cm-dashboard" text
|
||||||
|
let left_span = Span::styled(
|
||||||
|
" cm-dashboard",
|
||||||
|
Style::default().fg(Theme::background()).bg(background_color).add_modifier(Modifier::BOLD)
|
||||||
|
);
|
||||||
|
let left_title = Paragraph::new(Line::from(vec![left_span]))
|
||||||
|
.style(Style::default().bg(background_color));
|
||||||
|
frame.render_widget(left_title, chunks[0]);
|
||||||
|
|
||||||
|
// Right side: hosts with status indicators
|
||||||
|
let mut host_spans = Vec::new();
|
||||||
|
|
||||||
for (i, host) in self.available_hosts.iter().enumerate() {
|
for (i, host) in self.available_hosts.iter().enumerate() {
|
||||||
if i > 0 {
|
if i > 0 {
|
||||||
spans.push(Span::styled(" ", Typography::title()));
|
host_spans.push(Span::styled(
|
||||||
|
" ",
|
||||||
|
Style::default().fg(Theme::background()).bg(background_color)
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Always show normal status icon based on metrics (no command status at host level)
|
// Always show normal status icon based on metrics (no command status at host level)
|
||||||
let host_status = self.calculate_host_status(host, metric_store);
|
let host_status = self.calculate_host_status(host, metric_store);
|
||||||
let (status_icon, status_color) = (StatusIcons::get_icon(host_status), Theme::status_color(host_status));
|
let status_icon = StatusIcons::get_icon(host_status);
|
||||||
|
|
||||||
// Add status icon
|
// Add status icon with background color as foreground against status background
|
||||||
spans.push(Span::styled(
|
host_spans.push(Span::styled(
|
||||||
format!("{} ", status_icon),
|
format!("{} ", status_icon),
|
||||||
Style::default().fg(status_color),
|
Style::default().fg(Theme::background()).bg(background_color),
|
||||||
));
|
));
|
||||||
|
|
||||||
if Some(host) == self.current_host.as_ref() {
|
if Some(host) == self.current_host.as_ref() {
|
||||||
// Selected host in bold bright white
|
// Selected host in bold background color against status background
|
||||||
spans.push(Span::styled(
|
host_spans.push(Span::styled(
|
||||||
host.clone(),
|
host.clone(),
|
||||||
Typography::title().add_modifier(Modifier::BOLD),
|
Style::default()
|
||||||
|
.fg(Theme::background())
|
||||||
|
.bg(background_color)
|
||||||
|
.add_modifier(Modifier::BOLD),
|
||||||
));
|
));
|
||||||
} else {
|
} else {
|
||||||
// Other hosts in normal style with status color
|
// Other hosts in normal background color against status background
|
||||||
spans.push(Span::styled(
|
host_spans.push(Span::styled(
|
||||||
host.clone(),
|
host.clone(),
|
||||||
Style::default().fg(status_color),
|
Style::default().fg(Theme::background()).bg(background_color),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let title_line = Line::from(spans);
|
// Add right padding
|
||||||
let title = Paragraph::new(vec![title_line]);
|
host_spans.push(Span::styled(
|
||||||
|
" ",
|
||||||
|
Style::default().fg(Theme::background()).bg(background_color)
|
||||||
|
));
|
||||||
|
|
||||||
frame.render_widget(title, area);
|
let host_line = Line::from(host_spans);
|
||||||
|
let host_title = Paragraph::new(vec![host_line])
|
||||||
|
.style(Style::default().bg(background_color))
|
||||||
|
.alignment(ratatui::layout::Alignment::Right);
|
||||||
|
frame.render_widget(host_title, chunks[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calculate overall status for a host based on its metrics
|
/// Calculate overall status for a host based on its metrics
|
||||||
@@ -662,7 +708,7 @@ impl TuiApp {
|
|||||||
host_widgets.system_scroll_offset
|
host_widgets.system_scroll_offset
|
||||||
};
|
};
|
||||||
let host_widgets = self.get_or_create_host_widgets(&hostname);
|
let host_widgets = self.get_or_create_host_widgets(&hostname);
|
||||||
host_widgets.system_widget.render_with_scroll(frame, inner_area, scroll_offset);
|
host_widgets.system_widget.render_with_scroll(frame, inner_area, scroll_offset, &hostname);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -292,12 +292,6 @@ impl Components {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Typography {
|
impl Typography {
|
||||||
/// Main title style (dashboard header)
|
|
||||||
pub fn title() -> Style {
|
|
||||||
Style::default()
|
|
||||||
.fg(Theme::primary_text())
|
|
||||||
.bg(Theme::background())
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Widget title style (panel headers) - bold bright white
|
/// Widget title style (panel headers) - bold bright white
|
||||||
pub fn widget_title() -> Style {
|
pub fn widget_title() -> Style {
|
||||||
|
|||||||
@@ -230,20 +230,49 @@ impl SystemWidget {
|
|||||||
|
|
||||||
/// Extract pool name from disk metric name
|
/// Extract pool name from disk metric name
|
||||||
fn extract_pool_name(&self, metric_name: &str) -> Option<String> {
|
fn extract_pool_name(&self, metric_name: &str) -> Option<String> {
|
||||||
if let Some(captures) = metric_name.strip_prefix("disk_") {
|
// Pattern: disk_{pool_name}_{drive_name}_{metric_type}
|
||||||
|
// Since pool_name can contain underscores, work backwards from known metric suffixes
|
||||||
|
if metric_name.starts_with("disk_") {
|
||||||
|
// First try drive-specific metrics that have device names
|
||||||
|
if let Some(suffix_pos) = metric_name.rfind("_temperature")
|
||||||
|
.or_else(|| metric_name.rfind("_wear_percent"))
|
||||||
|
.or_else(|| metric_name.rfind("_health")) {
|
||||||
|
// Find the second-to-last underscore to get pool name
|
||||||
|
let before_suffix = &metric_name[..suffix_pos];
|
||||||
|
if let Some(drive_start) = before_suffix.rfind('_') {
|
||||||
|
return Some(metric_name[5..drive_start].to_string()); // Skip "disk_"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// For pool-level metrics (usage_percent, used_gb, total_gb), take everything before the metric suffix
|
||||||
|
else if let Some(suffix_pos) = metric_name.rfind("_usage_percent")
|
||||||
|
.or_else(|| metric_name.rfind("_used_gb"))
|
||||||
|
.or_else(|| metric_name.rfind("_total_gb")) {
|
||||||
|
return Some(metric_name[5..suffix_pos].to_string()); // Skip "disk_"
|
||||||
|
}
|
||||||
|
// Fallback to old behavior for unknown patterns
|
||||||
|
else if let Some(captures) = metric_name.strip_prefix("disk_") {
|
||||||
if let Some(pos) = captures.find('_') {
|
if let Some(pos) = captures.find('_') {
|
||||||
return Some(captures[..pos].to_string());
|
return Some(captures[..pos].to_string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract drive name from disk metric name
|
/// Extract drive name from disk metric name
|
||||||
fn extract_drive_name(&self, metric_name: &str) -> Option<String> {
|
fn extract_drive_name(&self, metric_name: &str) -> Option<String> {
|
||||||
// Pattern: disk_pool_drive_metric
|
// Pattern: disk_{pool_name}_{drive_name}_{metric_type}
|
||||||
let parts: Vec<&str> = metric_name.split('_').collect();
|
// Since pool_name can contain underscores, work backwards from known metric suffixes
|
||||||
if parts.len() >= 3 && parts[0] == "disk" {
|
if metric_name.starts_with("disk_") {
|
||||||
return Some(parts[2].to_string());
|
if let Some(suffix_pos) = metric_name.rfind("_temperature")
|
||||||
|
.or_else(|| metric_name.rfind("_wear_percent"))
|
||||||
|
.or_else(|| metric_name.rfind("_health")) {
|
||||||
|
// Find the second-to-last underscore to get the drive name
|
||||||
|
let before_suffix = &metric_name[..suffix_pos];
|
||||||
|
if let Some(drive_start) = before_suffix.rfind('_') {
|
||||||
|
return Some(before_suffix[drive_start + 1..].to_string());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
@@ -410,12 +439,12 @@ impl Widget for SystemWidget {
|
|||||||
|
|
||||||
impl SystemWidget {
|
impl SystemWidget {
|
||||||
/// Render with scroll offset support
|
/// Render with scroll offset support
|
||||||
pub fn render_with_scroll(&mut self, frame: &mut Frame, area: Rect, scroll_offset: usize) {
|
pub fn render_with_scroll(&mut self, frame: &mut Frame, area: Rect, scroll_offset: usize, hostname: &str) {
|
||||||
let mut lines = Vec::new();
|
let mut lines = Vec::new();
|
||||||
|
|
||||||
// NixOS section
|
// NixOS section
|
||||||
lines.push(Line::from(vec![
|
lines.push(Line::from(vec![
|
||||||
Span::styled("NixOS:", Typography::widget_title())
|
Span::styled(format!("NixOS {}:", hostname), Typography::widget_title())
|
||||||
]));
|
]));
|
||||||
|
|
||||||
let build_text = self.nixos_build.as_deref().unwrap_or("unknown");
|
let build_text = self.nixos_build.as_deref().unwrap_or("unknown");
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "cm-dashboard-shared"
|
name = "cm-dashboard-shared"
|
||||||
version = "0.1.34"
|
version = "0.1.42"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
Reference in New Issue
Block a user