diff --git a/.gitignore b/.gitignore index a127b89f7..a471ffe03 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ pkg/ tivan .vagrant +telegraf diff --git a/agent.go b/agent.go index 9614d6451..a84dbdd3b 100644 --- a/agent.go +++ b/agent.go @@ -57,18 +57,12 @@ func NewAgent(config *Config) (*Agent, error) { agent.Hostname = hostname } - if config.Tags == nil { - config.Tags = map[string]string{} - } - - config.Tags["host"] = agent.Hostname - return agent, nil } func (a *Agent) Connect() error { for _, o := range a.outputs { - err := o.output.Connect() + err := o.output.Connect(a.Hostname) if err != nil { return err } @@ -157,7 +151,6 @@ func (a *Agent) crankParallel() error { close(points) var bp BatchPoints - bp.Tags = a.Config.Tags bp.Time = time.Now() for sub := range points { @@ -181,7 +174,6 @@ func (a *Agent) crank() error { } } - acc.Tags = a.Config.Tags acc.Time = time.Now() return a.flush(&acc) @@ -202,7 +194,6 @@ func (a *Agent) crankSeparate(shutdown chan struct{}, plugin *runningPlugin) err return err } - acc.Tags = a.Config.Tags acc.Time = time.Now() err = a.flush(&acc) diff --git a/cmd/telegraf/telegraf.go b/cmd/telegraf/telegraf.go index d4659620a..5715c1997 100644 --- a/cmd/telegraf/telegraf.go +++ b/cmd/telegraf/telegraf.go @@ -102,7 +102,7 @@ func main() { close(shutdown) }() - log.Print("InfluxDB Agent running") + log.Print("Telegraf Agent running") log.Printf("Loaded outputs: %s", strings.Join(outputs, " ")) log.Printf("Loaded plugins: %s", strings.Join(plugins, " ")) if ag.Debug { @@ -111,10 +111,6 @@ func main() { ag.Interval, ag.Debug, ag.Hostname) } - if len(outputs) > 0 { - log.Printf("Tags enabled: %v", config.ListTags()) - } - if *fPidfile != "" { f, err := os.Create(*fPidfile) if err != nil { diff --git a/config.go b/config.go index 168b8bd1d..a4e0e43a5 100644 --- a/config.go +++ b/config.go @@ -34,8 +34,6 @@ func (d *Duration) UnmarshalTOML(b []byte) error { // will be logging to, as well as all the plugins that the user has // specified type Config struct { - Tags map[string]string - agent *ast.Table plugins map[string]*ast.Table outputs map[string]*ast.Table @@ -200,7 +198,6 @@ func LoadConfig(path string) (*Config, error) { } c := &Config{ - Tags: make(map[string]string), plugins: make(map[string]*ast.Table), outputs: make(map[string]*ast.Table), } @@ -214,10 +211,6 @@ func LoadConfig(path string) (*Config, error) { switch name { case "agent": c.agent = subtbl - case "tags": - if err := toml.UnmarshalTable(subtbl, c.Tags); err != nil { - return nil, errInvalidConfig - } case "outputs": for outputName, outputVal := range subtbl.Fields { outputSubtbl, ok := outputVal.(*ast.Table) @@ -234,20 +227,6 @@ func LoadConfig(path string) (*Config, error) { return c, nil } -// ListTags returns a string of tags specified in the config, -// line-protocol style -func (c *Config) ListTags() string { - var tags []string - - for k, v := range c.Tags { - tags = append(tags, fmt.Sprintf("%s=%s", k, v)) - } - - sort.Strings(tags) - - return strings.Join(tags, " ") -} - type hasConfig interface { BasicConfig() string } @@ -280,8 +259,11 @@ var header = `# Telegraf configuration # NOTE: The configuration has a few required parameters. They are marked # with 'required'. Be sure to edit those to make this configuration work. +# OUTPUTS +[outputs] + # Configuration for influxdb server to send metrics to -[influxdb] +[outputs.influxdb] # The full HTTP endpoint URL for your InfluxDB instance url = "http://localhost:8086" # required. @@ -298,12 +280,8 @@ database = "telegraf" # required. # Set the user agent for the POSTs (can be useful for log differentiation) # user_agent = "telegraf" -# tags = { "dc": "us-east-1" } -# Tags can also be specified via a normal map, but only one form at a time: - -# [influxdb.tags] -# dc = "us-east-1" +# tags = { "dc" = "us-east-1" } # Configuration for telegraf itself # [agent] diff --git a/etc/config.sample.toml b/etc/config.sample.toml index 2b816c632..e19eb09c2 100644 --- a/etc/config.sample.toml +++ b/etc/config.sample.toml @@ -39,9 +39,7 @@ database = "telegraf" # required. # Set the user agent for the POSTs (can be useful for log differentiation) # user_agent = "telegraf" -# Tags can also be specified via a normal map, but only one form at a time: -# [tags] -# dc = "us-east-1" +# tags = { "dc" = "us-east-1" } # Configuration for telegraf itself # [agent] diff --git a/outputs/influxdb/influxdb.go b/outputs/influxdb/influxdb.go index 4a672ba5e..13cd4ea63 100644 --- a/outputs/influxdb/influxdb.go +++ b/outputs/influxdb/influxdb.go @@ -13,11 +13,12 @@ type InfluxDB struct { Password string Database string UserAgent string + Tags map[string]string conn *client.Client } -func (i *InfluxDB) Connect() error { +func (i *InfluxDB) Connect(host string) error { u, err := url.Parse(i.URL) if err != nil { return err @@ -34,12 +35,18 @@ func (i *InfluxDB) Connect() error { return err } + if i.Tags == nil { + i.Tags = make(map[string]string) + } + i.Tags["host"] = host + i.conn = c return nil } func (i *InfluxDB) Write(bp client.BatchPoints) error { bp.Database = i.Database + bp.Tags = i.Tags if _, err := i.conn.Write(bp); err != nil { return err } diff --git a/outputs/registry.go b/outputs/registry.go index ccc40f9b2..a18ede493 100644 --- a/outputs/registry.go +++ b/outputs/registry.go @@ -5,7 +5,7 @@ import ( ) type Output interface { - Connect() error + Connect(string) error Write(client.BatchPoints) error } diff --git a/telegraf b/telegraf deleted file mode 100755 index 526440e8e..000000000 Binary files a/telegraf and /dev/null differ diff --git a/testdata/influx.toml b/testdata/influx.toml index 10684b159..fe64bf17c 100644 --- a/testdata/influx.toml +++ b/testdata/influx.toml @@ -9,9 +9,7 @@ url = "http://localhost:8086" username = "root" password = "root" database = "telegraf" - -[tags] -dc = "us-phx-1" +tags = { "dc" = "us-phx-1" } [redis] address = ":6379"