Added config flag to skip collection of network protocol metrics (#3880)

This commit is contained in:
Chris Ottinger 2018-03-14 15:08:21 +11:00 committed by Daniel Nelson
parent 7f50fa26e9
commit 25cc56d1e3
3 changed files with 33 additions and 13 deletions

View File

@ -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:

View File

@ -15,6 +15,7 @@ type NetIOStats struct {
ps PS
skipChecks bool
IgnoreProtocolStats bool
Interfaces []string
}
@ -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 {
@ -91,6 +98,7 @@ func (s *NetIOStats) Gather(acc telegraf.Accumulator) error {
// Get system wide stats for different network protocols
// (ignore these stats if the call fails)
if !s.IgnoreProtocolStats {
netprotos, _ := s.ps.NetProto()
fields := make(map[string]interface{})
for _, proto := range netprotos {
@ -104,6 +112,7 @@ func (s *NetIOStats) Gather(acc telegraf.Accumulator) error {
"interface": "all",
}
acc.AddFields("net", fields, tags)
}
return nil
}

View File

@ -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))
}