Handle multiple NFS device mounts

It's possible to mount an NFS share in multiple locations.
* Duplicates contain the same metric values, so they can be ignored.
* Update fixture.
This commit is contained in:
Ben Kochie 2017-01-24 13:26:24 +01:00
commit 5a6db5c8d2
2 changed files with 27 additions and 2 deletions

View file

@ -1,4 +1,4 @@
// Copyright 2016 The Prometheus Authors
// Copyright 2017 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
@ -15,8 +15,10 @@ package collector
import (
"fmt"
"sort"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"github.com/prometheus/procfs"
)
@ -493,6 +495,7 @@ func (c *mountStatsCollector) Update(ch chan<- prometheus.Metric) error {
if err != nil {
return fmt.Errorf("failed to parse mountstats: %v", err)
}
var deviceList []string
for _, m := range mounts {
// For the time being, only NFS statistics are available via this mechanism
@ -501,7 +504,14 @@ func (c *mountStatsCollector) Update(ch chan<- prometheus.Metric) error {
continue
}
c.updateNFSStats(ch, m.Device, stats)
sort.Strings(deviceList)
i := sort.SearchStrings(deviceList, m.Device)
if i < len(deviceList) && deviceList[i] == m.Device {
log.Debugf("Skipping duplicate device entry %q", m.Device)
} else {
deviceList = append(deviceList, m.Device)
c.updateNFSStats(ch, m.Device, stats)
}
}
return nil