Speed up interface stats in net input (#5757)
This commit is contained in:
parent
17a772d7ae
commit
01eecee8cf
|
@ -54,6 +54,15 @@ func (s *NetIOStats) Gather(acc telegraf.Accumulator) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interfaces, err := net.Interfaces()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error getting list of interfaces: %s", err)
|
||||||
|
}
|
||||||
|
interfacesByName := map[string]net.Interface{}
|
||||||
|
for _, iface := range interfaces {
|
||||||
|
interfacesByName[iface.Name] = iface
|
||||||
|
}
|
||||||
|
|
||||||
for _, io := range netio {
|
for _, io := range netio {
|
||||||
if len(s.Interfaces) != 0 {
|
if len(s.Interfaces) != 0 {
|
||||||
var found bool
|
var found bool
|
||||||
|
@ -66,8 +75,8 @@ func (s *NetIOStats) Gather(acc telegraf.Accumulator) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
} else if !s.skipChecks {
|
} else if !s.skipChecks {
|
||||||
iface, err := net.InterfaceByName(io.Name)
|
iface, ok := interfacesByName[io.Name]
|
||||||
if err != nil {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue