Skip to content

Commit

Permalink
Squelch logspam when unable to get disk usage stats
Browse files Browse the repository at this point in the history
To reproduce logspam:

```
$ docker plugin install --grant-all-permissions vieux/sshfs
$ nomad agent -dev
...
2017/08/25 17:09:03.282868 [WARN] client: error fetching host disk usage stats for /var/lib/docker/plugins/a8b4a69b07e5180f828d19e1e9e102ccc0e26f9c9939eaef85357260c30b20a7/rootfs/mnt/volumes: permission denied
... repeats every collection period ...
```
  • Loading branch information
schmichael committed Aug 28, 2017
1 parent 85a1899 commit 7a84cbe
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions client/stats/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ type HostStatsCollector struct {
hostStats *HostStats
hostStatsLock sync.RWMutex
allocDir string

// badParts is a set of partitions whose usage cannot be read; used to
// squelch logspam.
badParts map[string]struct{}
}

// NewHostStatsCollector returns a HostStatsCollector. The allocDir is passed in
Expand All @@ -83,6 +87,7 @@ func NewHostStatsCollector(logger *log.Logger, allocDir string) *HostStatsCollec
numCores: numCores,
logger: logger,
allocDir: allocDir,
badParts: make(map[string]struct{}),
}
return collector
}
Expand Down Expand Up @@ -134,9 +139,17 @@ func (h *HostStatsCollector) Collect() error {
for _, partition := range partitions {
usage, err := disk.Usage(partition.Mountpoint)
if err != nil {
if _, ok := h.badParts[partition.Mountpoint]; ok {
// already known bad, don't log again
continue
}

h.badParts[partition.Mountpoint] = struct{}{}
h.logger.Printf("[WARN] client: error fetching host disk usage stats for %v: %v", partition.Mountpoint, err)
continue
}
delete(h.badParts, partition.Mountpoint)

ds := h.toDiskStats(usage, &partition)
diskStats = append(diskStats, ds)
}
Expand Down

0 comments on commit 7a84cbe

Please sign in to comment.