InfluxDB output: add tests and a README

This commit is contained in:
Cameron Sparr 2015-11-13 10:39:36 -07:00
parent 20fbfc7006
commit 0f036d6bec
4 changed files with 54 additions and 10 deletions

View File

@ -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,

View File

@ -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.

View File

@ -23,7 +23,7 @@ type InfluxDB struct {
UserAgent string
Precision string
Timeout internal.Duration
UDPPayload int
UDPPayload int `toml:"udp_payload"`
conns []client.Client
}

View File

@ -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)
}