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"
|
"github.com/influxdb/telegraf/plugins/system/ps/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
|
func DiskPartitions(fstypes []string) ([]DiskPartitionStat, error) {
|
||||||
var ret []DiskPartitionStat
|
var ret []DiskPartitionStat
|
||||||
|
|
||||||
|
set := make(map[string]struct{}, len(fstypes))
|
||||||
|
for _, s := range fstypes {
|
||||||
|
set[s] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
count, err := Getfsstat(nil, MntWait)
|
count, err := Getfsstat(nil, MntWait)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ret, err
|
return ret, err
|
||||||
|
@ -74,7 +79,10 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
|
||||||
Fstype: common.IntToString(stat.Fstypename[:]),
|
Fstype: common.IntToString(stat.Fstypename[:]),
|
||||||
Opts: opts,
|
Opts: opts,
|
||||||
}
|
}
|
||||||
ret = append(ret, d)
|
_, ok := set[d.Fstype]
|
||||||
|
if ok || len(fstypes) == 0 {
|
||||||
|
ret = append(ret, d)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret, nil
|
return ret, nil
|
||||||
|
|
|
@ -18,9 +18,14 @@ const (
|
||||||
KernDevstatAll = 772
|
KernDevstatAll = 772
|
||||||
)
|
)
|
||||||
|
|
||||||
func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
|
func DiskPartitions(fstypes []string) ([]DiskPartitionStat, error) {
|
||||||
var ret []DiskPartitionStat
|
var ret []DiskPartitionStat
|
||||||
|
|
||||||
|
set := make(map[string]struct{}, len(fstypes))
|
||||||
|
for _, s := range fstypes {
|
||||||
|
set[s] = struct{}{}
|
||||||
|
}
|
||||||
|
|
||||||
// get length
|
// get length
|
||||||
count, err := syscall.Getfsstat(nil, MNT_WAIT)
|
count, err := syscall.Getfsstat(nil, MNT_WAIT)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -87,7 +92,12 @@ func DiskPartitions(all bool) ([]DiskPartitionStat, error) {
|
||||||
Fstype: common.IntToString(stat.Fstypename[:]),
|
Fstype: common.IntToString(stat.Fstypename[:]),
|
||||||
Opts: opts,
|
Opts: opts,
|
||||||
}
|
}
|
||||||
ret = append(ret, d)
|
|
||||||
|
_, ok := set[d.Fstype]
|
||||||
|
if ok || len(fstypes) == 0 {
|
||||||
|
ret = append(ret, d)
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret, nil
|
return ret, nil
|
||||||
|
|
Loading…
Reference in New Issue