This commit is contained in:
2025-10-12 18:03:32 +02:00
parent 49aee702f2
commit b226217ba4
7 changed files with 28 additions and 67 deletions

View File

@@ -514,7 +514,6 @@ impl ServiceCollector {
let should_update = self.should_update_description(service).await;
if should_update {
tracing::debug!("Service {} updating description (throttle check passed)", service);
if let Some(new_description) = self.get_service_description(service).await {
// Update cache
let mut cache = self.description_cache.lock().await;
@@ -546,16 +545,11 @@ impl ServiceCollector {
let should_update = (now + service_offset) % update_interval == 0;
if !should_update {
let next_update = update_interval - ((now + service_offset) % update_interval);
tracing::trace!("Service {} throttled, next update in {} seconds", service, next_update);
}
should_update
}
async fn get_service_description(&self, service: &str) -> Option<Vec<String>> {
tracing::debug!("Getting description for service: {}", service);
let result = match service {
"sshd" | "ssh" => self.get_ssh_active_users().await.map(|s| vec![s]),
"nginx" => self.get_nginx_sites().await,
@@ -566,11 +560,6 @@ impl ServiceCollector {
_ => None,
};
match &result {
Some(descriptions) => tracing::info!("Service {} got {} descriptions: {:?}", service, descriptions.len(), descriptions),
None => tracing::debug!("Service {} got no description", service),
}
result
}
@@ -712,16 +701,11 @@ impl ServiceCollector {
}
async fn get_nginx_sites(&self) -> Option<Vec<String>> {
tracing::debug!("Starting nginx site detection");
// Get the actual nginx config file path from systemd (NixOS uses custom config)
let config_path = match self.get_nginx_config_from_systemd().await {
Some(path) => {
tracing::debug!("Found nginx config path from systemd: {}", path);
path
}
Some(path) => path,
None => {
tracing::warn!("Could not find nginx config path from systemd, using default");
// Fallback to default nginx -T
match Command::new("sudo")
.args(["nginx", "-T"])
@@ -732,15 +716,12 @@ impl ServiceCollector {
{
Ok(output) => {
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
tracing::warn!("nginx -T failed with status {}: {}", output.status, stderr);
return None;
}
let config = String::from_utf8_lossy(&output.stdout);
return self.parse_nginx_config(&config).await;
}
Err(e) => {
tracing::warn!("Failed to execute sudo nginx -T: {}", e);
Err(_) => {
return None;
}
}
@@ -756,20 +737,16 @@ impl ServiceCollector {
.await
{
Ok(output) => output,
Err(e) => {
tracing::warn!("Failed to execute sudo nginx -T -c {}: {}", config_path, e);
Err(_) => {
return None;
}
};
if !output.status.success() {
let stderr = String::from_utf8_lossy(&output.stderr);
tracing::warn!("nginx -T failed with status {}: {}", output.status, stderr);
return None;
}
let config = String::from_utf8_lossy(&output.stdout);
tracing::debug!("Got nginx config, {} bytes", config.len());
self.parse_nginx_config(&config).await
}
@@ -824,7 +801,6 @@ impl ServiceCollector {
i += 1;
}
tracing::info!("Found {} potential sites, checking accessibility", sites.len());
// Check which sites are actually accessible
let mut accessible_sites = Vec::new();
@@ -837,10 +813,7 @@ impl ServiceCollector {
// Limit to reasonable number
accessible_sites.truncate(15);
tracing::info!("Final accessible nginx sites: {:?}", accessible_sites);
if accessible_sites.is_empty() {
tracing::warn!("No accessible nginx sites found");
None
} else {
Some(accessible_sites)
@@ -913,7 +886,6 @@ impl ServiceCollector {
response.contains(" 302 ") ||
response.contains(" 403 ") // Some sites return 403 but are still "accessible"
) {
tracing::debug!("Site {} accessible via {}", hostname, scheme);
return true;
}
}
@@ -921,7 +893,6 @@ impl ServiceCollector {
}
}
tracing::debug!("Site {} not accessible", hostname);
false
}
}