Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only split metrics if there is an udp output #2799

Merged
merged 1 commit into from
May 12, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions plugins/outputs/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package influxdb

import (
"fmt"
"io"
"log"
"math/rand"
"strings"
Expand Down Expand Up @@ -41,7 +42,8 @@ type InfluxDB struct {
// Precision is only here for legacy support. It will be ignored.
Precision string

clients []client.Client
clients []client.Client
splitPayload bool
}

var sampleConfig = `
Expand Down Expand Up @@ -109,6 +111,7 @@ func (i *InfluxDB) Connect() error {
return fmt.Errorf("Error creating UDP Client [%s]: %s", u, err)
}
i.clients = append(i.clients, c)
i.splitPayload = true
default:
// If URL doesn't start with "udp", assume HTTP client
config := client.HTTPConfig{
Expand Down Expand Up @@ -159,17 +162,26 @@ func (i *InfluxDB) Description() string {
return "Configuration for influxdb server to send metrics to"
}

func (i *InfluxDB) getReader(metrics []telegraf.Metric) io.Reader {
if !i.splitPayload {
return metric.NewReader(metrics)
}

splitData := make([]telegraf.Metric, 0)
for _, m := range metrics {
splitData = append(splitData, m.Split(i.UDPPayload)...)
}
return metric.NewReader(splitData)
}

// Write will choose a random server in the cluster to write to until a successful write
// occurs, logging each unsuccessful. If all servers fail, return error.
func (i *InfluxDB) Write(metrics []telegraf.Metric) error {
bufsize := 0
splitData := make([]telegraf.Metric, 0)

for _, m := range metrics {
bufsize += m.Len()
splitData = append(splitData, m.Split(i.UDPPayload)...)
}
r := metric.NewReader(splitData)
r := i.getReader(metrics)

// This will get set to nil if a successful write occurs
err := fmt.Errorf("Could not write to any InfluxDB server in cluster")
Expand Down