Monitor class collects and aggregates metrics from all orchestrator components, provides periodic health checks, and emits real-time metrics snapshots.
Monitor Class
Constructor
Configuration for health checks and timeouts
Worker pool instance to monitor
Task queue instance to track
Configuration
Methods
start()
Starts the monitoring loop with periodic health checks and metrics emission.stop()
Stops the monitoring loop and clears all timers.getSnapshot()
Returns the current metrics snapshot.Complete metrics snapshot with current state
Callback Registration
The monitor supports various callbacks for event-driven monitoring:Usage Example
Metrics Collection
The monitor automatically collects:- Task statistics: Pending, running, completed, failed counts
- Worker statistics: Active workers, available capacity
- Token usage: Total tokens consumed across all LLM calls
- Cost tracking: Estimated USD cost based on token usage
- Merge statistics: Merge attempts, successes, conflict rate
- Finalization metrics: Build/test results from final sweep
Health Checks
Periodic health checks detect:- Worker timeouts: Workers that exceed
workerTimeoutthreshold - Empty diffs: Workers that complete with no file changes
- Suspicious tasks: Tasks with anomalous behavior patterns
Related
- Orchestrator — Main orchestrator factory
- Worker Pool — Worker lifecycle management
- Task Queue — Task priority queue