graphite output: set write deadline on TCP connection
This commit is contained in:
parent
7b550c11cb
commit
69ab8a645c
|
@ -2,7 +2,6 @@ package graphite
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
|
@ -98,9 +97,12 @@ func (g *Graphite) Write(metrics []telegraf.Metric) error {
|
|||
// Send data to a random server
|
||||
p := rand.Perm(len(g.conns))
|
||||
for _, n := range p {
|
||||
if _, e := fmt.Fprint(g.conns[n], graphitePoints); e != nil {
|
||||
if g.Timeout > 0 {
|
||||
g.conns[n].SetWriteDeadline(time.Now().Add(time.Duration(g.Timeout) * time.Second))
|
||||
}
|
||||
if _, e := g.conns[n].Write([]byte(graphitePoints)); e != nil {
|
||||
// Error
|
||||
log.Println("ERROR: " + err.Error())
|
||||
log.Println("ERROR: " + e.Error())
|
||||
// Let's try the next one
|
||||
} else {
|
||||
// Success
|
||||
|
|
Loading…
Reference in New Issue