Skip to content

Commit

Permalink
Merge pull request #2090 from christoe/b-1680-more-resilient-disk-stats
Browse files Browse the repository at this point in the history
#1680: Continue after not being able to stat a mountpoint
  • Loading branch information
diptanu authored Dec 13, 2016
2 parents 80e9927 + c3df9dd commit ea92063
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func NewClient(cfg *config.Config, consulSyncer *consul.Syncer, logger *log.Logg
start: time.Now(),
connPool: nomad.NewPool(cfg.LogOutput, clientRPCCache, clientMaxStreams, tlsWrap),
logger: logger,
hostStatsCollector: stats.NewHostStatsCollector(),
hostStatsCollector: stats.NewHostStatsCollector(logger),
allocs: make(map[string]*AllocRunner),
blockedAllocations: make(map[string]*structs.Allocation),
allocUpdates: make(chan *structs.Allocation, 64),
Expand Down
8 changes: 6 additions & 2 deletions client/stats/host.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package stats

import (
"log"
"math"
"runtime"
"time"
Expand Down Expand Up @@ -56,15 +57,17 @@ type HostStatsCollector struct {
clkSpeed float64
numCores int
statsCalculator map[string]*HostCpuStatsCalculator
logger *log.Logger
}

// NewHostStatsCollector returns a HostStatsCollector
func NewHostStatsCollector() *HostStatsCollector {
func NewHostStatsCollector(logger *log.Logger) *HostStatsCollector {
numCores := runtime.NumCPU()
statsCalculator := make(map[string]*HostCpuStatsCalculator)
collector := &HostStatsCollector{
statsCalculator: statsCalculator,
numCores: numCores,
logger: logger,
}
return collector
}
Expand Down Expand Up @@ -116,7 +119,8 @@ func (h *HostStatsCollector) Collect() (*HostStats, error) {
for _, partition := range partitions {
usage, err := disk.Usage(partition.Mountpoint)
if err != nil {
return nil, err
h.logger.Printf("[WARN] client: error fetching host disk usage stats for %v: %v", partition.Mountpoint, err)
continue
}
ds := DiskStats{
Device: partition.Device,
Expand Down

0 comments on commit ea92063

Please sign in to comment.