resolve all merge issues, move Tags back to Config

This commit is contained in:
JP 2015-08-11 21:08:47 -05:00
parent c5c701d178
commit 75b6ec6469
7 changed files with 39 additions and 22 deletions

View File

@ -19,6 +19,7 @@
- [#85](https://github.com/influxdb/telegraf/pull/85): Fix GetLocalHost testutil function for mac users - [#85](https://github.com/influxdb/telegraf/pull/85): Fix GetLocalHost testutil function for mac users
- [#89](https://github.com/influxdb/telegraf/pull/89): go fmt fixes - [#89](https://github.com/influxdb/telegraf/pull/89): go fmt fixes
- [#94](https://github.com/influxdb/telegraf/pull/94): Fix for issue #93, explicitly call sarama.v1 -> sarama - [#94](https://github.com/influxdb/telegraf/pull/94): Fix for issue #93, explicitly call sarama.v1 -> sarama
- [#101](https://github.com/influxdb/telegraf/issues/101): switch back from master branch if building locally
## v0.1.4 [2015-07-09] ## v0.1.4 [2015-07-09]

View File

@ -3,7 +3,6 @@ package telegraf
import ( import (
"fmt" "fmt"
"log" "log"
"net/url"
"os" "os"
"sort" "sort"
"strings" "strings"
@ -79,6 +78,7 @@ func (a *Agent) Connect() error {
return nil return nil
} }
// LoadOutputs loads the agent's outputs
func (a *Agent) LoadOutputs() ([]string, error) { func (a *Agent) LoadOutputs() ([]string, error) {
var names []string var names []string
@ -188,7 +188,7 @@ func (a *Agent) crankParallel() error {
bp.Points = append(bp.Points, sub.Points...) bp.Points = append(bp.Points, sub.Points...)
} }
return a.flush(bp) return a.flush(&bp)
} }
func (a *Agent) crank() error { func (a *Agent) crank() error {
@ -208,7 +208,7 @@ func (a *Agent) crank() error {
bp.Time = time.Now() bp.Time = time.Now()
bp.Tags = a.Config.Tags bp.Tags = a.Config.Tags
return a.flush(bp) return a.flush(&bp)
} }
func (a *Agent) crankSeparate(shutdown chan struct{}, plugin *runningPlugin) error { func (a *Agent) crankSeparate(shutdown chan struct{}, plugin *runningPlugin) error {
@ -229,7 +229,7 @@ func (a *Agent) crankSeparate(shutdown chan struct{}, plugin *runningPlugin) err
bp.Tags = a.Config.Tags bp.Tags = a.Config.Tags
bp.Time = time.Now() bp.Time = time.Now()
err = a.flush(acc) err = a.flush(&bp)
if err != nil { if err != nil {
return err return err
} }
@ -243,14 +243,14 @@ func (a *Agent) crankSeparate(shutdown chan struct{}, plugin *runningPlugin) err
} }
} }
func (a *Agent) flush(bp BatchPoints) error { func (a *Agent) flush(bp *BatchPoints) error {
var wg sync.WaitGroup var wg sync.WaitGroup
var outerr error var outerr error
for _, o := range a.outputs { for _, o := range a.outputs {
wg.Add(1) wg.Add(1)
go func(output *runningOutput) { go func(ro *runningOutput) {
defer wg.Done() defer wg.Done()
outerr = o.output.Write(bp.BatchPoints) outerr = ro.output.Write(bp.BatchPoints)
}(o) }(o)
} }

View File

@ -9,6 +9,7 @@ import (
"strings" "strings"
"github.com/influxdb/telegraf" "github.com/influxdb/telegraf"
_ "github.com/influxdb/telegraf/outputs/all"
_ "github.com/influxdb/telegraf/plugins/all" _ "github.com/influxdb/telegraf/plugins/all"
) )
@ -21,16 +22,13 @@ var fPidfile = flag.String("pidfile", "", "file to write our pid to")
var fPLuginsFilter = flag.String("filter", "", "filter the plugins to enable, separator is :") var fPLuginsFilter = flag.String("filter", "", "filter the plugins to enable, separator is :")
// Telegraf version // Telegraf version
var Version = "unreleased" var Version = "0.1.5-dev"
// Telegraf commit
var Commit = ""
func main() { func main() {
flag.Parse() flag.Parse()
if *fVersion { if *fVersion {
fmt.Printf("InfluxDB Telegraf agent - Version %s\n", Version) fmt.Printf("Telegraf - Version %s\n", Version)
return return
} }
@ -62,6 +60,15 @@ func main() {
ag.Debug = true ag.Debug = true
} }
outputs, err := ag.LoadOutputs()
if err != nil {
log.Fatal(err)
}
if len(outputs) == 0 {
log.Printf("Error: no outputs found, did you provide a config file?")
os.Exit(1)
}
plugins, err := ag.LoadPlugins(*fPLuginsFilter) plugins, err := ag.LoadPlugins(*fPLuginsFilter)
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)
@ -105,7 +112,7 @@ func main() {
close(shutdown) close(shutdown)
}() }()
log.Print("Telegraf Agent running") log.Printf("Starting Telegraf (version %s)\n", Version)
log.Printf("Loaded outputs: %s", strings.Join(outputs, " ")) log.Printf("Loaded outputs: %s", strings.Join(outputs, " "))
log.Printf("Loaded plugins: %s", strings.Join(plugins, " ")) log.Printf("Loaded plugins: %s", strings.Join(plugins, " "))
if ag.Debug { if ag.Debug {
@ -114,6 +121,8 @@ func main() {
ag.Interval, ag.Debug, ag.Hostname) ag.Interval, ag.Debug, ag.Hostname)
} }
log.Printf("Tags enabled: %v", config.ListTags())
if *fPidfile != "" { if *fPidfile != "" {
f, err := os.Create(*fPidfile) f, err := os.Create(*fPidfile)
if err != nil { if err != nil {

View File

@ -30,9 +30,8 @@ func (d *Duration) UnmarshalTOML(b []byte) error {
return nil return nil
} }
// Config specifies the URL/user/password for the database that telegraf // Config specifies the outputs that telegraf will be logging to,
// will be logging to, as well as all the plugins that the user has // as well as all the plugins that the user has specified
// specified
type Config struct { type Config struct {
Tags map[string]string Tags map[string]string
@ -51,6 +50,7 @@ func (c *Config) Outputs() map[string]*ast.Table {
return c.outputs return c.outputs
} }
// The name of a tag, and the values on which to filter
type TagFilter struct { type TagFilter struct {
Name string Name string
Filter []string Filter []string
@ -243,7 +243,7 @@ func (c *Config) OutputsDeclared() []string {
func declared(endpoints map[string]*ast.Table) []string { func declared(endpoints map[string]*ast.Table) []string {
var names []string var names []string
for name, _ := range endpoints { for name := range endpoints {
names = append(names, name) names = append(names, name)
} }

View File

@ -39,7 +39,8 @@ database = "telegraf" # required.
# Set the user agent for the POSTs (can be useful for log differentiation) # Set the user agent for the POSTs (can be useful for log differentiation)
# user_agent = "telegraf" # user_agent = "telegraf"
# tags = { "dc" = "us-east-1" } [tags]
dc = "us-east-1"
# Configuration for telegraf itself # Configuration for telegraf itself
# [agent] # [agent]

View File

@ -1,9 +1,13 @@
package influxdb package influxdb
import ( import (
"fmt"
"log"
"net/url" "net/url"
"strings"
"github.com/influxdb/influxdb/client" "github.com/influxdb/influxdb/client"
t "github.com/influxdb/telegraf"
"github.com/influxdb/telegraf/outputs" "github.com/influxdb/telegraf/outputs"
) )
@ -13,7 +17,7 @@ type InfluxDB struct {
Password string Password string
Database string Database string
UserAgent string UserAgent string
Timeout Duration Timeout t.Duration
conn *client.Client conn *client.Client
} }
@ -50,7 +54,6 @@ func (i *InfluxDB) Connect() error {
func (i *InfluxDB) Write(bp client.BatchPoints) error { func (i *InfluxDB) Write(bp client.BatchPoints) error {
bp.Database = i.Database bp.Database = i.Database
bp.Tags = i.Tags
if _, err := i.conn.Write(bp); err != nil { if _, err := i.conn.Write(bp); err != nil {
return err return err
} }

View File

@ -3,12 +3,15 @@ interval = "5s"
http = ":11213" http = ":11213"
debug = true debug = true
[influxdb] [outputs]
[outputs.influxdb]
url = "http://localhost:8086" url = "http://localhost:8086"
username = "root" username = "root"
password = "root" password = "root"
database = "telegraf" database = "telegraf"
tags = { dc = "us-phx-1" }
[tags]
dc = "us-phx-1"
[redis] [redis]
address = ":6379" address = ":6379"