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

added config flag to skip collection of network protocol metrics #3880

Merged
merged 1 commit into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions plugins/inputs/system/NET_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ This plugin gathers metrics about network interface and protocol usage (Linux on
##
# interfaces = ["eth*", "enp0s[0-1]", "lo"]
##
## On linux systems telegraf also collects protocol stats.
## Setting ignore_protocol_stats to true will skip reporting of protocol metrics.
##
# ignore_protocol_stats = false
##
```

### Measurements & Fields:
Expand Down
35 changes: 22 additions & 13 deletions plugins/inputs/system/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ type NetIOStats struct {
filter filter.Filter
ps PS

skipChecks bool
Interfaces []string
skipChecks bool
IgnoreProtocolStats bool
Interfaces []string
}

func (_ *NetIOStats) Description() string {
Expand All @@ -28,6 +29,12 @@ var netSampleConfig = `
## regardless of status.
##
# interfaces = ["eth0"]
##
## On linux systems telegraf also collects protocol stats.
## Setting ignore_protocol_stats to true will skip reporting of protocol metrics.
##
# ignore_protocol_stats = false
##
`

func (_ *NetIOStats) SampleConfig() string {
Expand Down Expand Up @@ -91,19 +98,21 @@ func (s *NetIOStats) Gather(acc telegraf.Accumulator) error {

// Get system wide stats for different network protocols
// (ignore these stats if the call fails)
netprotos, _ := s.ps.NetProto()
fields := make(map[string]interface{})
for _, proto := range netprotos {
for stat, value := range proto.Stats {
name := fmt.Sprintf("%s_%s", strings.ToLower(proto.Protocol),
strings.ToLower(stat))
fields[name] = value
if !s.IgnoreProtocolStats {
netprotos, _ := s.ps.NetProto()
fields := make(map[string]interface{})
for _, proto := range netprotos {
for stat, value := range proto.Stats {
name := fmt.Sprintf("%s_%s", strings.ToLower(proto.Protocol),
strings.ToLower(stat))
fields[name] = value
}
}
tags := map[string]string{
"interface": "all",
}
acc.AddFields("net", fields, tags)
}
tags := map[string]string{
"interface": "all",
}
acc.AddFields("net", fields, tags)

return nil
}
Expand Down
6 changes: 6 additions & 0 deletions plugins/inputs/system/net_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,10 @@ func TestNetStats(t *testing.T) {
"udp_socket": 1,
}
acc.AssertContainsTaggedFields(t, "netstat", fields3, make(map[string]string))

acc.Metrics = nil
err = (&NetIOStats{ps: &mps, IgnoreProtocolStats: true}).Gather(&acc)
require.NoError(t, err)

acc.AssertDoesNotContainsTaggedFields(t, "netstat", fields3, make(map[string]string))
}