Use name filter for IOCounters in diskio (#2649)
Use IOCountersForNames for disk counters.
This commit is contained in:
@@ -125,25 +125,12 @@ func (_ *DiskIOStats) SampleConfig() string {
|
||||
}
|
||||
|
||||
func (s *DiskIOStats) Gather(acc telegraf.Accumulator) error {
|
||||
diskio, err := s.ps.DiskIO()
|
||||
diskio, err := s.ps.DiskIO(s.Devices)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting disk io info: %s", err)
|
||||
}
|
||||
|
||||
var restrictDevices bool
|
||||
devices := make(map[string]bool)
|
||||
if len(s.Devices) != 0 {
|
||||
restrictDevices = true
|
||||
for _, dev := range s.Devices {
|
||||
devices[dev] = true
|
||||
}
|
||||
}
|
||||
|
||||
for _, io := range diskio {
|
||||
_, member := devices[io.Name]
|
||||
if restrictDevices && !member {
|
||||
continue
|
||||
}
|
||||
tags := map[string]string{}
|
||||
tags["name"] = s.diskName(io.Name)
|
||||
for t, v := range s.diskTags(io.Name) {
|
||||
|
||||
@@ -61,7 +61,7 @@ func (m *MockPS) NetProto() ([]net.ProtoCountersStat, error) {
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
func (m *MockPS) DiskIO() (map[string]disk.IOCountersStat, error) {
|
||||
func (m *MockPS) DiskIO(names []string) (map[string]disk.IOCountersStat, error) {
|
||||
ret := m.Called()
|
||||
|
||||
r0 := ret.Get(0).(map[string]disk.IOCountersStat)
|
||||
|
||||
@@ -17,7 +17,7 @@ type PS interface {
|
||||
DiskUsage(mountPointFilter []string, fstypeExclude []string) ([]*disk.UsageStat, []*disk.PartitionStat, error)
|
||||
NetIO() ([]net.IOCountersStat, error)
|
||||
NetProto() ([]net.ProtoCountersStat, error)
|
||||
DiskIO() (map[string]disk.IOCountersStat, error)
|
||||
DiskIO(names []string) (map[string]disk.IOCountersStat, error)
|
||||
VMStat() (*mem.VirtualMemoryStat, error)
|
||||
SwapStat() (*mem.SwapMemoryStat, error)
|
||||
NetConnections() ([]net.ConnectionStat, error)
|
||||
@@ -120,8 +120,8 @@ func (s *systemPS) NetConnections() ([]net.ConnectionStat, error) {
|
||||
return net.Connections("all")
|
||||
}
|
||||
|
||||
func (s *systemPS) DiskIO() (map[string]disk.IOCountersStat, error) {
|
||||
m, err := disk.IOCounters()
|
||||
func (s *systemPS) DiskIO(names []string) (map[string]disk.IOCountersStat, error) {
|
||||
m, err := disk.IOCountersForNames(names)
|
||||
if err == internal.NotImplementedError {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user