Fix service discovery to show all configured services regardless of state
All checks were successful
Build and Release / build-and-release (push) Successful in 2m7s
All checks were successful
Build and Release / build-and-release (push) Successful in 2m7s
Changed service discovery from 'systemctl list-units --all' to 'systemctl list-unit-files' to ensure ALL service unit files are discovered, including services that have never been started. Changes: - Updated systemctl command to use list-unit-files instead of list-units --all - Modified parsing logic to handle unit file format (2 fields vs 4 fields) - Set placeholder values in discovery cache, actual runtime status fetched during collection - This ensures all configured services (like inactive ARK servers) appear in dashboard The issue was that list-units --all only shows services systemd has loaded/attempted to load, but list-unit-files shows ALL service unit files regardless of their runtime state.
This commit is contained in:
@@ -136,11 +136,10 @@ impl SystemdCollector {
|
||||
/// Auto-discover interesting services to monitor (internal version that doesn't update state)
|
||||
fn discover_services_internal(&self) -> Result<(Vec<String>, std::collections::HashMap<String, ServiceStatusInfo>)> {
|
||||
debug!("Starting systemd service discovery with status caching");
|
||||
// Get all services (includes inactive, running, failed - everything)
|
||||
// Get all service unit files (includes services that have never been started)
|
||||
let units_output = Command::new("systemctl")
|
||||
.arg("list-units")
|
||||
.arg("list-unit-files")
|
||||
.arg("--type=service")
|
||||
.arg("--all")
|
||||
.arg("--no-pager")
|
||||
.arg("--plain")
|
||||
.output()?;
|
||||
@@ -162,23 +161,20 @@ impl SystemdCollector {
|
||||
|
||||
for line in units_str.lines() {
|
||||
let fields: Vec<&str> = line.split_whitespace().collect();
|
||||
if fields.len() >= 4 && fields[0].ends_with(".service") {
|
||||
if fields.len() >= 2 && fields[0].ends_with(".service") {
|
||||
let service_name = fields[0].trim_end_matches(".service");
|
||||
let unit_file_state = fields.get(1).unwrap_or(&"unknown").to_string();
|
||||
|
||||
// Extract status information from systemctl list-units output
|
||||
let load_state = fields.get(1).unwrap_or(&"unknown").to_string();
|
||||
let active_state = fields.get(2).unwrap_or(&"unknown").to_string();
|
||||
let sub_state = fields.get(3).unwrap_or(&"unknown").to_string();
|
||||
|
||||
// Cache the status information
|
||||
// For unit files, we don't have runtime status info yet - will be fetched individually
|
||||
// Set placeholder values for status cache (actual status will be fetched when collecting metrics)
|
||||
status_cache.insert(service_name.to_string(), ServiceStatusInfo {
|
||||
load_state: load_state.clone(),
|
||||
active_state: active_state.clone(),
|
||||
sub_state: sub_state.clone(),
|
||||
load_state: "unknown".to_string(), // Will be determined when we check individual status
|
||||
active_state: "unknown".to_string(), // Will be determined when we check individual status
|
||||
sub_state: unit_file_state.clone(), // Use unit file state as placeholder
|
||||
});
|
||||
|
||||
all_service_names.insert(service_name.to_string());
|
||||
debug!("Parsed service: {} (load:{}, active:{}, sub:{})", service_name, load_state, active_state, sub_state);
|
||||
debug!("Found service unit file: {} (file_state: {})", service_name, unit_file_state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user