Filter disk stats by filesystem type, for Darwin & FreeBSD

Tested on MacOS, not FreeBSD.
This commit is contained in:
Simon Fraser 2015-07-30 17:32:40 +01:00
parent f1af559f11
commit 1a591f9828
2 changed files with 22 additions and 4 deletions

View File

@ -9,9 +9,14 @@ import (
"github.com/influxdb/telegraf/plugins/system/ps/common"
)
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
func DiskPartitions(fstypes []string) ([]DiskPartitionStat, error) {
var ret []DiskPartitionStat
set := make(map[string]struct{}, len(fstypes))
for _, s := range fstypes {
set[s] = struct{}{}
}
count, err := Getfsstat(nil, MntWait)
if err != nil {
return ret, err
@ -74,8 +79,11 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
Fstype: common.IntToString(stat.Fstypename[:]),
Opts: opts,
}
_, ok := set[d.Fstype]
if ok || len(fstypes) == 0 {
ret = append(ret, d)
}
}
return ret, nil
}

View File

@ -18,9 +18,14 @@ const (
KernDevstatAll = 772
)
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
func DiskPartitions(fstypes []string) ([]DiskPartitionStat, error) {
var ret []DiskPartitionStat
set := make(map[string]struct{}, len(fstypes))
for _, s := range fstypes {
set[s] = struct{}{}
}
// get length
count, err := syscall.Getfsstat(nil, MNT_WAIT)
if err != nil {
@ -87,9 +92,14 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
Fstype: common.IntToString(stat.Fstypename[:]),
Opts: opts,
}
_, ok := set[d.Fstype]
if ok || len(fstypes) == 0 {
ret = append(ret, d)
}
}
return ret, nil
}