move tags to influxdb struct, update all sample configs
This commit is contained in:
parent
48c10f9454
commit
91f6c4b740
|
@ -1,3 +1,4 @@
|
|||
pkg/
|
||||
tivan
|
||||
.vagrant
|
||||
telegraf
|
||||
|
|
11
agent.go
11
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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
32
config.go
32
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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
)
|
||||
|
||||
type Output interface {
|
||||
Connect() error
|
||||
Connect(string) error
|
||||
Write(client.BatchPoints) error
|
||||
}
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Reference in New Issue