mirror of
https://github.com/kemko/nomad.git
synced 2026-01-03 08:55:43 +03:00
nomad: cleanup stats goroutines
This commit is contained in:
@@ -395,16 +395,20 @@ func (b *EvalBroker) Stats() *BrokerStats {
|
||||
}
|
||||
|
||||
// EmitStats is used to export metrics about the broker while enabled
|
||||
func (b *EvalBroker) EmitStats(period time.Duration) {
|
||||
func (b *EvalBroker) EmitStats(period time.Duration, stopCh chan struct{}) {
|
||||
for {
|
||||
<-time.After(period)
|
||||
select {
|
||||
case <-time.After(period):
|
||||
stats := b.Stats()
|
||||
metrics.SetGauge([]string{"nomad", "broker", "total_ready"}, float32(stats.TotalReady))
|
||||
metrics.SetGauge([]string{"nomad", "broker", "total_unacked"}, float32(stats.TotalUnacked))
|
||||
for sched, schedStats := range stats.ByScheduler {
|
||||
metrics.SetGauge([]string{"nomad", "broker", sched, "ready"}, float32(schedStats.Ready))
|
||||
metrics.SetGauge([]string{"nomad", "broker", sched, "unacked"}, float32(schedStats.Unacked))
|
||||
}
|
||||
|
||||
stats := b.Stats()
|
||||
metrics.SetGauge([]string{"nomad", "broker", "total_ready"}, float32(stats.TotalReady))
|
||||
metrics.SetGauge([]string{"nomad", "broker", "total_unacked"}, float32(stats.TotalUnacked))
|
||||
for sched, schedStats := range stats.ByScheduler {
|
||||
metrics.SetGauge([]string{"nomad", "broker", sched, "ready"}, float32(schedStats.Ready))
|
||||
metrics.SetGauge([]string{"nomad", "broker", sched, "unacked"}, float32(schedStats.Unacked))
|
||||
case <-stopCh:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -195,12 +195,16 @@ func (q *PlanQueue) Stats() *QueueStats {
|
||||
}
|
||||
|
||||
// EmitStats is used to export metrics about the broker while enabled
|
||||
func (q *PlanQueue) EmitStats(period time.Duration) {
|
||||
func (q *PlanQueue) EmitStats(period time.Duration, stopCh chan struct{}) {
|
||||
for {
|
||||
<-time.After(period)
|
||||
select {
|
||||
case <-time.After(period):
|
||||
stats := q.Stats()
|
||||
metrics.SetGauge([]string{"nomad", "plan", "queue_depth"}, float32(stats.Depth))
|
||||
|
||||
stats := q.Stats()
|
||||
metrics.SetGauge([]string{"nomad", "plan", "queue_depth"}, float32(stats.Depth))
|
||||
case <-stopCh:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -188,10 +188,10 @@ func NewServer(config *Config) (*Server, error) {
|
||||
go s.listen()
|
||||
|
||||
// Emit metrics for the eval broker
|
||||
go evalBroker.EmitStats(time.Second)
|
||||
go evalBroker.EmitStats(time.Second, s.shutdownCh)
|
||||
|
||||
// Emit metrics for the plan queue
|
||||
go planQueue.EmitStats(time.Second)
|
||||
go planQueue.EmitStats(time.Second, s.shutdownCh)
|
||||
|
||||
// Done
|
||||
return s, nil
|
||||
|
||||
Reference in New Issue
Block a user