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"
|
2015-06-03 03:31:04 +00:00
|
|
|
"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"
|
2015-06-10 21:53:12 +00:00
|
|
|
"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 {
|
2015-06-10 21:53:12 +00:00
|
|
|
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"`
|
2015-06-05 20:40:18 +00:00
|
|
|
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-03-25 20:27:20 +00:00
|
|
|
|
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"`
|
2015-06-03 03:31:04 +00:00
|
|
|
|
|
|
|
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.
|
2015-03-26 17:10:12 +00:00
|
|
|
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()
|
2015-06-10 21:53:12 +00:00
|
|
|
c.Precreator = precreator.NewConfig()
|
2015-06-05 20:40:18 +00:00
|
|
|
|
|
|
|
c.Admin = admin.NewConfig()
|
2015-05-29 19:50:05 +00:00
|
|
|
c.HTTPD = httpd.NewConfig()
|
2015-06-05 20:40:18 +00:00
|
|
|
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()
|
2015-06-05 18:23:54 +00:00
|
|
|
c.Retention = retention.NewConfig()
|
2015-06-03 03:31:04 +00:00
|
|
|
c.HintedHandoff = hh.NewConfig()
|
2015-04-23 22:03:28 +00:00
|
|
|
|
2015-03-26 17:10:12 +00:00
|
|
|
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) {
|
2015-03-26 17:10:12 +00:00
|
|
|
c := NewConfig()
|
|
|
|
|
2015-05-29 19:50:05 +00:00
|
|
|
// By default, store meta and data files in current users home directory
|
2015-03-26 17:10:12 +00:00
|
|
|
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")
|
2015-03-26 17:10:12 +00:00
|
|
|
c.Data.Dir = filepath.Join(u.HomeDir, ".influxdb/data")
|
2015-06-05 05:03:15 +00:00
|
|
|
c.HintedHandoff.Dir = filepath.Join(u.HomeDir, ".influxdb/hh")
|
2015-03-26 17:10:12 +00:00
|
|
|
|
|
|
|
c.Admin.Enabled = true
|
|
|
|
c.Monitoring.Enabled = false
|
|
|
|
|
2015-03-20 22:13:59 +00:00
|
|
|
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")
|
2015-06-05 05:03:15 +00:00
|
|
|
} else if c.HintedHandoff.Dir == "" {
|
|
|
|
return errors.New("HintedHandoff.Dir must be specified")
|
2015-01-26 18:03:49 +00:00
|
|
|
}
|
2015-05-29 19:50:05 +00:00
|
|
|
return nil
|
2015-01-26 18:03:49 +00:00
|
|
|
}
|