Skip to content

Feature/observer and polish#8

Merged
HackStrix merged 2 commits intomainfrom
feature/observer-and-polish
Mar 13, 2026
Merged

Feature/observer and polish#8
HackStrix merged 2 commits intomainfrom
feature/observer-and-polish

Conversation

@HackStrix
Copy link
Owner

This pull request introduces host-level resource monitoring to the pool, allowing users to observe not just pool state (workers, sessions) but also the underlying machine's memory and CPU idle percentage. The new functionality is implemented in a cross-platform way: on Linux, it reads from /proc files, while on other platforms it returns zeroed values. Documentation and tests are included, and several minor improvements and clarifications were made to the codebase and comments.

Host resource monitoring

  • Added the observer subpackage, which provides the PollNodeStats() function to sample total/available memory and CPU idle percentage on Linux (returns zeroed values on other platforms). (observer/observer.go, observer/observer_linux.go, observer/observer_unsupported.go) [1] [2] [3]
  • Integrated host-level stats into the pool: PoolStats now includes a Node field (of type observer.NodeStats), populated by calling observer.PollNodeStats() in Pool.Stats(). (pool.go) [1] [2] [3]
  • Updated the README with documentation and usage examples for the new monitoring features, including caveats about measurement latency and cross-platform behavior. (README.md)

Testing and code quality

  • Added a test for PollNodeStats() that checks for correct values and platform-specific behavior. (observer/observer_test.go)
  • Improved test pool setup to avoid goroutine leaks by wiring context cancellation properly. (pool_test.go) [1] [2]

Minor improvements

  • Clarified log message in release to indicate when a worker is already evicted (e.g., due to crash or health check). (pool.go)
  • Improved comments in Shutdown to clarify the purpose of signals sent during shutdown. (pool.go)

- Fix misleading log in release(): invalid/evicted workers now log
  'already evicted, discarding' instead of 'returned to pool'
- Fix newTestPool in pool_test.go: wire ctx/cancel so addWorker
  goroutines (triggered by maybeScaleUp) don't panic on nil p.ctx;
  register t.Cleanup(cancel) to prevent goroutine leaks
- Document Shutdown(): clarify that p.cancel() and close(p.done) are
  intentionally distinct — cancel kills in-flight factory.Spawn calls,
  done stops healthCheckLoop and runTTLSweep
observer/observer.go        — NodeStats struct + PollNodeStats() public API
observer/observer_linux.go  — Linux impl: /proc/meminfo (RAM) + /proc/stat
                              (CPU idle, two samples 100ms apart)
observer/observer_unsupported.go — zero-valued stub for non-Linux builds
observer/observer_test.go   — cross-platform test (zero on darwin, live on linux)

pool.go: extend PoolStats with Node observer.NodeStats field; wire
PollNodeStats() into Pool.Stats(). On Linux Stats() now blocks ~100ms
to measure CPU idle — documented in godoc and README.

README.md: add Monitoring section showing Stats() output with Node field
@HackStrix HackStrix merged commit 253bb3d into main Mar 13, 2026
7 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.

1 participant