A metric is a measured value describing a worker machine’s current state or workload. A manager polls these values to decide where an incoming task can fit, much like assigning new work to the least constrained available worker. section 1.5.5 section 6.0
Useful worker metrics match the resources tasks request: CPU usage as a percentage; total and available memory; and total and available disk space. The worker also tracks its task count, giving the manager another view of current work. section 6.1 section 6.4
Collect metrics as a small pipeline:
- Read machine-state data. On Linux, /proc exposes CPU, memory, disk, process, and load information as files; /proc/stat and /proc/meminfo supply relevant inputs. section 6.2
- Refresh stored statistics regularly. A worker can call GetStats, copy in TaskCount, and pause before the next collection cycle. section 6.4
- Serve the latest snapshot. A GET /stats handler returns the worker’s stored statistics as JSON, alongside task-operation routes. section 6.4 section 6.6
A polling-friendly worker endpoint
A collector updates the worker’s Stats field every 15 seconds, then GET /stats responds with that snapshot. The interval is intentionally slow enough to observe; a busier production system would need more real-time collection. section 6.4
Listing 6.12 The worker’s new CollectStats() method
func (w *Worker) CollectStats() {
for {
log.Println("Collecting stats")
w.Stats = GetStats()
w.Stats.TaskCount = w.TaskCount
time.Sleep(15 * time.Second)
}
}
The collection loop makes the metric lifecycle explicit: sample machine statistics, add task count, store the snapshot, then wait before sampling again. section 6.4
The low-level Linux parsing can be delegated to goprocinfo, which gathers data from /proc. This keeps the worker focused on collecting, retaining, and exposing a scheduling-oriented summary rather than reproducing filesystem parsing. section 6.6















