Add support for glob patterns in net input plugin (#3140)
This commit is contained in:
parent
ca76242e3e
commit
dd8157ec68
|
@ -9,9 +9,11 @@ This plugin gathers metrics about network interface and protocol usage (Linux on
|
||||||
[[inputs.net]]
|
[[inputs.net]]
|
||||||
## By default, telegraf gathers stats from any up interface (excluding loopback)
|
## By default, telegraf gathers stats from any up interface (excluding loopback)
|
||||||
## Setting interfaces will tell it to gather these explicit interfaces,
|
## Setting interfaces will tell it to gather these explicit interfaces,
|
||||||
## regardless of status.
|
## regardless of status. When specifying an interface, glob-style
|
||||||
|
## patterns are also supported.
|
||||||
|
##
|
||||||
|
# interfaces = ["eth*", "enp0s[0-1]", "lo"]
|
||||||
##
|
##
|
||||||
# interfaces = ["eth0"]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Measurements & Fields:
|
### Measurements & Fields:
|
||||||
|
|
|
@ -6,10 +6,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/influxdata/telegraf"
|
"github.com/influxdata/telegraf"
|
||||||
|
"github.com/influxdata/telegraf/filter"
|
||||||
"github.com/influxdata/telegraf/plugins/inputs"
|
"github.com/influxdata/telegraf/plugins/inputs"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NetIOStats struct {
|
type NetIOStats struct {
|
||||||
|
filter filter.Filter
|
||||||
ps PS
|
ps PS
|
||||||
|
|
||||||
skipChecks bool
|
skipChecks bool
|
||||||
|
@ -38,15 +40,18 @@ func (s *NetIOStats) Gather(acc telegraf.Accumulator) error {
|
||||||
return fmt.Errorf("error getting net io info: %s", err)
|
return fmt.Errorf("error getting net io info: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.filter == nil {
|
||||||
|
if s.filter, err = filter.Compile(s.Interfaces); err != nil {
|
||||||
|
return fmt.Errorf("error compiling filter: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, io := range netio {
|
for _, io := range netio {
|
||||||
if len(s.Interfaces) != 0 {
|
if len(s.Interfaces) != 0 {
|
||||||
var found bool
|
var found bool
|
||||||
|
|
||||||
for _, name := range s.Interfaces {
|
if s.filter.Match(io.Name) {
|
||||||
if name == io.Name {
|
|
||||||
found = true
|
found = true
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if !found {
|
if !found {
|
||||||
|
|
Loading…
Reference in New Issue