Skip to content

host: read CPU on Windows; show n/a for the load averages it lacks - #144

Merged
T-Crypt merged 2 commits into
mainfrom
T-Crypt/host-cpu-windows
Oct 22, 2026
Merged

T-Crypt merged 2 commits into
mainfrom
T-Crypt/host-cpu-windows

Conversation

@T-Crypt

@T-Crypt T-Crypt commented Oct 22, 2026

Copy link
Copy Markdown
Owner

Fixes #139, reported by @azrael-229.

Problem

On Windows, host.Reader.Read() filled RAM and swap but left CPU and the load averages at 0, and still marked the reading supported. The harbor's machine meter drew CPU 0% and LOAD 0 0 0 as live readings, even with the GPU at 91%.

Change

  • CPU on Windows comes from GetSystemTimes (kernel32, loaded by name like GlobalMemoryStatusEx; x/sys v0.48.0 does not wrap it). It is usage over the interval since the last read. Kernel time includes idle, so total = kernel + user.
  • One formula: cpuPct is pure and shared, so Linux and Windows compute usage the same way.
  • Load becomes *[3]float64 with omitempty in host.Stats and proto.Host. Linux sets it; Windows leaves it out of the JSON instead of sending zeros. An API reader that decodes into [3]float64 still gets zeros, as before.
  • The harbor's LOAD row and berth status show n/a when load is absent.

Proof

  • TestCPUPct (portable table): the first read, half busy, all idle, all busy, counters going backwards, no time passing.
  • TestLoadUnmeasuredIsAbsent: no "load" key when it is unmeasured, the literal array when it is measured. Both fail to build on main.
  • TestStatsWindows (runs in the Windows CI job): Load is nil, and CPU over a 200 ms busy loop is a reading in (0, 100].
  • Linux TestRead still reads /proc/loadavg.
  • The harbor's load row, run in Node: absent gives "n/a", measured gives "1.50 0.75 0.25". On main, a Windows node showed 0.00 0.00 0.00.
  • build, gofmt, vet, go test ./..., Windows build and vet, golangci-lint (0 issues).

…ne of

Windows filled RAM and swap but left CPU and the load averages at 0 while
marking the reading supported, so the harbor drew CPU 0% and LOAD 0 0 0 as
live. CPU now comes from GetSystemTimes over the interval since the last
read, through the same formula Linux uses. Load becomes a pointer that is
left out of the JSON where the platform has no load averages, and the
harbor and berth status show n/a for it.
@T-Crypt
T-Crypt merged commit 8797895 into main Oct 22, 2026
2 checks passed
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.

[windows] host stats: CPU and load averages are never read; the UI shows them as measured zeros

1 participant