Fix export of stale device error metrics for unmounted filesystems

Instead of maintaining a counter metric for device errors in memory,
this change exports a gauge and uses const metrics to avoid leaking
metrics for unmounted filesystems.
This commit is contained in:
Tobias Schmidt 2017-03-22 21:48:18 -03:00
commit d290ea94b8
2 changed files with 34 additions and 19 deletions

View file

@ -46,13 +46,15 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) {
log.Debugf("Ignoring fs type: %s", labels.fsType)
continue
}
labelValues := []string{labels.device, labels.mountPoint, labels.fsType}
buf := new(syscall.Statfs_t)
err := syscall.Statfs(labels.mountPoint, buf)
if err != nil {
c.devErrors.WithLabelValues(labelValues...).Inc()
log.Debugf("Statfs on %s returned %s",
labels.mountPoint, err)
stats = append(stats, filesystemStats{
labels: labels,
deviceError: 1,
})
log.Errorf("Error on statfs() system call for %q: %s", labels.mountPoint, err)
continue
}
@ -82,11 +84,14 @@ func mountPointDetails() ([]filesystemLabels, error) {
defer file.Close()
filesystems := []filesystemLabels{}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
parts := strings.Fields(scanner.Text())
filesystems = append(filesystems, filesystemLabels{parts[0], parts[1], parts[2]})
filesystems = append(filesystems, filesystemLabels{
device: parts[0],
mountPoint: parts[1],
fsType: parts[2],
})
}
return filesystems, scanner.Err()
}