summaryrefslogtreecommitdiff
path: root/MACOS.md
blob: ba6efdad2b55e95b357040ab3df9b60b135a175c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
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)