Filter disk stats by filesystem type, for Darwin & FreeBSD
Tested on MacOS, not FreeBSD.
This commit is contained in:
parent
f1af559f11
commit
1a591f9828
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue