From e2b1a6bc891bb32431091b8c9f6407d5ba437b92 Mon Sep 17 00:00:00 2001 From: Daniel Nelson Date: Mon, 27 Aug 2018 14:47:04 -0700 Subject: [PATCH] Add read_buffer_size option to statsd input (#4598) --- plugins/inputs/statsd/README.md | 4 ++++ plugins/inputs/statsd/statsd.go | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/plugins/inputs/statsd/README.md b/plugins/inputs/statsd/README.md index 648fa72ac..85cb4a46e 100644 --- a/plugins/inputs/statsd/README.md +++ b/plugins/inputs/statsd/README.md @@ -58,6 +58,10 @@ ## calculation of percentiles. Raising this limit increases the accuracy ## of percentiles but also increases the memory usage and cpu time. percentile_limit = 1000 + + ## Maximum socket buffer size in bytes, once the buffer fills up, metrics + ## will start dropping. Defaults to the OS default. + # read_buffer_size = 65535 ``` ### Description diff --git a/plugins/inputs/statsd/statsd.go b/plugins/inputs/statsd/statsd.go index 3e5a73aa3..60b55887e 100644 --- a/plugins/inputs/statsd/statsd.go +++ b/plugins/inputs/statsd/statsd.go @@ -76,6 +76,8 @@ type Statsd struct { // see https://github.com/influxdata/telegraf/pull/992 UDPPacketSize int `toml:"udp_packet_size"` + ReadBufferSize int `toml:"read_buffer_size"` + sync.Mutex // Lock for preventing a data race during resource cleanup cleanup sync.Mutex @@ -411,6 +413,10 @@ func (s *Statsd) udpListen() error { } log.Println("I! Statsd UDP listener listening on: ", s.UDPlistener.LocalAddr().String()) + if s.ReadBufferSize > 0 { + s.UDPlistener.SetReadBuffer(s.ReadBufferSize) + } + buf := make([]byte, UDP_MAX_PACKET_SIZE) for { select {