Browse Source

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.
pull/434/head
Ben Kochie 8 years ago
parent
commit
5a6db5c8d2
  1. 15
      collector/fixtures/proc/10/mountstats
  2. 14
      collector/mountstats_linux.go

15
collector/fixtures/proc/10/mountstats

@ -17,3 +17,18 @@ device 192.168.1.1:/srv/test mounted on /mnt/nfs/test with fstype nfs4 statvers=
READ: 1298 1298 0 207680 1210292152 6 79386 79407
WRITE: 0 0 0 0 0 0 0 0
device 192.168.1.1:/srv/test mounted on /mnt/nfs/test-dupe with fstype nfs4 statvers=1.1
opts: rw,vers=4.0,rsize=1048576,wsize=1048576,namlen=255,acregmin=3,acregmax=60,acdirmin=30,acdirmax=60,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.1.5,local_lock=none
age: 13968
caps: caps=0xfff7,wtmult=512,dtsize=32768,bsize=0,namlen=255
nfsv4: bm0=0xfdffafff,bm1=0xf9be3e,bm2=0x0,acl=0x0,pnfs=not configured
sec: flavor=1,pseudoflavor=1
events: 52 226 0 0 1 13 398 0 0 331 0 47 0 0 77 0 0 77 0 0 0 0 0 0 0 0 0
bytes: 1207640230 0 0 0 1210214218 0 295483 0
RPC iostats version: 1.0 p/v: 100003/4 (nfs)
xprt: tcp 832 0 1 0 11 6428 6428 0 12154 0 24 26 5726
per-op statistics
NULL: 0 0 0 0 0 0 0 0
READ: 1298 1298 0 207680 1210292152 6 79386 79407
WRITE: 0 0 0 0 0 0 0 0

14
collector/mountstats_linux.go

@ -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

Loading…
Cancel
Save