resource
All checks were successful
Build Org Backend / build (push) Successful in 24s

This commit is contained in:
2026-06-26 14:45:13 +01:00
parent cebdf72635
commit 016b9dcd81
3 changed files with 109 additions and 27 deletions

View File

@@ -19,13 +19,14 @@ ZONE_MANIFEST_PATH=/home/zaine/master-folder/org-platform/zone/data/manifest.jso
ZONE_AUTHORING_URL=http://127.0.0.1:8765
ZONE_WATCHER_UNIT=watcher.service
ZONE_SCRIPTS_LOG_DIR=/home/zaine/logs
ZONE_RESOURCES_STORAGE_PATH=/
EMACS_RUN_DIR=/home/zaine
EMACS_RUN_LOG=/home/zaine/logs/emacs.log
COMBINED_RUN_LOG=/home/zaine/logs/combined.log
ADVENTURE_RESOURCES_FREE_DIR=/home/zaine
ADVENTURE_RESOURCES_FREE_LOG=/home/zaine/logs/adventure-resources.log
ADVENTURE_RESOURCES_FREE_COMMAND="/usr/bin/docker system prune -af"
ADVENTURE_RESOURCES_FREE_COMMAND="sudo -n sh -c 'sync; echo 3 > /proc/sys/vm/drop_caches' && /usr/bin/docker system prune -af && /usr/bin/docker builder prune -af"
GUACAMOLE_RUN_DIR=/home/zaine
GUACAMOLE_CONTAINER_NAME=guacamole
GUACAMOLE_START_LOG=/home/zaine/logs/guacamole-start.log

View File

@@ -85,7 +85,7 @@ public class BuildController {
@Value("${combined.run.log}") private String combinedRunLogFile;
@Value("${adventure.resources.free.dir:/home/zaine}") private String resourceFreeDirectory;
@Value("${adventure.resources.free.log:/home/zaine/logs/adventure-resources.log}") private String resourceFreeLogFile;
@Value("${adventure.resources.free.command:/usr/bin/docker system prune -af}") private String resourceFreeCommand;
@Value("${adventure.resources.free.command:sudo -n sh -c 'sync; echo 3 > /proc/sys/vm/drop_caches' && /usr/bin/docker system prune -af && /usr/bin/docker builder prune -af}") private String resourceFreeCommand;
@Value("${guacamole.run.dir:/home/zaine}") private String guacamoleRunDirectory;
@Value("${guacamole.container.name:guacamole}") private String guacamoleContainerName;
@Value("${guacamole.start.log:/home/zaine/logs/guacamole-start.log}") private String guacamoleStartLogFile;

View File

@@ -8,6 +8,8 @@ import java.io.RandomAccessFile;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -66,6 +68,8 @@ public class ZoneStatusService {
private final Path scriptsLogDir;
private final Path storagePath;
private final TimesheetService timesheetService;
private final BuildRunStateService buildRunState;
@@ -84,6 +88,8 @@ public class ZoneStatusService {
@Value("${zone.scripts.log.dir}") String scriptsLogDir,
@Value("${zone.resources.storage.path:/}") String storagePath,
TimesheetService timesheetService,
BuildRunStateService buildRunState) {
@@ -98,6 +104,8 @@ public class ZoneStatusService {
this.scriptsLogDir = Path.of(scriptsLogDir);
this.storagePath = Path.of(storagePath);
this.timesheetService = timesheetService;
this.buildRunState = buildRunState;
@@ -120,12 +128,85 @@ public class ZoneStatusService {
status.put("lastRuns", buildRunState.lastRunsSnapshot());
status.put("systemResources", fetchSystemResources());
status.put("timesheet", fetchTimesheetSummary());
return status;
}
private Map<String, Object> fetchSystemResources() {
Map<String, Object> resources = new LinkedHashMap<>();
resources.put("available", true);
resources.put("cpu", fetchCpu());
resources.put("memory", fetchMemory());
resources.put("storage", fetchStorage());
return resources;
}
private Map<String, Object> fetchCpu() {
Map<String, Object> cpu = new LinkedHashMap<>();
java.lang.management.OperatingSystemMXBean os =
java.lang.management.ManagementFactory.getOperatingSystemMXBean();
cpu.put("cores", os.getAvailableProcessors());
cpu.put("loadAverage", os.getSystemLoadAverage());
if (os instanceof com.sun.management.OperatingSystemMXBean sunOs) {
double load = sunOs.getCpuLoad();
if (load >= 0) {
cpu.put("usagePct", Math.round(load * 1000.0) / 10.0);
}
double processLoad = sunOs.getProcessCpuLoad();
if (processLoad >= 0) {
cpu.put("processUsagePct", Math.round(processLoad * 1000.0) / 10.0);
}
}
return cpu;
}
private Map<String, Object> fetchMemory() {
Map<String, Object> memory = new LinkedHashMap<>();
java.lang.management.OperatingSystemMXBean os =
java.lang.management.ManagementFactory.getOperatingSystemMXBean();
if (os instanceof com.sun.management.OperatingSystemMXBean sunOs) {
long total = sunOs.getTotalPhysicalMemorySize();
long free = sunOs.getFreePhysicalMemorySize();
long used = Math.max(0, total - free);
memory.put("totalBytes", total);
memory.put("freeBytes", free);
memory.put("usedBytes", used);
memory.put("usedPct", pct(used, total));
} else {
memory.put("available", false);
memory.put("message", "Physical memory stats unavailable");
}
return memory;
}
private Map<String, Object> fetchStorage() {
Map<String, Object> storage = new LinkedHashMap<>();
storage.put("path", storagePath.toString());
try {
FileStore store = Files.getFileStore(storagePath);
long total = store.getTotalSpace();
long usable = store.getUsableSpace();
long used = Math.max(0, total - usable);
storage.put("totalBytes", total);
storage.put("usableBytes", usable);
storage.put("usedBytes", used);
storage.put("usedPct", pct(used, total));
} catch (IOException ex) {
storage.put("available", false);
storage.put("message", ex.getMessage());
}
return storage;
}
private static double pct(long value, long total) {
if (total <= 0) return 0.0;
return Math.round((value * 1000.0) / total) / 10.0;
}
@SuppressWarnings("unchecked")