Skip to content

feat(spored): Windows idle/metrics via PowerShell/quser (#77 stage 2) - #85

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/77-windows-spored-stage2
Jun 8, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/77-windows-spored-stage2

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

Stage 2 of Windows spored (#77): real implementations for the Windows sys_*.go leaves 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.

  • CPU: cumulative idle/total from Win32_PerfRawData_PerfOS_Processor(_Total) — PercentIdleTime + Timestamp_Sys100NS, monotonic so the shared getCPUUsage delta math yields busy%. (A first LoadPercentage approach was non-cumulative → would have always read 0%/idle; caught and fixed against live hardware.)
  • Network: cumulative RX+TX via Get-NetAdapterStatistics.
  • Disk: cumulative bytes via Win32_PerfRawData_PerfDisk_PhysicalDisk(_Total).
  • Processes: Get-Process -Name.
  • Sessions: quser parse (console + RDP), STATE=Active and idle < 5 min; conservative on unknown formats (never falsely idle a busy desktop).
  • Ports: Get-NetTCPConnection -State Established -LocalPort.
  • warnUsers: 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). quserIdleIsRecent has a unit test.

Deferred (not lifecycle-critical)

pkg/agent/metrics.go (optional observability collector source) still reads /proc and returns errors gracefully on Windows; it gets Windows sources in a later pass (tracked in #77).

GOOS=windows + GOOS=linux build clean; host tests + make check unchanged.

Refs #77. Next: Stage 3 (Windows Service entrypoint), Stage 4 (installer + GoReleaser + launch wiring).

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.
@scttfrdmn
scttfrdmn merged commit c6c7c10 into main Jun 8, 2026
2 checks passed
@scttfrdmn
scttfrdmn deleted the feat/77-windows-spored-stage2 branch June 8, 2026 22:02
@codecov

codecov Bot commented Jun 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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.

1 participant