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