Skip to content

Commit

Permalink
Fix some inputs panic will lead to the telegraf exit
Browse files Browse the repository at this point in the history
closes #585
closes #584
  • Loading branch information
Wu Taizeng authored and sparrc committed Jan 26, 2016
1 parent 47ea2d5 commit 637981f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"math/big"
"math/rand"
"os"
"runtime"
"sync"
"time"

Expand Down Expand Up @@ -87,6 +88,18 @@ func (a *Agent) Close() error {
return err
}

func panicRecover(input *models.RunningInput) {
if err := recover(); err != nil {
trace := make([]byte, 2048)
runtime.Stack(trace, true)
log.Printf("FATAL: Input [%s] panicked: %s, Stack:\n%s\n",
input.Name, err, trace)
log.Println("PLEASE REPORT THIS PANIC ON GITHUB with " +
"stack trace, configuration, and OS information: " +
"https://github.com/influxdata/telegraf/issues/new")
}
}

// gatherParallel runs the inputs that are using the same reporting interval
// as the telegraf agent.
func (a *Agent) gatherParallel(pointChan chan *client.Point) error {
Expand All @@ -103,6 +116,7 @@ func (a *Agent) gatherParallel(pointChan chan *client.Point) error {
wg.Add(1)
counter++
go func(input *models.RunningInput) {
defer panicRecover(input)
defer wg.Done()

acc := NewAccumulator(input.Config, pointChan)
Expand Down Expand Up @@ -148,6 +162,8 @@ func (a *Agent) gatherSeparate(
input *models.RunningInput,
pointChan chan *client.Point,
) error {
defer panicRecover(input)

ticker := time.NewTicker(input.Config.Interval)

for {
Expand Down

0 comments on commit 637981f

Please sign in to comment.