Commit f765e82a authored by Diptanu Choudhury's avatar Diptanu Choudhury
Browse files

Stopping the metrics collector timers using defer and starting to collect host stats right away

parent 03c9d94a
Showing with 5 additions and 3 deletions
+5 -3
......@@ -1282,7 +1282,10 @@ func (c *Client) syncConsul() {
// collectHostStats collects host resource usage stats periodically
func (c *Client) collectHostStats() {
next := time.NewTimer(c.config.StatsCollectionInterval)
// Start collecting host stats right away and then keep collecting every
// collection interval
next := time.NewTimer(0)
defer next.Stop()
for {
select {
case <-next.C:
......@@ -1296,7 +1299,6 @@ func (c *Client) collectHostStats() {
c.resourceUsageLock.RUnlock()
next.Reset(c.config.StatsCollectionInterval)
case <-c.shutdownCh:
next.Stop()
return
}
}
......
......@@ -688,6 +688,7 @@ func (e *UniversalExecutor) collectPids() {
// Fire the timer right away when the executor starts from there on the pids
// are collected every scan interval
timer := time.NewTimer(0)
defer timer.Stop()
for {
select {
case <-timer.C:
......@@ -700,7 +701,6 @@ func (e *UniversalExecutor) collectPids() {
e.pidLock.Unlock()
timer.Reset(pidScanInterval)
case <-e.processExited:
timer.Stop()
return
}
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment