2014-10-21 05:32:47 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
2014-12-31 19:42:53 +00:00
|
|
|
"os/user"
|
|
|
|
"path/filepath"
|
2014-10-21 05:32:47 +00:00
|
|
|
"strconv"
|
2015-01-08 20:23:48 +00:00
|
|
|
"strings"
|
2014-10-21 05:32:47 +00:00
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/BurntSushi/toml"
|
2015-01-08 19:10:38 +00:00
|
|
|
"github.com/influxdb/influxdb/graphite"
|
2014-10-21 05:32:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
// DefaultPointBatchSize represents the number of points to batch together.
|
|
|
|
DefaultPointBatchSize = 100
|
|
|
|
|
|
|
|
// DefaultPointBatchSize represents the number of writes to batch together.
|
|
|
|
DefaultWriteBatchSize = 10 * 1024 * 1024 // 10MB
|
|
|
|
|
|
|
|
// DefaultConcurrentShardQueryLimit represents the number of shards that
|
|
|
|
// can be queried concurrently at one time.
|
|
|
|
DefaultConcurrentShardQueryLimit = 10
|
|
|
|
|
2014-12-31 19:42:53 +00:00
|
|
|
// DefaultAPIReadTimeout represents the duration before an API request times out.
|
2014-10-21 05:32:47 +00:00
|
|
|
DefaultAPIReadTimeout = 5 * time.Second
|
2014-12-31 19:42:53 +00:00
|
|
|
|
|
|
|
// DefaultBrokerPort represents the default port the broker runs on.
|
|
|
|
DefaultBrokerPort = 8086
|
|
|
|
|
|
|
|
// DefaultHTTPAPIPort represents the default port the HTTP API runs on.
|
|
|
|
DefaultHTTPAPIPort = 8086
|
2014-10-21 05:32:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config represents the configuration format for the influxd binary.
|
2015-01-08 20:07:09 +00:00
|
|
|
type (
|
|
|
|
Graphite struct {
|
|
|
|
Addr string `toml:"address"`
|
|
|
|
Database string `toml:"database"`
|
|
|
|
Enabled bool `toml:"enabled"`
|
|
|
|
Port uint16 `toml:"port"`
|
|
|
|
Protocol string `toml:"protocol"`
|
|
|
|
NamePosition string `toml:"name-position"`
|
|
|
|
NameSeparator string `toml:"name-separator"`
|
|
|
|
}
|
|
|
|
|
|
|
|
Config struct {
|
|
|
|
Hostname string `toml:"hostname"`
|
|
|
|
BindAddress string `toml:"bind-address"`
|
|
|
|
ReportingDisabled bool `toml:"reporting-disabled"`
|
|
|
|
Version string `toml:"-"`
|
|
|
|
InfluxDBVersion string `toml:"-"`
|
|
|
|
|
|
|
|
Admin struct {
|
|
|
|
Port int `toml:"port"`
|
|
|
|
Assets string `toml:"assets"`
|
|
|
|
} `toml:"admin"`
|
|
|
|
|
|
|
|
HTTPAPI struct {
|
|
|
|
Port int `toml:"port"`
|
|
|
|
SSLPort int `toml:"ssl-port"`
|
|
|
|
SSLCertPath string `toml:"ssl-cert"`
|
|
|
|
ReadTimeout Duration `toml:"read-timeout"`
|
|
|
|
} `toml:"api"`
|
|
|
|
|
|
|
|
InputPlugins struct {
|
|
|
|
Graphites []Graphite `toml:"graphite"`
|
|
|
|
UDPInput struct {
|
|
|
|
Enabled bool `toml:"enabled"`
|
|
|
|
Port uint16 `toml:"port"`
|
|
|
|
Database string `toml:"database"`
|
|
|
|
} `toml:"udp"`
|
|
|
|
UDPServersInput []struct {
|
|
|
|
Enabled bool `toml:"enabled"`
|
|
|
|
Port int `toml:"port"`
|
|
|
|
Database string `toml:"database"`
|
|
|
|
} `toml:"udp_servers"`
|
|
|
|
} `toml:"input_plugins"`
|
|
|
|
|
|
|
|
Broker struct {
|
|
|
|
Port int `toml:"port"`
|
|
|
|
Dir string `toml:"dir"`
|
|
|
|
Timeout Duration `toml:"election-timeout"`
|
|
|
|
} `toml:"broker"`
|
|
|
|
|
|
|
|
Data struct {
|
|
|
|
Dir string `toml:"dir"`
|
|
|
|
WriteBufferSize int `toml:"write-buffer-size"`
|
|
|
|
MaxOpenShards int `toml:"max-open-shards"`
|
|
|
|
PointBatchSize int `toml:"point-batch-size"`
|
|
|
|
WriteBatchSize int `toml:"write-batch-size"`
|
|
|
|
Engines map[string]toml.Primitive `toml:"engines"`
|
|
|
|
RetentionSweepPeriod Duration `toml:"retention-sweep-period"`
|
|
|
|
} `toml:"data"`
|
|
|
|
|
|
|
|
Cluster struct {
|
|
|
|
Dir string `toml:"dir"`
|
|
|
|
ProtobufPort int `toml:"protobuf_port"`
|
|
|
|
ProtobufTimeout Duration `toml:"protobuf_timeout"`
|
|
|
|
ProtobufHeartbeatInterval Duration `toml:"protobuf_heartbeat"`
|
|
|
|
MinBackoff Duration `toml:"protobuf_min_backoff"`
|
|
|
|
MaxBackoff Duration `toml:"protobuf_max_backoff"`
|
|
|
|
WriteBufferSize int `toml:"write-buffer-size"`
|
|
|
|
ConcurrentShardQueryLimit int `toml:"concurrent-shard-query-limit"`
|
|
|
|
MaxResponseBufferSize int `toml:"max-response-buffer-size"`
|
|
|
|
} `toml:"cluster"`
|
|
|
|
|
|
|
|
Logging struct {
|
|
|
|
File string `toml:"file"`
|
|
|
|
Level string `toml:"level"`
|
|
|
|
} `toml:"logging"`
|
|
|
|
}
|
|
|
|
)
|
2014-10-21 05:32:47 +00:00
|
|
|
|
|
|
|
// NewConfig returns an instance of Config with reasonable defaults.
|
|
|
|
func NewConfig() *Config {
|
2014-12-31 19:42:53 +00:00
|
|
|
u, _ := user.Current()
|
|
|
|
|
2014-10-21 05:32:47 +00:00
|
|
|
c := &Config{}
|
2014-12-30 22:46:50 +00:00
|
|
|
c.Data.RetentionSweepPeriod = Duration(10 * time.Minute)
|
2014-10-21 05:32:47 +00:00
|
|
|
c.Cluster.ConcurrentShardQueryLimit = DefaultConcurrentShardQueryLimit
|
2014-12-31 19:42:53 +00:00
|
|
|
c.Broker.Dir = filepath.Join(u.HomeDir, ".influxdb/broker")
|
|
|
|
c.Broker.Port = DefaultBrokerPort
|
2014-12-30 22:46:50 +00:00
|
|
|
c.Broker.Timeout = Duration(1 * time.Second)
|
2014-12-31 19:42:53 +00:00
|
|
|
c.HTTPAPI.Port = DefaultHTTPAPIPort
|
2014-10-21 05:32:47 +00:00
|
|
|
c.HTTPAPI.ReadTimeout = Duration(DefaultAPIReadTimeout)
|
|
|
|
c.Cluster.MinBackoff = Duration(1 * time.Second)
|
|
|
|
c.Cluster.MaxBackoff = Duration(10 * time.Second)
|
|
|
|
c.Cluster.ProtobufHeartbeatInterval = Duration(10 * time.Millisecond)
|
2014-12-31 19:42:53 +00:00
|
|
|
c.Data.Dir = filepath.Join(u.HomeDir, ".influxdb/data")
|
2014-12-30 22:46:50 +00:00
|
|
|
c.Data.WriteBufferSize = 1000
|
2014-10-21 05:32:47 +00:00
|
|
|
c.Cluster.WriteBufferSize = 1000
|
|
|
|
c.Cluster.MaxResponseBufferSize = 100
|
|
|
|
|
|
|
|
// Detect hostname (or set to localhost).
|
|
|
|
if c.Hostname, _ = os.Hostname(); c.Hostname == "" {
|
|
|
|
c.Hostname = "localhost"
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIX(benbjohnson): Append where the udp servers are actually used.
|
|
|
|
// config.UDPServers = append(config.UDPServers, UDPInputConfig{
|
|
|
|
// Enabled: tomlConfiguration.InputPlugins.UDPInput.Enabled,
|
|
|
|
// Database: tomlConfiguration.InputPlugins.UDPInput.Database,
|
|
|
|
// Port: tomlConfiguration.InputPlugins.UDPInput.Port,
|
|
|
|
// })
|
|
|
|
|
|
|
|
return c
|
|
|
|
}
|
|
|
|
|
2014-12-30 22:46:50 +00:00
|
|
|
// PointBatchSize returns the data point batch size, if set.
|
2014-10-21 05:32:47 +00:00
|
|
|
// If not set, the LevelDB point batch size is returned.
|
|
|
|
// If that is not set then the default point batch size is returned.
|
|
|
|
func (c *Config) PointBatchSize() int {
|
2014-12-30 22:46:50 +00:00
|
|
|
if c.Data.PointBatchSize != 0 {
|
|
|
|
return c.Data.PointBatchSize
|
2014-10-21 05:32:47 +00:00
|
|
|
}
|
|
|
|
return DefaultPointBatchSize
|
|
|
|
}
|
|
|
|
|
2014-12-30 22:46:50 +00:00
|
|
|
// WriteBatchSize returns the data write batch size, if set.
|
2014-10-21 05:32:47 +00:00
|
|
|
// If not set, the LevelDB write batch size is returned.
|
|
|
|
// If that is not set then the default write batch size is returned.
|
|
|
|
func (c *Config) WriteBatchSize() int {
|
2014-12-30 22:46:50 +00:00
|
|
|
if c.Data.WriteBatchSize != 0 {
|
|
|
|
return c.Data.WriteBatchSize
|
2014-10-21 05:32:47 +00:00
|
|
|
}
|
|
|
|
return DefaultWriteBatchSize
|
|
|
|
}
|
|
|
|
|
|
|
|
// MaxOpenShards returns the maximum number of shards to keep open at once.
|
|
|
|
func (c *Config) MaxOpenShards() int {
|
2014-12-30 22:46:50 +00:00
|
|
|
return c.Data.MaxOpenShards
|
2014-10-21 05:32:47 +00:00
|
|
|
}
|
|
|
|
|
2014-12-16 06:05:01 +00:00
|
|
|
// ApiHTTPListenAddr returns the binding address the API HTTP server
|
|
|
|
func (c *Config) ApiHTTPListenAddr() string {
|
|
|
|
return fmt.Sprintf("%s:%d", c.BindAddress, c.HTTPAPI.Port)
|
|
|
|
}
|
|
|
|
|
2014-12-30 22:46:50 +00:00
|
|
|
// BrokerListenAddr returns the binding address the Broker server
|
|
|
|
func (c *Config) BrokerListenAddr() string {
|
|
|
|
return fmt.Sprintf("%s:%d", c.BindAddress, c.Broker.Port)
|
2014-12-16 06:05:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-30 22:46:50 +00:00
|
|
|
// BrokerConnectionString returns the address required to contact the Broker server
|
|
|
|
func (c *Config) BrokerConnectionString() string {
|
|
|
|
return fmt.Sprintf("http://%s:%d", c.Hostname, c.Broker.Port)
|
2014-12-19 16:51:24 +00:00
|
|
|
}
|
|
|
|
|
2014-10-21 05:32:47 +00:00
|
|
|
// Size represents a TOML parseable file size.
|
|
|
|
// Users can specify size using "m" for megabytes and "g" for gigabytes.
|
|
|
|
type Size int
|
|
|
|
|
|
|
|
// UnmarshalText parses a byte size from text.
|
|
|
|
func (s *Size) UnmarshalText(text []byte) error {
|
|
|
|
// Parse numeric portion of value.
|
|
|
|
length := len(string(text))
|
|
|
|
size, err := strconv.ParseInt(string(text[:length-1]), 10, 64)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse unit of measure ("m", "g", etc).
|
|
|
|
switch suffix := text[len(text)-1]; suffix {
|
|
|
|
case 'm':
|
|
|
|
size *= 1 << 20 // MB
|
|
|
|
case 'g':
|
|
|
|
size *= 1 << 30 // GB
|
|
|
|
default:
|
|
|
|
return fmt.Errorf("unknown size suffix: %c", suffix)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check for overflow.
|
|
|
|
if size > maxInt {
|
|
|
|
return fmt.Errorf("size %d cannot be represented by an int", size)
|
|
|
|
}
|
|
|
|
|
|
|
|
*s = Size(size)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Duration is a TOML wrapper type for time.Duration.
|
|
|
|
type Duration time.Duration
|
|
|
|
|
|
|
|
// UnmarshalText parses a TOML value into a duration value.
|
|
|
|
func (d *Duration) UnmarshalText(text []byte) error {
|
|
|
|
// Ignore if there is no value set.
|
|
|
|
if len(text) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise parse as a duration formatted string.
|
|
|
|
duration, err := time.ParseDuration(string(text))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set duration and return.
|
|
|
|
*d = Duration(duration)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseConfigFile parses a configuration file at a given path.
|
|
|
|
func ParseConfigFile(path string) (*Config, error) {
|
|
|
|
c := NewConfig()
|
|
|
|
if _, err := toml.DecodeFile(path, &c); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ParseConfig parses a configuration string into a config object.
|
|
|
|
func ParseConfig(s string) (*Config, error) {
|
|
|
|
c := NewConfig()
|
|
|
|
if _, err := toml.Decode(s, &c); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return c, nil
|
|
|
|
}
|
|
|
|
|
2015-01-07 08:02:58 +00:00
|
|
|
// ConnnectionString returns the connection string for this Graphite config in the form host:port.
|
2015-01-08 00:15:39 +00:00
|
|
|
func (g *Graphite) ConnectionString(defaultBindAddr string) string {
|
2014-12-30 22:46:33 +00:00
|
|
|
|
2015-01-08 20:19:44 +00:00
|
|
|
addr := g.Addr
|
2015-01-06 22:26:31 +00:00
|
|
|
// If no address specified, use default.
|
2015-01-08 20:19:44 +00:00
|
|
|
if addr == "" {
|
2015-01-06 22:26:31 +00:00
|
|
|
addr = defaultBindAddr
|
2014-12-30 22:46:33 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 20:19:44 +00:00
|
|
|
port := g.Port
|
2015-01-06 22:26:31 +00:00
|
|
|
// If no port specified, use default.
|
2015-01-08 20:19:44 +00:00
|
|
|
if port == 0 {
|
2015-01-08 19:10:38 +00:00
|
|
|
port = graphite.DefaultGraphitePort
|
2014-12-30 22:46:33 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 20:19:44 +00:00
|
|
|
return fmt.Sprintf("%s:%d", addr, port)
|
2014-12-30 22:46:33 +00:00
|
|
|
}
|
|
|
|
|
2015-01-08 19:10:38 +00:00
|
|
|
// NameSeparatorString returns the character separating fields for Graphite data, or the default
|
2015-01-08 00:15:39 +00:00
|
|
|
// if no separator is set.
|
|
|
|
func (g *Graphite) NameSeparatorString() string {
|
|
|
|
if g.NameSeparator == "" {
|
2015-01-08 19:10:38 +00:00
|
|
|
return graphite.DefaultGraphiteNameSeparator
|
2015-01-08 00:15:39 +00:00
|
|
|
}
|
|
|
|
return g.NameSeparator
|
|
|
|
}
|
|
|
|
|
2015-01-08 20:23:48 +00:00
|
|
|
func (g *Graphite) LastEnabled() bool {
|
|
|
|
return g.NamePosition == strings.ToLower("last")
|
|
|
|
}
|
|
|
|
|
2014-10-21 05:32:47 +00:00
|
|
|
/*
|
|
|
|
func (c *Config) AdminHTTPPortString() string {
|
|
|
|
if c.AdminHTTPPort <= 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s:%d", c.BindAddress, c.AdminHTTPPort)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) APIHTTPSPortString() string {
|
|
|
|
return fmt.Sprintf("%s:%d", c.BindAddress, c.APIHTTPSPort)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) GraphitePortString() string {
|
|
|
|
if c.GraphitePort <= 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s:%d", c.BindAddress, c.GraphitePort)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) UDPInputPortString(port int) string {
|
|
|
|
if port <= 0 {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%s:%d", c.BindAddress, port)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) ProtobufConnectionString() string {
|
|
|
|
return fmt.Sprintf("%s:%d", c.Hostname, c.ProtobufPort)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Config) ProtobufListenString() string {
|
|
|
|
return fmt.Sprintf("%s:%d", c.BindAddress, c.ProtobufPort)
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
// maxInt is the largest integer representable by a word (architeture dependent).
|
|
|
|
const maxInt = int64(^uint(0) >> 1)
|