From 1d10eda84efd14e86d803badb77d125536a3d4a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vinh=20Qu=E1=BB=91c=20Nguy=E1=BB=85n?= Date: Fri, 23 Sep 2016 03:37:47 -0700 Subject: [PATCH] Fix crash when allow pending messgae wasn't set (#1785) The default is 0 so we hit a division by 0 error and crash. This checks ensure we will not crash and `log` and continue to let telegraf run Also we set default allow pending message number to 10000 --- plugins/inputs/statsd/statsd.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/inputs/statsd/statsd.go b/plugins/inputs/statsd/statsd.go index 555f6d45b..eb02a1df2 100644 --- a/plugins/inputs/statsd/statsd.go +++ b/plugins/inputs/statsd/statsd.go @@ -24,7 +24,8 @@ const ( defaultFieldName = "value" - defaultSeparator = "_" + defaultSeparator = "_" + defaultAllowPendingMessage = 10000 ) var dropwarn = "ERROR: statsd message queue full. " + @@ -297,7 +298,7 @@ func (s *Statsd) udpListen() error { case s.in <- bufCopy: default: s.drops++ - if s.drops == 1 || s.drops%s.AllowedPendingMessages == 0 { + if s.drops == 1 || s.AllowedPendingMessages == 0 || s.drops%s.AllowedPendingMessages == 0 { log.Printf(dropwarn, s.drops) } } @@ -650,7 +651,8 @@ func (s *Statsd) Stop() { func init() { inputs.Add("statsd", func() telegraf.Input { return &Statsd{ - MetricSeparator: "_", + MetricSeparator: "_", + AllowedPendingMessages: defaultAllowPendingMessage, } }) }