diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-14 12:32:54 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-14 12:33:40 +0200 |
| commit | 50733fe4ebac28136144d5b85721ee5fd0b7850a (patch) | |
| tree | 6546058f9ea41b81502e833c50ab32ef96718ec8 /MACOS.md | |
| parent | 52e70e2a065da95cdfcf7d370173003d3ce395cd (diff) | |
Add macOS support with automatic window activation
This commit adds full macOS support for loadbars, allowing it to run
natively on macOS for both localhost monitoring and remote Linux hosts.
Key changes:
- Embed both Linux and Darwin monitoring scripts in the binary
- Auto-detect localhost OS and use appropriate script
- Darwin script uses native macOS tools (sysctl, vm_stat, netstat, iostat)
- Remote hosts always use Linux script (assumes /proc filesystem)
- Automatic window activation on macOS using build tags
- No external helper scripts needed
The binary now works seamlessly on macOS:
- localhost monitoring uses macOS-specific commands
- Remote Linux hosts work via SSH with Linux script
- SDL window automatically comes to foreground on macOS
- Cross-platform build with single binary for all scenarios
Technical implementation:
- internal/collector/script.go: Embeds both scripts
- internal/collector/loadbars-remote-darwin.sh: macOS monitoring
- internal/collector/loadbars-remote.sh: Linux monitoring (copied from scripts/)
- internal/display/activate_darwin.go: macOS window activation
- internal/display/activate.go: No-op for other platforms
- Updated README.md with macOS installation instructions
- Added MACOS.md with detailed macOS documentation
Diffstat (limited to 'MACOS.md')
| -rw-r--r-- | MACOS.md | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/MACOS.md b/MACOS.md new file mode 100644 index 0000000..ba6efda --- /dev/null +++ b/MACOS.md @@ -0,0 +1,71 @@ +# macOS Support for Loadbars + +## What was implemented + +Loadbars now fully supports macOS with automatic window activation built into the binary. + +### Changes made: + +1. **Script embedding** - Both Linux and Darwin monitoring scripts are embedded in the binary +2. **OS detection** - Automatically uses the correct script based on the host: + - `localhost` on macOS → Darwin script (sysctl, vm_stat, netstat, iostat) + - `localhost` on Linux → Linux script (/proc filesystem) + - All remote hosts → Linux script (assumes remote servers are Linux) +3. **Window activation** - macOS-specific code automatically brings SDL window to foreground + - Uses build tags (`activate_darwin.go` and `activate.go`) + - No external helper script needed + +## Usage on macOS + +Simply run the binary directly: + +```bash +# Monitor localhost +./loadbars --showcores --showmem --shownet + +# Monitor remote Linux servers +./loadbars server1.example.com server2.example.com --showcores + +# Monitor both localhost and remotes +./loadbars localhost server1.example.com server2.example.com --showcores +``` + +The window will automatically appear in the foreground. + +## Building on macOS + +Requirements: +```bash +brew install sdl2 +``` + +Build: +```bash +mage build +# or +go build -o loadbars ./cmd/loadbars +``` + +## Technical details + +### Script selection logic +- `internal/collector/script.go` - Embeds both scripts +- `internal/collector/collector.go` - Selects script based on host: + - For localhost: checks if `/proc` exists to determine Linux vs macOS + - For remote hosts: always uses Linux script + +### Window activation +- `internal/display/activate_darwin.go` - macOS-specific activation using `open -a` +- `internal/display/activate.go` - No-op for other platforms +- Called automatically after SDL window creation + +### Darwin monitoring script +- Uses macOS native tools: `sysctl`, `vm_stat`, `netstat -ibn`, `iostat` +- Outputs same protocol format as Linux script (M LOADAVG, M MEMSTATS, etc.) +- Limitations: No per-core CPU stats on macOS (iostat limitation) + +## Known limitations + +- Remote macOS hosts are not supported (assumes all remote hosts are Linux) +- macOS script doesn't provide per-core CPU statistics (iostat limitation) +- Swap usage on macOS always shows 0 (macOS uses compressed memory differently) |
