From a3c846b73e4b93a90c6c82b57f64958619b5bb31 Mon Sep 17 00:00:00 2001 From: subhachandrachandra Date: Fri, 21 Aug 2015 15:15:19 -0700 Subject: [PATCH 1/3] Fixed total memory reporting for Darwin systems. hw.memsize is reported as bytes instead of pages. --- plugins/system/ps/mem/mem_darwin.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/system/ps/mem/mem_darwin.go b/plugins/system/ps/mem/mem_darwin.go index 5d2ff7e3e..43da44d1d 100644 --- a/plugins/system/ps/mem/mem_darwin.go +++ b/plugins/system/ps/mem/mem_darwin.go @@ -53,7 +53,7 @@ func VirtualMemory() (*VirtualMemoryStat, error) { } ret := &VirtualMemoryStat{ - Total: parsed[0] * p, + Total: parsed[0], Free: parsed[1] * p, } From 13ee9ff37be54226cf23bd44b34016be7db6d38f Mon Sep 17 00:00:00 2001 From: subhachandrachandra Date: Fri, 21 Aug 2015 16:08:54 -0700 Subject: [PATCH 2/3] Fixed memory reporting for Linux systems /proc/meminfo reports memory in KiloBytes and so needs a multiplier of 1024 instead of 1000. The kernel reports in terms of pages and the proc filesystem is left shifting by 2 for 4KB pages to get KB. Since this is a binary shift, Bytes will need to shift by 10 and so get multiplied by 1024. From the kernel code. PAGE_SHIFT = 12 for 4KB pages "MemTotal: %8lu kB\n", K(i.totalram) --- plugins/system/ps/mem/mem_linux.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/plugins/system/ps/mem/mem_linux.go b/plugins/system/ps/mem/mem_linux.go index a0505b5f5..42a49a2b6 100644 --- a/plugins/system/ps/mem/mem_linux.go +++ b/plugins/system/ps/mem/mem_linux.go @@ -30,17 +30,17 @@ func VirtualMemory() (*VirtualMemoryStat, error) { } switch key { case "MemTotal": - ret.Total = t * 1000 + ret.Total = t * 1024 case "MemFree": - ret.Free = t * 1000 + ret.Free = t * 1024 case "Buffers": - ret.Buffers = t * 1000 + ret.Buffers = t * 1024 case "Cached": - ret.Cached = t * 1000 + ret.Cached = t * 1024 case "Active": - ret.Active = t * 1000 + ret.Active = t * 1024 case "Inactive": - ret.Inactive = t * 1000 + ret.Inactive = t * 1024 } } ret.Available = ret.Free + ret.Buffers + ret.Cached From e6ea09f4825d073094eec6763716923b478876ae Mon Sep 17 00:00:00 2001 From: subhachandrachandra Date: Wed, 7 Oct 2015 14:42:11 -0700 Subject: [PATCH 3/3] 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