Filter mount points before stats are collected

fixes #440
This commit is contained in:
Cameron Sparr
2016-01-20 10:42:55 -07:00
parent d3925fe578
commit fc1aa7d3b4
5 changed files with 61 additions and 38 deletions

View File

@@ -9,7 +9,10 @@ import (
type DiskStats struct {
ps PS
// Legacy support
Mountpoints []string
MountPoints []string
}
func (_ *DiskStats) Description() string {
@@ -19,7 +22,7 @@ func (_ *DiskStats) Description() string {
var diskSampleConfig = `
# By default, telegraf gather stats for all mountpoints.
# Setting mountpoints will restrict the stats to the specified mountpoints.
# Mountpoints=["/"]
# mount_points = ["/"]
`
func (_ *DiskStats) SampleConfig() string {
@@ -27,25 +30,17 @@ func (_ *DiskStats) SampleConfig() string {
}
func (s *DiskStats) Gather(acc inputs.Accumulator) error {
disks, err := s.ps.DiskUsage()
// Legacy support:
if len(s.Mountpoints) != 0 {
s.MountPoints = s.Mountpoints
}
disks, err := s.ps.DiskUsage(s.MountPoints)
if err != nil {
return fmt.Errorf("error getting disk usage info: %s", err)
}
var restrictMpoints bool
mPoints := make(map[string]bool)
if len(s.Mountpoints) != 0 {
restrictMpoints = true
for _, mp := range s.Mountpoints {
mPoints[mp] = true
}
}
for _, du := range disks {
_, member := mPoints[du.Path]
if restrictMpoints && !member {
continue
}
tags := map[string]string{
"path": du.Path,
"fstype": du.Fstype,