Implement comprehensive monitoring improvements

- Add full email notifications with lettre and Stockholm timezone
- Add status persistence to prevent notification spam on restart
- Change nginx monitoring to check backend proxy_pass URLs instead of frontend domains
- Increase nginx site timeout to 10 seconds for backend health checks
- Fix cache intervals: disk (5min), backup (10min), systemd (30s), cpu/memory (5s)
- Remove rate limiting for immediate notifications on all status changes
- Store metric status in /var/lib/cm-dashboard/last-status.json
This commit is contained in:
2025-10-20 14:32:44 +02:00
parent ecaf3aedb5
commit 66a79574e0
5 changed files with 260 additions and 95 deletions

View File

@@ -595,8 +595,8 @@ impl SystemdCollector {
// Create HTTP client with timeouts (similar to legacy implementation)
let client = reqwest::blocking::Client::builder()
.timeout(Duration::from_secs(5))
.connect_timeout(Duration::from_secs(2))
.timeout(Duration::from_secs(10))
.connect_timeout(Duration::from_secs(10))
.redirect(reqwest::redirect::Policy::limited(10))
.build()?;
@@ -739,12 +739,9 @@ impl SystemdCollector {
while i < lines.len() {
let line = lines[i].trim();
if line.starts_with("server") && line.contains("{") {
debug!("Found server block at line {}", i);
if let Some(server_name) = self.parse_server_block(&lines, &mut i) {
debug!("Extracted server name: {}", server_name);
let url = format!("https://{}", server_name);
// Use the full domain as the site name for clarity
sites.push((server_name.clone(), url));
if let Some(proxy_url) = self.parse_server_block(&lines, &mut i) {
let site_name = proxy_url.replace("http://", "").replace("https://", "");
sites.push((site_name, proxy_url));
}
}
i += 1;
@@ -758,6 +755,7 @@ impl SystemdCollector {
fn parse_server_block(&self, lines: &[&str], start_index: &mut usize) -> Option<String> {
use tracing::debug;
let mut server_names = Vec::new();
let mut proxy_pass_url = None;
let mut has_redirect = false;
let mut i = *start_index + 1;
let mut brace_count = 1;
@@ -787,6 +785,17 @@ impl SystemdCollector {
}
}
// Extract proxy_pass URL (backend IP:port)
if trimmed.starts_with("proxy_pass") {
if let Some(url_part) = trimmed.strip_prefix("proxy_pass") {
let url_clean = url_part.trim().trim_end_matches(';');
if !url_clean.is_empty() {
proxy_pass_url = Some(url_clean.to_string());
debug!("Found proxy_pass in block: {}", url_clean);
}
}
}
// Check for redirects (skip redirect-only servers)
if trimmed.contains("return") && (trimmed.contains("301") || trimmed.contains("302")) {
has_redirect = true;
@@ -797,11 +806,12 @@ impl SystemdCollector {
*start_index = i - 1;
// Only return hostnames that are not redirects and have actual content
if !server_names.is_empty() && !has_redirect {
Some(server_names[0].clone())
} else {
None
if let Some(proxy_url) = proxy_pass_url {
if !has_redirect {
return Some(proxy_url);
}
}
None
}
}