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 protocol stats to the network plugin #382

Merged
merged 2 commits into from
Dec 4, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add network protocol stats to the network plugin
  • Loading branch information
nathanielc authored and sparrc committed Dec 4, 2015
commit 0d0a8e9b68aa2a72aed96a25d5228043d41e9512
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Contributor

Choose a reason for hiding this comment

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

this should go higher up, under 0.2.3


### Bugfixes
- [#331](https://github.com/influxdb/telegraf/pull/331): Dont overwrite host tag in redis plugin.
Expand Down
10 changes: 10 additions & 0 deletions plugins/system/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package system
import (
"fmt"
"net"
"strings"

"github.com/influxdb/telegraf/plugins"
)
Expand Down Expand Up @@ -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()
Copy link
Contributor

Choose a reason for hiding this comment

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

If we're ignoring the error just set the var name to _ to make it more clear that we don't care if this call fails

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch surprised it even compiled....

for _, proto := range netprotos {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will just do nothing on unsupported systems, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct

for stat, value := range proto.Stats {
name := fmt.Sprintf("%s_%s", proto.Protocol, strings.ToLower(stat))
acc.Add(name, value, nil)
}
}

return nil
}

Expand Down
5 changes: 5 additions & 0 deletions plugins/system/ps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down