From 0d0a8e9b68aa2a72aed96a25d5228043d41e9512 Mon Sep 17 00:00:00 2001 From: Nathaniel Cook Date: Thu, 19 Nov 2015 14:58:21 -0700 Subject: [PATCH] Add network protocol stats to the network plugin --- CHANGELOG.md | 1 + plugins/system/net.go | 10 ++++++++++ plugins/system/ps.go | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f90c585d..6f4f2f4f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -83,6 +83,7 @@ same type. - [#364](https://github.com/influxdb/telegraf/pull/364): Support InfluxDB UDP output. - [#370](https://github.com/influxdb/telegraf/pull/370): Support specifying multiple outputs, as lists. - [#372](https://github.com/influxdb/telegraf/pull/372): Remove gosigar and update go-dockerclient for FreeBSD support. Thanks @MerlinDMC! +- [#382](https://github.com/influxdb/telegraf/pull/382): Add system wide network protocol stats to `net` plugin. ### Bugfixes - [#331](https://github.com/influxdb/telegraf/pull/331): Dont overwrite host tag in redis plugin. diff --git a/plugins/system/net.go b/plugins/system/net.go index 7b4df5247..d11710fc0 100644 --- a/plugins/system/net.go +++ b/plugins/system/net.go @@ -3,6 +3,7 @@ package system import ( "fmt" "net" + "strings" "github.com/influxdb/telegraf/plugins" ) @@ -79,6 +80,15 @@ func (s *NetIOStats) Gather(acc plugins.Accumulator) error { acc.Add("drop_out", io.Dropout, tags) } + // Get system wide stats for different network protocols + netprotos, err := s.ps.NetProto() + for _, proto := range netprotos { + for stat, value := range proto.Stats { + name := fmt.Sprintf("%s_%s", proto.Protocol, strings.ToLower(stat)) + acc.Add(name, value, nil) + } + } + return nil } diff --git a/plugins/system/ps.go b/plugins/system/ps.go index 367bb7aca..d0c35c62c 100644 --- a/plugins/system/ps.go +++ b/plugins/system/ps.go @@ -29,6 +29,7 @@ type PS interface { CPUTimes(perCPU, totalCPU bool) ([]cpu.CPUTimesStat, error) DiskUsage() ([]*disk.DiskUsageStat, error) NetIO() ([]net.NetIOCountersStat, error) + NetProto() ([]net.NetProtoCountersStat, error) DiskIO() (map[string]disk.DiskIOCountersStat, error) VMStat() (*mem.VirtualMemoryStat, error) SwapStat() (*mem.SwapMemoryStat, error) @@ -88,6 +89,10 @@ func (s *systemPS) DiskUsage() ([]*disk.DiskUsageStat, error) { return usage, nil } +func (s *systemPS) NetProto() ([]net.NetProtoCountersStat, error) { + return net.NetProtoCounters(nil) +} + func (s *systemPS) NetIO() ([]net.NetIOCountersStat, error) { return net.NetIOCounters(true) }