Skip to content

Commit

Permalink
Speed up interface stats in net input (influxdata#5757)
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszo authored and Helge Waastad committed Jun 13, 2019
1 parent 0a9521e commit 15da377
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions plugins/inputs/net/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
if len(s.Interfaces) != 0 {
var found bool
Expand All @@ -66,8 +75,8 @@ func (s *NetIOStats) Gather(acc telegraf.Accumulator) error {
continue
}
} else if !s.skipChecks {
iface, err := net.InterfaceByName(io.Name)
if err != nil {
iface, ok := interfacesByName[io.Name]
if !ok {
continue
}

Expand Down

0 comments on commit 15da377

Please sign in to comment.