2015-05-29 19:50:05 +00:00
|
|
|
package graphite
|
|
|
|
|
|
|
|
import "strings"
|
|
|
|
|
|
|
|
const (
|
2015-06-08 20:12:42 +00:00
|
|
|
// DefaultBindAddress is the default binding interface if none is specified.
|
|
|
|
DefaultBindAddress = ":2003"
|
|
|
|
|
2015-05-29 19:50:05 +00:00
|
|
|
// DefaultDatabase is the default database if none is specified.
|
|
|
|
DefaultDatabase = "graphite"
|
|
|
|
|
|
|
|
// DefaultNameSeparator represents the default field separator.
|
|
|
|
DefaultNameSeparator = "."
|
2015-06-08 20:12:42 +00:00
|
|
|
|
|
|
|
// DefaultNamePosition represents the default location of the name.
|
|
|
|
DefaultNamePosition = "last"
|
|
|
|
|
|
|
|
// DefaultProtocol is the default IP protocol used by the Graphite input.
|
|
|
|
DefaultProtocol = "tcp"
|
2015-05-29 19:50:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Config represents the configuration for Graphite endpoints.
|
|
|
|
type Config struct {
|
|
|
|
BindAddress string `toml:"bind-address"`
|
|
|
|
Database string `toml:"database"`
|
|
|
|
Enabled bool `toml:"enabled"`
|
|
|
|
Protocol string `toml:"protocol"`
|
|
|
|
NamePosition string `toml:"name-position"`
|
|
|
|
NameSeparator string `toml:"name-separator"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewConfig returns a new Config with defaults.
|
|
|
|
func NewConfig() Config {
|
|
|
|
return Config{
|
2015-06-08 20:12:42 +00:00
|
|
|
BindAddress: DefaultBindAddress,
|
2015-05-29 19:50:05 +00:00
|
|
|
Database: DefaultDatabase,
|
2015-06-08 20:12:42 +00:00
|
|
|
Protocol: DefaultProtocol,
|
|
|
|
NamePosition: DefaultNamePosition,
|
2015-05-29 19:50:05 +00:00
|
|
|
NameSeparator: DefaultNameSeparator,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// LastEnabled returns whether the server should interpret the last field as "name".
|
|
|
|
func (c *Config) LastEnabled() bool {
|
|
|
|
return c.NamePosition == strings.ToLower("last")
|
|
|
|
}
|