Skip to content

fix(api): support macOS hosts in server system stats monitoring - #645

Open
chbndrhnns wants to merge 1 commit into
oblien:mainfrom
chbndrhnns:fix/server-monitor-macos-support
Open

fix(api): support macOS hosts in server system stats monitoring#645
chbndrhnns wants to merge 1 commit into
oblien:mainfrom
chbndrhnns:fix/server-monitor-macos-support

Conversation

@chbndrhnns

Copy link
Copy Markdown
Contributor

Closes #608

Summary

When connecting a macOS (Darwin) host via SSH (e.g. a MacBook or Mac mini), the Server Overview page showed - for CPU, Memory, Disk, and Uptime.

The background metrics streaming endpoint (GET /system/monitor/stream) runs STATS_COMMAND on an interval over SSH to collect live host statistics. The command was hardcoded for Linux and relied on /proc/stat, /proc/meminfo, /proc/uptime, /proc/loadavg, and df -B1 /. On macOS:

  • /proc does not exist.
  • df -B1 fails with df: illegal option -- B.

This caused STATS_COMMAND to fail on Darwin hosts, preventing the stats SSE event from emitting valid JSON and leaving the frontend cards in a perpetual empty state (-).

Changes

  • Updated STATS_COMMAND in apps/api/src/modules/system/server-check.controller.ts to detect the OS via [ "$(uname -s)" = "Darwin" ]:
    • Darwin (macOS):
      • CPU & Load Average: Samples CPU utilization and load averages via iostat -c 2 (falling back to sysctl -n vm.loadavg for load averages if needed).
      • Memory: Probes total RAM via sysctl -n hw.memsize and available memory via vm_stat ((free + inactive + speculative) * pagesize).
      • Disk: Probes root filesystem via POSIX-standard df -Pk / (1024-byte blocks), computing total, used, and available bytes.
      • Uptime: Computes seconds since boot using sysctl -n kern.boottime and current timestamp.
    • Linux:
      • Continues to use /proc/stat, /proc/meminfo, /proc/uptime, /proc/loadavg, and POSIX df -Pk / with safe fallbacks.
  • Added unit test apps/api/test/modules/system/server-monitoring-command.test.ts verifying structural integrity and execution against the host.

Tests

  • Verified STATS_COMMAND execution on macOS (Darwin), confirming valid JSON output with all expected fields (cpu, memTotal, memUsed, memAvail, diskTotal, diskUsed, diskAvail, uptime, load1, load5, load15).
  • Added unit test in apps/api/test/modules/system/server-monitoring-command.test.ts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shows no system info for macbook

1 participant