Skip to content

Commit

Permalink
Add keep alive support to the TCP mode of statsd (#3781)
Browse files Browse the repository at this point in the history
  • Loading branch information
canha authored and danielnelson committed Feb 16, 2018
1 parent 6406abb commit cd620ac
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions etc/telegraf.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3045,6 +3045,13 @@
#
# ## MaxTCPConnection - applicable when protocol is set to tcp (default=250)
# max_tcp_connections = 250
# ## Enable TCP keep alive probes (default=false)
# tcp_keep_alive = false
#
# ## Specifies the keep-alive period for an active network connection.
# ## Only applies to TCP sockets and will be ignored if tcp_keep_alive is false.
# ## Defaults to the OS configuration.
# # tcp_keep_alive_period = "2h"
#
# ## Address and port to host UDP listener on
# service_address = ":8125"
Expand Down
10 changes: 10 additions & 0 deletions plugins/inputs/statsd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@

## MaxTCPConnection - applicable when protocol is set to tcp (default=250)
max_tcp_connections = 250

## Enable TCP keep alive probes (default=false)
tcp_keep_alive = false

## Specifies the keep-alive period for an active network connection.
## Only applies to TCP sockets and will be ignored if tcp_keep_alive is false.
## Defaults to the OS configuration.
# tcp_keep_alive_period = "2h"

## Address and port to host UDP listener on
service_address = ":8125"
Expand Down Expand Up @@ -157,6 +165,8 @@ metric type:
- **protocol** string: Protocol used in listener - tcp or udp options
- **max_tcp_connections** []int: Maximum number of concurrent TCP connections
to allow. Used when protocol is set to tcp.
- **tcp_keep_alive** boolean: Enable TCP keep alive probes
- **tcp_keep_alive_period** internal.Duration: Specifies the keep-alive period for an active network connection
- **service_address** string: Address to listen for statsd UDP packets on
- **delete_gauges** boolean: Delete gauges on every collection interval
- **delete_counters** boolean: Delete counters on every collection interval
Expand Down
24 changes: 24 additions & 0 deletions plugins/inputs/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ type Statsd struct {

MaxTCPConnections int `toml:"max_tcp_connections"`

TCPKeepAlive bool `toml:"tcp_keep_alive"`
TCPKeepAlivePeriod *internal.Duration `toml:"tcp_keep_alive_period"`

graphiteParser *graphite.GraphiteParser

acc telegraf.Accumulator
Expand Down Expand Up @@ -177,6 +180,14 @@ const sampleConfig = `
## MaxTCPConnection - applicable when protocol is set to tcp (default=250)
max_tcp_connections = 250
## Enable TCP keep alive probes (default=false)
tcp_keep_alive = false
## Specifies the keep-alive period for an active network connection.
## Only applies to TCP sockets and will be ignored if tcp_keep_alive is false.
## Defaults to the OS configuration.
# tcp_keep_alive_period = "2h"
## Address and port to host UDP listener on
service_address = ":8125"
Expand Down Expand Up @@ -361,6 +372,18 @@ func (s *Statsd) tcpListen() error {
return err
}

if s.TCPKeepAlive {
if err = conn.SetKeepAlive(true); err != nil {
return err
}

if s.TCPKeepAlivePeriod != nil {
if err = conn.SetKeepAlivePeriod(s.TCPKeepAlivePeriod.Duration); err != nil {
return err
}
}
}

select {
case <-s.accept:
// not over connection limit, handle the connection properly.
Expand Down Expand Up @@ -863,6 +886,7 @@ func init() {
Protocol: defaultProtocol,
ServiceAddress: ":8125",
MaxTCPConnections: 250,
TCPKeepAlive: false,
MetricSeparator: "_",
AllowedPendingMessages: defaultAllowPendingMessage,
DeleteCounters: true,
Expand Down

0 comments on commit cd620ac

Please sign in to comment.