Fix all remaining commands to use full paths
- Fix systemctl, du, df, uptime, ss, journalctl commands - Add sudo for du command (needed for directory access) - This should resolve all remaining command path issues in the service - Storage, backup, and system monitoring should now work properly
This commit is contained in:
@@ -138,7 +138,7 @@ impl BackupCollector {
|
||||
// Get systemctl status for backup service
|
||||
let status_output = timeout(
|
||||
timeout_duration,
|
||||
Command::new("systemctl")
|
||||
Command::new("/run/current-system/sw/bin/systemctl")
|
||||
.args([
|
||||
"show",
|
||||
&self.backup_service,
|
||||
@@ -179,7 +179,7 @@ impl BackupCollector {
|
||||
}
|
||||
|
||||
async fn get_last_backup_log_message(&self) -> Result<String, CollectorError> {
|
||||
let output = Command::new("journalctl")
|
||||
let output = Command::new("/run/current-system/sw/bin/journalctl")
|
||||
.args([
|
||||
"-u",
|
||||
&self.backup_service,
|
||||
@@ -210,7 +210,7 @@ impl BackupCollector {
|
||||
}
|
||||
|
||||
async fn get_backup_logs_for_failures(&self) -> Result<Option<DateTime<Utc>>, CollectorError> {
|
||||
let output = Command::new("journalctl")
|
||||
let output = Command::new("/run/current-system/sw/bin/journalctl")
|
||||
.args([
|
||||
"-u",
|
||||
&self.backup_service,
|
||||
|
||||
@@ -43,7 +43,7 @@ impl ServiceCollector {
|
||||
// Use more efficient systemctl command - just get the essential info
|
||||
let status_output = timeout(
|
||||
timeout_duration,
|
||||
Command::new("systemctl")
|
||||
Command::new("/run/current-system/sw/bin/systemctl")
|
||||
.args(["show", service, "--property=ActiveState,SubState,MainPID", "--no-pager"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
@@ -229,8 +229,8 @@ impl ServiceCollector {
|
||||
}
|
||||
|
||||
async fn get_directory_size(&self, path: &str) -> Result<f32, CollectorError> {
|
||||
let output = Command::new("du")
|
||||
.args(["-s", "-k", path]) // Use kilobytes instead of forcing GB
|
||||
let output = Command::new("sudo")
|
||||
.args(["/run/current-system/sw/bin/du", "-s", "-k", path]) // Use kilobytes instead of forcing GB
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output()
|
||||
@@ -258,7 +258,7 @@ impl ServiceCollector {
|
||||
}
|
||||
|
||||
async fn get_service_memory_limit(&self, service: &str) -> Result<f32, CollectorError> {
|
||||
let output = Command::new("systemctl")
|
||||
let output = Command::new("/run/current-system/sw/bin/systemctl")
|
||||
.args(["show", service, "--property=MemoryMax", "--no-pager"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
@@ -286,7 +286,7 @@ impl ServiceCollector {
|
||||
|
||||
|
||||
async fn get_disk_usage(&self) -> Result<DiskUsage, CollectorError> {
|
||||
let output = Command::new("df")
|
||||
let output = Command::new("/run/current-system/sw/bin/df")
|
||||
.args(["-BG", "--output=size,used,avail", "/"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
@@ -479,7 +479,7 @@ impl ServiceCollector {
|
||||
|
||||
async fn get_web_server_connections(&self) -> Option<String> {
|
||||
// Use simpler ss command with minimal output
|
||||
let output = Command::new("ss")
|
||||
let output = Command::new("/run/current-system/sw/bin/ss")
|
||||
.args(["-tn", "state", "established", "sport", ":80", "or", "sport", ":443"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
@@ -645,7 +645,7 @@ impl ServiceCollector {
|
||||
}
|
||||
|
||||
async fn get_nginx_config_from_systemd(&self) -> Option<String> {
|
||||
let output = Command::new("systemctl")
|
||||
let output = Command::new("/run/current-system/sw/bin/systemctl")
|
||||
.args(["show", "nginx", "--property=ExecStart", "--no-pager"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
|
||||
@@ -48,8 +48,8 @@ impl SmartCollector {
|
||||
|
||||
let command_result = timeout(
|
||||
timeout_duration,
|
||||
Command::new("smartctl")
|
||||
.args(["-a", "-j", &format!("/dev/{}", device)])
|
||||
Command::new("sudo")
|
||||
.args(["/run/current-system/sw/bin/smartctl", "-a", "-j", &format!("/dev/{}", device)])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.output(),
|
||||
@@ -132,7 +132,7 @@ impl SmartCollector {
|
||||
}
|
||||
|
||||
async fn get_drive_capacity(&self, device: &str) -> Result<f32, CollectorError> {
|
||||
let output = Command::new("lsblk")
|
||||
let output = Command::new("/run/current-system/sw/bin/lsblk")
|
||||
.args(["-J", "-o", "NAME,SIZE", &format!("/dev/{}", device)])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
@@ -204,7 +204,7 @@ impl SmartCollector {
|
||||
}
|
||||
|
||||
async fn get_disk_usage(&self) -> Result<DiskUsage, CollectorError> {
|
||||
let output = Command::new("df")
|
||||
let output = Command::new("/run/current-system/sw/bin/df")
|
||||
.args(["-BG", "--output=size,used,avail", "/"])
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
|
||||
@@ -21,7 +21,7 @@ impl SystemCollector {
|
||||
}
|
||||
|
||||
async fn get_cpu_load(&self) -> Result<(f32, f32, f32), CollectorError> {
|
||||
let output = Command::new("uptime")
|
||||
let output = Command::new("/run/current-system/sw/bin/uptime")
|
||||
.output()
|
||||
.await
|
||||
.map_err(|e| CollectorError::CommandFailed {
|
||||
|
||||
Reference in New Issue
Block a user