InfluxDB output: add tests and a README
This commit is contained in:
parent
20fbfc7006
commit
0f036d6bec
|
@ -1,10 +1,7 @@
|
||||||
package amon
|
package amon
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -22,12 +19,6 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestUriOverride(t *testing.T) {
|
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{
|
a := &Amon{
|
||||||
ServerKey: fakeServerKey,
|
ServerKey: fakeServerKey,
|
||||||
AmonInstance: fakeAmonInstance,
|
AmonInstance: fakeAmonInstance,
|
||||||
|
|
|
@ -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.
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,7 @@ type InfluxDB struct {
|
||||||
UserAgent string
|
UserAgent string
|
||||||
Precision string
|
Precision string
|
||||||
Timeout internal.Duration
|
Timeout internal.Duration
|
||||||
UDPPayload int
|
UDPPayload int `toml:"udp_payload"`
|
||||||
|
|
||||||
conns []client.Client
|
conns []client.Client
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue