Enqueing metrics only if they are not nil

This commit is contained in:
Diptanu Choudhury
2016-06-02 17:14:15 -04:00
parent a9f02036c7
commit 63dd00a2f3
2 changed files with 6 additions and 6 deletions

View File

@@ -1337,10 +1337,10 @@ func (c *Client) collectHostStats() {
c.logger.Printf("[DEBUG] client: error fetching host resource usage stats: %v", err)
continue
}
c.resourceUsageLock.RLock()
c.resourceUsage.Enqueue(ru)
c.resourceUsageLock.RUnlock()
if ru != nil {
c.resourceUsageLock.RLock()
c.resourceUsage.Enqueue(ru)
c.resourceUsageLock.RUnlock()
c.emitStats(ru)
}
next.Reset(c.config.StatsCollectionInterval)

View File

@@ -474,10 +474,10 @@ func (r *TaskRunner) collectResourceUsageStats() {
if err != nil {
r.logger.Printf("[DEBUG] client: error fetching stats of task %v: %v", r.task.Name, err)
}
r.resourceUsageLock.Lock()
r.resourceUsage.Enqueue(ru)
r.resourceUsageLock.Unlock()
if ru != nil {
r.resourceUsageLock.Lock()
r.resourceUsage.Enqueue(ru)
r.resourceUsageLock.Unlock()
r.emitStats(ru)
}
next.Reset(r.config.StatsCollectionInterval)