Skip to content

Commit

Permalink
Allow graphite and collectd bind address to be set
Browse files Browse the repository at this point in the history
Fix #1055. Close #1056
  • Loading branch information
otoolep authored and jvshahid committed Oct 27, 2014
1 parent e27d3bb commit ffd9a4b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## v0.8.5 [unreleased]

### Features

- [Issue #1055](https://github.com/influxdb/influxdb/issues/1055). Allow
graphite and collectd input plugins to have separate binding address

### Bugfixes

- [Issue #821](https://github.com/influxdb/influxdb/issues/821). Don't
Expand Down
2 changes: 1 addition & 1 deletion api/collectd/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ type Server struct {
func NewServer(config *configuration.Configuration, coord api.Coordinator, clusterConfig *cluster.ClusterConfiguration) *Server {
s := &Server{}

s.listenAddress = config.CollectdPortString()
s.listenAddress = config.CollectdBindString()
s.database = config.CollectdDatabase
s.coordinator = coord
s.shutdown = make(chan bool, 1)
Expand Down
2 changes: 1 addition & 1 deletion api/graphite/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const max_queue = 20000
// TODO: check that database exists and create it if not
func NewServer(config *configuration.Configuration, coord api.Coordinator, clusterConfig *cluster.ClusterConfiguration) *Server {
self := &Server{}
self.listenAddress = config.GraphitePortString()
self.listenAddress = config.GraphiteBindString()
self.database = config.GraphiteDatabase
self.coordinator = coord
self.writeSeries = make(chan Record, max_queue)
Expand Down
2 changes: 2 additions & 0 deletions config.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ read-timeout = "5s"
# Configure the graphite api
[input_plugins.graphite]
enabled = false
# address = "0.0.0.0" # If not set, is actually set to bind-address.
# port = 2003
# database = "" # store graphite data in this database
# udp_enabled = true # enable udp interface on the same port as the tcp interface

# Configure the collectd api
[input_plugins.collectd]
enabled = false
# address = "0.0.0.0" # If not set, is actually set to bind-address.
# port = 25826
# database = ""
# types.db can be found in a collectd installation or on github:
Expand Down
22 changes: 18 additions & 4 deletions configuration/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ type ApiConfig struct {

type GraphiteConfig struct {
Enabled bool
Address string
Port int
Database string
UdpEnabled bool `toml:"udp_enabled"`
}

type CollectdInputConfig struct {
Enabled bool
Address string
Port int
Database string
TypesDB string `toml:"typesdb"`
Expand Down Expand Up @@ -172,11 +174,13 @@ type Configuration struct {
ApiReadTimeout time.Duration

GraphiteEnabled bool
GraphiteAddress string
GraphitePort int
GraphiteDatabase string
GraphiteUdpEnabled bool

CollectdEnabled bool
CollectdAddress string
CollectdPort int
CollectdDatabase string
CollectdTypesDB string
Expand Down Expand Up @@ -316,11 +320,13 @@ func parseTomlConfiguration(filename string) (*Configuration, error) {
ApiReadTimeout: apiReadTimeout,

GraphiteEnabled: tomlConfiguration.InputPlugins.Graphite.Enabled,
GraphiteAddress: tomlConfiguration.InputPlugins.Graphite.Address,
GraphitePort: tomlConfiguration.InputPlugins.Graphite.Port,
GraphiteDatabase: tomlConfiguration.InputPlugins.Graphite.Database,
GraphiteUdpEnabled: tomlConfiguration.InputPlugins.Graphite.UdpEnabled,

CollectdEnabled: tomlConfiguration.InputPlugins.CollectdInput.Enabled,
CollectdAddress: tomlConfiguration.InputPlugins.CollectdInput.Address,
CollectdPort: tomlConfiguration.InputPlugins.CollectdInput.Port,
CollectdDatabase: tomlConfiguration.InputPlugins.CollectdInput.Database,
CollectdTypesDB: tomlConfiguration.InputPlugins.CollectdInput.TypesDB,
Expand Down Expand Up @@ -422,20 +428,28 @@ func (self *Configuration) ApiHttpSslPortString() string {
return fmt.Sprintf("%s:%d", self.BindAddress, self.ApiHttpSslPort)
}

func (self *Configuration) GraphitePortString() string {
func (self *Configuration) GraphiteBindString() string {
if self.GraphitePort <= 0 {
return ""
}

return fmt.Sprintf("%s:%d", self.BindAddress, self.GraphitePort)
if self.GraphiteAddress != "" {
return fmt.Sprintf("%s:%d", self.GraphiteAddress, self.GraphitePort)
} else {
return fmt.Sprintf("%s:%d", self.BindAddress, self.GraphitePort)
}
}

func (self *Configuration) CollectdPortString() string {
func (self *Configuration) CollectdBindString() string {
if self.CollectdPort <= 0 {
return ""
}

return fmt.Sprintf("%s:%d", self.BindAddress, self.CollectdPort)
if self.CollectdAddress != "" {
return fmt.Sprintf("%s:%d", self.CollectdAddress, self.CollectdPort)
} else {
return fmt.Sprintf("%s:%d", self.BindAddress, self.CollectdPort)
}
}

func (self *Configuration) UdpInputPortString(port int) string {
Expand Down
4 changes: 2 additions & 2 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func (self *Server) ListenAndServe() error {
} else if self.Config.GraphiteDatabase == "" {
log.Warn(fail_reason("database name is invalid"))
} else {
log.Info("Starting Graphite Listener on port %d", self.Config.GraphitePort)
log.Info("Starting Graphite Listener on %s", self.Config.GraphiteBindString())
go self.GraphiteApi.ListenAndServe()
}
} else {
Expand All @@ -171,7 +171,7 @@ func (self *Server) ListenAndServe() error {
} else if _, err := os.Stat(self.Config.CollectdTypesDB); err != nil {
log.Warn(failReason("types.db is invalid"))
} else {
log.Info("Starting Collectd Listener on port %d", self.Config.CollectdPort)
log.Info("Starting Collectd Listener on %s", self.Config.CollectdBindString())
go self.CollectdApi.ListenAndServe()
}
} else {
Expand Down

0 comments on commit ffd9a4b

Please sign in to comment.