From e6ea09f4825d073094eec6763716923b478876ae Mon Sep 17 00:00:00 2001 From: subhachandrachandra Date: Wed, 7 Oct 2015 14:42:11 -0700 Subject: [PATCH] Added Mountpoints and SkipInodeUsage options to the Disk plugin to control which mountpoint stats get reported for and to skip inode stats. --- plugins/system/disk.go | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/plugins/system/disk.go b/plugins/system/disk.go index 74348bdbe..cac219757 100644 --- a/plugins/system/disk.go +++ b/plugins/system/disk.go @@ -8,13 +8,27 @@ import ( type DiskStats struct { ps PS + + Mountpoints []string + SkipInodeUsage bool } func (_ *DiskStats) Description() string { return "Read metrics about disk usage by mount point" } -func (_ *DiskStats) SampleConfig() string { return "" } +var diskSampleConfig = ` + # By default, telegraf gather stats for all mountpoints and for inodes. + # Setting mountpoints will restrict the stats to the specified ones. + # mountpoints. + # Mountpoints=["/"] + # Setting SkipInodeUsage will skip the reporting of inode stats. + # SkipInodeUsage=true +` + +func (_ *DiskStats) SampleConfig() string { + return diskSampleConfig +} func (s *DiskStats) Gather(acc plugins.Accumulator) error { disks, err := s.ps.DiskUsage() @@ -22,7 +36,16 @@ func (s *DiskStats) Gather(acc plugins.Accumulator) error { return fmt.Errorf("error getting disk usage info: %s", err) } + mPoints := make(map[string]bool) + for _, mp := range s.Mountpoints { + mPoints[mp] = true + } + for _, du := range disks { + _, member := mPoints[ du.Path ] + if !member { + continue + } tags := map[string]string{ "path": du.Path, "fstype": du.Fstype, @@ -30,9 +53,11 @@ func (s *DiskStats) Gather(acc plugins.Accumulator) error { acc.Add("total", du.Total, tags) acc.Add("free", du.Free, tags) acc.Add("used", du.Total-du.Free, tags) - acc.Add("inodes_total", du.InodesTotal, tags) - acc.Add("inodes_free", du.InodesFree, tags) - acc.Add("inodes_used", du.InodesTotal-du.InodesFree, tags) + if !s.SkipInodeUsage { + acc.Add("inodes_total", du.InodesTotal, tags) + acc.Add("inodes_free", du.InodesFree, tags) + acc.Add("inodes_used", du.InodesTotal-du.InodesFree, tags) + } } return nil