Skip to content

Commit

Permalink
Fix crash when allow pending messgae wasn't set (#1785)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Vinh Quốc Nguyễn authored and jackzampolin committed Oct 7, 2016
1 parent 32e8acc commit 3d91f22
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions plugins/inputs/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ const (

defaultFieldName = "value"

defaultSeparator = "_"
defaultSeparator = "_"
defaultAllowPendingMessage = 10000
)

var dropwarn = "ERROR: statsd message queue full. " +
Expand Down Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -650,7 +651,8 @@ func (s *Statsd) Stop() {
func init() {
inputs.Add("statsd", func() telegraf.Input {
return &Statsd{
MetricSeparator: "_",
MetricSeparator: "_",
AllowedPendingMessages: defaultAllowPendingMessage,
}
})
}

0 comments on commit 3d91f22

Please sign in to comment.