Repository navigation
host: read CPU on Windows; show n/a for the load averages it lacks - #144
Merged
Merged
Conversation
…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.
# Conflicts: # CHANGELOG.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
GetSystemTimes(kernel32, loaded by name likeGlobalMemoryStatusEx;x/sysv0.48.0 does not wrap it). It is usage over the interval since the last read. Kernel time includes idle, so total = kernel + user.cpuPctis pure and shared, so Linux and Windows compute usage the same way.*[3]float64withomitemptyinhost.Statsandproto.Host. Linux sets it; Windows leaves it out of the JSON instead of sending zeros. An API reader that decodes into[3]float64still gets zeros, as before.berth statusshown/awhen 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):Loadis nil, and CPU over a 200 ms busy loop is a reading in (0, 100].TestReadstill reads/proc/loadavg."n/a", measured gives"1.50 0.75 0.25". On main, a Windows node showed0.00 0.00 0.00.go test ./..., Windows build and vet, golangci-lint (0 issues).