Skip to content

Add cross-platform health check fallbacks (#1)#17

Open
xudexing19920829 wants to merge 15 commits into
weilixiong:mainfrom
xudexing19920829:feat/cross-platform-health-check
Open

Add cross-platform health check fallbacks (#1)#17
xudexing19920829 wants to merge 15 commits into
weilixiong:mainfrom
xudexing19920829:feat/cross-platform-health-check

Conversation

@xudexing19920829

Copy link
Copy Markdown

Add cross-platform health check fallbacks

Fixes: #1

Changes

check_memory_usage() now has a cross-platform fallback:

  • Primary path (Linux): Reads /proc/meminfo as before — no change in behavior
  • macOS fallback (_check_memory_fallback): Uses sysctl -n hw.memsize for total memory and vm_stat for page-level available memory. Calculates used percentage and returns same (status, detail, pct) tuple
  • Linux fallback (no /proc): Uses free -b command
  • Returns "WARNING" with descriptive message if no method works

check_load_average() now has a cross-platform fallback:

  • Primary path (Linux): Reads /proc/loadavg as before — no change
  • Fallback (_check_load_average_fallback): Uses os.getloadavg() which works on macOS, Linux, and BSD. Returns same tuple format with load percentages
  • Returns "WARNING" on platforms without getloadavg (Windows)

Additional improvements:

  • Added platform.system() to health check output for visibility
  • Platform info included in JSON output
  • Print report now shows platform

Acceptance criteria

  • check_memory_usage() keeps existing /proc/meminfo path on Linux
  • ✅ macOS fallback returns meaningful memory status via sysctl/vm_stat
  • check_load_average() keeps existing /proc/loadavg path where available
  • ✅ Falls back to os.getloadavg() on non-Linux Unix systems
  • ✅ JSON and text output remain backward compatible
  • ✅ All fallbacks return same (status, detail, value) tuple format

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.

1 participant