Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for glob patterns in net input plugin #3140

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Godeps
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ github.com/go-ole/go-ole be49f7c07711fcb603cff39e1de7c67926dc0ba7
github.com/google/go-cmp f94e52cad91c65a63acc1e75d4be223ea22e99bc
github.com/gorilla/mux 392c28fe23e1c45ddba891b0320b3b5df220beea
github.com/go-sql-driver/mysql 2e00b5cd70399450106cec6431c2e2ce3cae5034
github.com/gobwas/glob bea32b9cd2d6f55753d94a28e959b13f0244797a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have this (line 21)

github.com/hailocab/go-hostpool e80d13ce29ede4452c43dea11e79b9bc8a15b478
github.com/hashicorp/consul 63d2fc68239b996096a1c55a0d4b400ea4c2583f
github.com/influxdata/tail a395bf99fe07c233f41fba0735fa2b13b58588ea
Expand Down
6 changes: 4 additions & 2 deletions plugins/inputs/system/NET_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ This plugin gathers metrics about network interface and protocol usage (Linux on
[[inputs.net]]
## By default, telegraf gathers stats from any up interface (excluding loopback)
## 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:
Expand Down
18 changes: 15 additions & 3 deletions plugins/inputs/system/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"net"
"strings"

"github.com/gobwas/glob"
"github.com/influxdata/telegraf"
"github.com/influxdata/telegraf/plugins/inputs"
)

type NetIOStats struct {
ps PS
patterns []glob.Glob
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use filter.Filter here

ps PS

skipChecks bool
Interfaces []string
Expand Down Expand Up @@ -38,12 +40,22 @@ func (s *NetIOStats) Gather(acc telegraf.Accumulator) error {
return fmt.Errorf("error getting net io info: %s", err)
}

if s.patterns == nil {
for _, name := range s.Interfaces {
p, err := glob.Compile(name)
if err != nil {
return fmt.Errorf("error compiling glob pattern: %s", err)
}
s.patterns = append(s.patterns, p)
}
}

for _, io := range netio {
if len(s.Interfaces) != 0 {
var found bool

for _, name := range s.Interfaces {
if name == io.Name {
for _, pattern := range s.patterns {
if pattern.Match(io.Name) {
found = true
break
}
Expand Down