Added config flag to skip collection of network protocol metrics (#3880)
This commit is contained in:
parent
7f50fa26e9
commit
25cc56d1e3
|
@ -14,6 +14,11 @@ This plugin gathers metrics about network interface and protocol usage (Linux on
|
||||||
##
|
##
|
||||||
# interfaces = ["eth*", "enp0s[0-1]", "lo"]
|
# 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:
|
### Measurements & Fields:
|
||||||
|
|
|
@ -14,8 +14,9 @@ type NetIOStats struct {
|
||||||
filter filter.Filter
|
filter filter.Filter
|
||||||
ps PS
|
ps PS
|
||||||
|
|
||||||
skipChecks bool
|
skipChecks bool
|
||||||
Interfaces []string
|
IgnoreProtocolStats bool
|
||||||
|
Interfaces []string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (_ *NetIOStats) Description() string {
|
func (_ *NetIOStats) Description() string {
|
||||||
|
@ -28,6 +29,12 @@ var netSampleConfig = `
|
||||||
## regardless of status.
|
## regardless of status.
|
||||||
##
|
##
|
||||||
# interfaces = ["eth0"]
|
# 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 {
|
func (_ *NetIOStats) SampleConfig() string {
|
||||||
|
@ -91,19 +98,21 @@ func (s *NetIOStats) Gather(acc telegraf.Accumulator) error {
|
||||||
|
|
||||||
// Get system wide stats for different network protocols
|
// Get system wide stats for different network protocols
|
||||||
// (ignore these stats if the call fails)
|
// (ignore these stats if the call fails)
|
||||||
netprotos, _ := s.ps.NetProto()
|
if !s.IgnoreProtocolStats {
|
||||||
fields := make(map[string]interface{})
|
netprotos, _ := s.ps.NetProto()
|
||||||
for _, proto := range netprotos {
|
fields := make(map[string]interface{})
|
||||||
for stat, value := range proto.Stats {
|
for _, proto := range netprotos {
|
||||||
name := fmt.Sprintf("%s_%s", strings.ToLower(proto.Protocol),
|
for stat, value := range proto.Stats {
|
||||||
strings.ToLower(stat))
|
name := fmt.Sprintf("%s_%s", strings.ToLower(proto.Protocol),
|
||||||
fields[name] = value
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,4 +106,10 @@ func TestNetStats(t *testing.T) {
|
||||||
"udp_socket": 1,
|
"udp_socket": 1,
|
||||||
}
|
}
|
||||||
acc.AssertContainsTaggedFields(t, "netstat", fields3, make(map[string]string))
|
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))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue