influxdb/cmd/influxd/run/config.go

99 lines
3.0 KiB
Go
Raw Normal View History

2015-05-28 21:47:47 +00:00
package run
2014-10-21 05:32:47 +00:00
import (
2015-05-29 19:50:05 +00:00
"errors"
2014-10-21 05:32:47 +00:00
"fmt"
2014-12-31 19:42:53 +00:00
"os/user"
"path/filepath"
2014-10-21 05:32:47 +00:00
2015-05-29 19:50:05 +00:00
"github.com/influxdb/influxdb/cluster"
"github.com/influxdb/influxdb/meta"
2015-05-30 14:20:12 +00:00
"github.com/influxdb/influxdb/services/admin"
"github.com/influxdb/influxdb/services/collectd"
"github.com/influxdb/influxdb/services/continuous_querier"
"github.com/influxdb/influxdb/services/graphite"
"github.com/influxdb/influxdb/services/hh"
2015-05-30 14:20:12 +00:00
"github.com/influxdb/influxdb/services/httpd"
"github.com/influxdb/influxdb/services/monitor"
"github.com/influxdb/influxdb/services/opentsdb"
"github.com/influxdb/influxdb/services/precreator"
2015-06-04 21:31:23 +00:00
"github.com/influxdb/influxdb/services/retention"
2015-06-03 13:06:36 +00:00
"github.com/influxdb/influxdb/services/udp"
2015-05-28 21:47:47 +00:00
"github.com/influxdb/influxdb/tsdb"
2014-10-21 05:32:47 +00:00
)
// Config represents the configuration format for the influxd binary.
2015-01-11 02:49:13 +00:00
type Config struct {
Meta meta.Config `toml:"meta"`
Data tsdb.Config `toml:"data"`
Cluster cluster.Config `toml:"cluster"`
Retention retention.Config `toml:"retention"`
Precreator precreator.Config `toml:"shard-precreation"`
2015-05-29 19:50:05 +00:00
Admin admin.Config `toml:"admin"`
HTTPD httpd.Config `toml:"http"`
2015-05-29 19:50:05 +00:00
Graphites []graphite.Config `toml:"graphite"`
Collectd collectd.Config `toml:"collectd"`
OpenTSDB opentsdb.Config `toml:"opentsdb"`
2015-06-03 13:06:36 +00:00
UDP udp.Config `toml:"udp"`
2015-05-28 21:47:47 +00:00
// Snapshot SnapshotConfig `toml:"snapshot"`
2015-05-29 19:50:05 +00:00
Monitoring monitor.Config `toml:"monitoring"`
ContinuousQuery continuous_querier.Config `toml:"continuous_queries"`
HintedHandoff hh.Config `toml:"hinted-handoff"`
2015-01-11 02:49:13 +00:00
}
2014-10-21 05:32:47 +00:00
// NewConfig returns an instance of Config with reasonable defaults.
func NewConfig() *Config {
2014-10-21 05:32:47 +00:00
c := &Config{}
2015-05-29 19:50:05 +00:00
c.Meta = meta.NewConfig()
c.Data = tsdb.NewConfig()
2015-05-30 20:00:46 +00:00
c.Cluster = cluster.NewConfig()
c.Precreator = precreator.NewConfig()
c.Admin = admin.NewConfig()
2015-05-29 19:50:05 +00:00
c.HTTPD = httpd.NewConfig()
c.Collectd = collectd.NewConfig()
c.OpenTSDB = opentsdb.NewConfig()
2015-05-29 19:50:05 +00:00
c.Monitoring = monitor.NewConfig()
c.ContinuousQuery = continuous_querier.NewConfig()
c.Retention = retention.NewConfig()
c.HintedHandoff = hh.NewConfig()
return c
}
2015-05-30 20:00:46 +00:00
// NewDemoConfig returns the config that runs when no config is specified.
func NewDemoConfig() (*Config, error) {
c := NewConfig()
2015-05-29 19:50:05 +00:00
// By default, store meta and data files in current users home directory
u, err := user.Current()
if err != nil {
return nil, fmt.Errorf("failed to determine current user for storage")
}
2015-05-29 19:50:05 +00:00
c.Meta.Dir = filepath.Join(u.HomeDir, ".influxdb/meta")
c.Data.Dir = filepath.Join(u.HomeDir, ".influxdb/data")
c.HintedHandoff.Dir = filepath.Join(u.HomeDir, ".influxdb/hh")
c.Admin.Enabled = true
c.Monitoring.Enabled = false
return c, nil
2014-10-21 05:32:47 +00:00
}
2015-05-29 19:50:05 +00:00
// Validate returns an error if the config is invalid.
func (c *Config) Validate() error {
if c.Meta.Dir == "" {
return errors.New("Meta.Dir must be specified")
} else if c.Data.Dir == "" {
return errors.New("Data.Dir must be specified")
} else if c.HintedHandoff.Dir == "" {
return errors.New("HintedHandoff.Dir must be specified")
}
2015-05-29 19:50:05 +00:00
return nil
}