diff --git a/agent.go b/agent.go index 6540601ea0999..90bc24f8da714 100644 --- a/agent.go +++ b/agent.go @@ -88,6 +88,8 @@ func (a *Agent) LoadOutputs() ([]string, error) { return nil, fmt.Errorf("Undefined but requested output: %s", name) } + _, err = c.Query(client.Query{ + Command: fmt.Sprintf("CREATE DATABASE %s", config.Database), output := creator() err := a.Config.ApplyOutput(name, output) diff --git a/outputs/all/all.go b/outputs/all/all.go new file mode 100644 index 0000000000000..2a8018674349c --- /dev/null +++ b/outputs/all/all.go @@ -0,0 +1,5 @@ +package all + +import ( + _ "github.com/influxdb/telegraf/outputs/influxdb" +) diff --git a/outputs/influxdb/influxdb.go b/outputs/influxdb/influxdb.go new file mode 100644 index 0000000000000..1153f064b2fc4 --- /dev/null +++ b/outputs/influxdb/influxdb.go @@ -0,0 +1,67 @@ +package influxdb + +import ( + "fmt" + "log" + "net/url" + "strings" + + "github.com/influxdb/influxdb/client" + t "github.com/influxdb/telegraf" + "github.com/influxdb/telegraf/outputs" +) + +type InfluxDB struct { + URL string + Username string + Password string + Database string + UserAgent string + Timeout t.Duration + + conn *client.Client +} + +func (i *InfluxDB) Connect() error { + u, err := url.Parse(i.URL) + if err != nil { + return err + } + + c, err := client.NewClient(client.Config{ + URL: *u, + Username: i.Username, + Password: i.Password, + UserAgent: i.UserAgent, + Timeout: i.Timeout.Duration, + }) + + if err != nil { + return err + } + + _, err = c.Query(client.Query{ + Command: fmt.Sprintf("CREATE DATABASE telegraf"), + }) + + if err != nil && !strings.Contains(err.Error(), "database already exists") { + log.Fatal(err) + } + + i.conn = c + return nil +} + +func (i *InfluxDB) Write(bp client.BatchPoints) error { + bp.Database = i.Database + if _, err := i.conn.Write(bp); err != nil { + return err + } + return nil +} + +func init() { + outputs.Add("influxdb", func() outputs.Output { + return &InfluxDB{} + }) +} diff --git a/outputs/registry.go b/outputs/registry.go new file mode 100644 index 0000000000000..3abd55e6965c7 --- /dev/null +++ b/outputs/registry.go @@ -0,0 +1,729 @@ + + + + + + + + + + + + + telegraf/registry.go at outputs-phase1 · jipperinbham/telegraf · GitHub + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Skip to content +
+ + + + + + + + + + + +
+
+
+ +
+
+
+ +
+ + + +

+ + /telegraf + + + + + + + forked from influxdb/telegraf + +

+
+ +
+
+ +
+
+
+ + + + +
+ +
+

HTTPS clone URL

+
+ + + + +
+
+ + +
+

Subversion checkout URL

+
+ + + + +
+
+ + + +
You can clone with +
or
. + + + +
+ + + + Download ZIP + +
+
+
+ + + + + + + +
+ +
+ + Branch: + outputs-phase1 + + + +
+ +
+ + + + +
+ + +
+ + +
+
+ @jipperinbham + + + +
+ + + +
+ +
+
+
+ +
+ Raw + Blame + History +
+ + + + + +
+ +
+ 19 lines (13 sloc) + + 0.277 kB +
+
+ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
package outputs
+
import (
"github.com/influxdb/influxdb/client"
)
+
type Output interface {
Connect() error
Write(client.BatchPoints) error
}
+
type Creator func() Output
+
var Outputs = map[string]Creator{}
+
func Add(name string, creator Creator) {
Outputs[name] = creator
}
+ +
+ +
+ +Jump to Line + + +
+
+ +
+
+ + +
+ +
+ +
+ + +
+
+
+ +
+
+
+
+
+
+ + + + + + +
+
+ + + + + + +
+ + + Something went wrong with that request. Please try again. +
+ + + + + + + + + +