Repository navigation
feat(spored): Windows idle/metrics via PowerShell/quser (#77 stage 2) - #85
Merged
Merged
Conversation
Real implementations for the Windows sys_*.go leaves stubbed in Stage 1, so spored's idle detection works on Windows. Shells out to native tools (no WMI Go binding), mirroring the Linux exec approach: - CPU: cumulative idle/total counters from Win32_PerfRawData_PerfOS_Processor (_Total): PercentIdleTime + Timestamp_Sys100NS — monotonic, so the shared getCPUUsage delta math (100 - dIdle/dTotal*100) yields busy%. (The earlier LoadPercentage approach was non-cumulative and would have always read 0%/idle.) - Network: cumulative RX+TX via Get-NetAdapterStatistics. - Disk: cumulative bytes via Win32_PerfRawData_PerfDisk_PhysicalDisk(_Total). - Processes: Get-Process -Name. - Sessions: quser parsing (console + RDP), STATE=Active and IDLE TIME < 5 min; conservative on unknown idle formats (never falsely idle a busy desktop). - Port connections: Get-NetTCPConnection -State Established -LocalPort. - warnUsers: msg.exe; pre-stop: powershell -Command. Validated against live Windows 11 (build 26200) over SSH: all readers parse correctly and a two-sample CPU delta computed 7.6% busy on a mostly-idle box (matches observed load). quserIdleIsRecent has a unit test (windows-tagged). Deferred (not lifecycle-critical): pkg/agent/metrics.go observability collector still reads /proc and returns errors gracefully on Windows — that optional metrics-server source gets Windows sources in a later pass. Tracked in #77. GOOS=windows + GOOS=linux build clean; host tests + make check unchanged. Refs #77.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Summary
Stage 2 of Windows spored (#77): real implementations for the Windows
sys_*.goleaves stubbed in Stage 1, so idle detection actually works on Windows. Shells out to native tools (no WMI Go binding), mirroring the Linux exec approach.Win32_PerfRawData_PerfOS_Processor(_Total)—PercentIdleTime+Timestamp_Sys100NS, monotonic so the sharedgetCPUUsagedelta math yields busy%. (A first LoadPercentage approach was non-cumulative → would have always read 0%/idle; caught and fixed against live hardware.)Get-NetAdapterStatistics.Win32_PerfRawData_PerfDisk_PhysicalDisk(_Total).Get-Process -Name.quserparse (console + RDP),STATE=Activeand idle < 5 min; conservative on unknown formats (never falsely idle a busy desktop).Get-NetTCPConnection -State Established -LocalPort.msg.exe; pre-stop:powershell -Command.Validated on real Windows 11 (build 26200) over SSH
All readers parse correctly; a two-sample CPU delta computed 7.6% busy on a mostly-idle box (matches observed load).
quserIdleIsRecenthas a unit test.Deferred (not lifecycle-critical)
pkg/agent/metrics.go(optional observability collector source) still reads/procand returns errors gracefully on Windows; it gets Windows sources in a later pass (tracked in #77).GOOS=windows+GOOS=linuxbuild clean; host tests +make checkunchanged.Refs #77. Next: Stage 3 (Windows Service entrypoint), Stage 4 (installer + GoReleaser + launch wiring).