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 keep alive support to the TCP mode of statsd #3781

Merged
merged 1 commit into from
Feb 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
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
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