add tcp connections stat plugin.
This commit is contained in:
parent
64a3a718e6
commit
23eb08be15
|
@ -32,6 +32,7 @@ type PS interface {
|
||||||
VMStat() (*mem.VirtualMemoryStat, error)
|
VMStat() (*mem.VirtualMemoryStat, error)
|
||||||
SwapStat() (*mem.SwapMemoryStat, error)
|
SwapStat() (*mem.SwapMemoryStat, error)
|
||||||
DockerStat() ([]*DockerContainerStat, error)
|
DockerStat() ([]*DockerContainerStat, error)
|
||||||
|
NetConnections() ([]net.NetConnectionStat, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
func add(acc plugins.Accumulator,
|
func add(acc plugins.Accumulator,
|
||||||
|
@ -90,6 +91,10 @@ func (s *systemPS) NetIO() ([]net.NetIOCountersStat, error) {
|
||||||
return net.NetIOCounters(true)
|
return net.NetIOCounters(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *systemPS) NetConnections() ([]net.NetConnectionStat, error) {
|
||||||
|
return net.NetConnections("all")
|
||||||
|
}
|
||||||
|
|
||||||
func (s *systemPS) DiskIO() (map[string]disk.DiskIOCountersStat, error) {
|
func (s *systemPS) DiskIO() (map[string]disk.DiskIOCountersStat, error) {
|
||||||
m, err := disk.DiskIOCounters()
|
m, err := disk.DiskIOCounters()
|
||||||
if err == common.NotImplementedError {
|
if err == common.NotImplementedError {
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/influxdb/telegraf/plugins"
|
||||||
|
)
|
||||||
|
|
||||||
|
type TCPConnectionStats struct {
|
||||||
|
ps PS
|
||||||
|
}
|
||||||
|
|
||||||
|
func (_ *TCPConnectionStats) Description() string {
|
||||||
|
return "Read metrics about TCP status such as established, time wait etc"
|
||||||
|
}
|
||||||
|
|
||||||
|
var tcpstatSampleConfig = ""
|
||||||
|
|
||||||
|
func (_ *TCPConnectionStats) SampleConfig() string {
|
||||||
|
return tcpstatSampleConfig
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *TCPConnectionStats) Gather(acc plugins.Accumulator) error {
|
||||||
|
netconns, err := s.ps.NetConnections()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("error getting net connections info: %s", err)
|
||||||
|
}
|
||||||
|
counts := make(map[string]int)
|
||||||
|
|
||||||
|
// TODO: add family to tags or else
|
||||||
|
tags := map[string]string{}
|
||||||
|
for _, netcon := range netconns {
|
||||||
|
c, ok := counts[netcon.Status]
|
||||||
|
if !ok {
|
||||||
|
counts[netcon.Status] = 0
|
||||||
|
}
|
||||||
|
counts[netcon.Status] = c + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
acc.Add("established", counts["ESTABLISHED"], tags)
|
||||||
|
acc.Add("syn_sent", counts["SYN_SENT"], tags)
|
||||||
|
acc.Add("syn_recv", counts["SYN_RECV"], tags)
|
||||||
|
acc.Add("fin_wait1", counts["FIN_WAIT1"], tags)
|
||||||
|
acc.Add("fin_wait2", counts["FIN_WAIT2"], tags)
|
||||||
|
acc.Add("time_wait", counts["TIME_WAIT"], tags)
|
||||||
|
acc.Add("close", counts["CLOSE"], tags)
|
||||||
|
acc.Add("close_wait", counts["CLOSE_WAIT"], tags)
|
||||||
|
acc.Add("last_ack", counts["LAST_ACK"], tags)
|
||||||
|
acc.Add("listen", counts["LISTEN"], tags)
|
||||||
|
acc.Add("closing", counts["CLOSING"], tags)
|
||||||
|
acc.Add("none", counts["NONE"], tags)
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
plugins.Add("tcpconn", func() plugins.Plugin {
|
||||||
|
return &TCPConnectionStats{ps: &systemPS{}}
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue