diff --git a/outputs/amon/amon_test.go b/outputs/amon/amon_test.go index 94443cbd8..d694323c8 100644 --- a/outputs/amon/amon_test.go +++ b/outputs/amon/amon_test.go @@ -1,10 +1,7 @@ package amon import ( - "encoding/json" "fmt" - "net/http" - "net/http/httptest" "reflect" "testing" "time" @@ -22,12 +19,6 @@ var ( ) func TestUriOverride(t *testing.T) { - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(http.StatusOK) - json.NewEncoder(w).Encode(`{"status":"ok"}`) - })) - defer ts.Close() - a := &Amon{ ServerKey: fakeServerKey, AmonInstance: fakeAmonInstance, diff --git a/outputs/influxdb/README.md b/outputs/influxdb/README.md new file mode 100644 index 000000000..f9a8f7217 --- /dev/null +++ b/outputs/influxdb/README.md @@ -0,0 +1,12 @@ +# InfluxDB Output Plugin + +This plugin writes to [InfluxDB](https://www.influxdb.com) via HTTP or UDP. + +Required parameters: + +* `urls`: List of strings, this is for InfluxDB clustering +support. On each flush interval, Telegraf will randomly choose one of the urls +to write to. Each URL should start with either `http://` or `udp://` +* `database`: The name of the database to write to. + + diff --git a/outputs/influxdb/influxdb.go b/outputs/influxdb/influxdb.go index 014c06631..983fcc6ee 100644 --- a/outputs/influxdb/influxdb.go +++ b/outputs/influxdb/influxdb.go @@ -23,7 +23,7 @@ type InfluxDB struct { UserAgent string Precision string Timeout internal.Duration - UDPPayload int + UDPPayload int `toml:"udp_payload"` conns []client.Client } diff --git a/outputs/influxdb/influxdb_test.go b/outputs/influxdb/influxdb_test.go new file mode 100644 index 000000000..cf1d7d9b3 --- /dev/null +++ b/outputs/influxdb/influxdb_test.go @@ -0,0 +1,41 @@ +package influxdb + +import ( + "fmt" + "net/http" + "net/http/httptest" + "testing" + + "github.com/influxdb/telegraf/testutil" + + "github.com/stretchr/testify/require" +) + +func TestUDPInflux(t *testing.T) { + i := InfluxDB{ + URLs: []string{"udp://localhost:8089"}, + } + + err := i.Connect() + require.NoError(t, err) + err = i.Write(testutil.MockBatchPoints().Points()) + require.NoError(t, err) +} + +func TestHTTPInflux(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.WriteHeader(http.StatusOK) + w.Header().Set("Content-Type", "application/json") + fmt.Fprintln(w, `{"results":[{}]}`) + })) + defer ts.Close() + + i := InfluxDB{ + URLs: []string{ts.URL}, + } + + err := i.Connect() + require.NoError(t, err) + err = i.Write(testutil.MockBatchPoints().Points()) + require.NoError(t, err) +}