Skip to content

Commit

Permalink
Handle multiple NFS device mounts
Browse files Browse the repository at this point in the history
It's possible to mount an NFS share in multiple locations.
* Duplicates contain the same metric values, so they can be ignored.
* Update fixture.
  • Loading branch information
SuperQ committed Jan 24, 2017
1 parent 8d4f36a commit 5a6db5c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
15 changes: 15 additions & 0 deletions collector/fixtures/proc/10/mountstats
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 12 additions & 2 deletions collector/mountstats_linux.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -15,8 +15,10 @@ package collector

import (
"fmt"
"sort"

"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/common/log"
"github.com/prometheus/procfs"
)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5a6db5c

Please sign in to comment.