Skip to content

Commit

Permalink
Allow listening on specific IP addresses
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Pivotto <[email protected]>
  • Loading branch information
roidelapluie committed Apr 9, 2018
1 parent 7bc9386 commit 7f745f3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions conf/example.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# listen_port defines the port on which Trickster's Proxy server listens.
# since this is a proxy for Prometheus, we use 9090 by default, just like Prometheus does
# listen_port = 9090
# listen_address defines the ip on which Trickster's Proxy server listens.
# empty by default, listening on all interfaces
# listen_address =

[cache]
# cache_type defines what kind of cache Trickster uses
Expand Down Expand Up @@ -82,6 +85,9 @@

# listen_port defines the port that Trickster's metrics server listens on at /metrics
listen_port = 8082
# listen_address defines the ip that Trickster's metrics server listens on at /metrics
# empty by default, listening on all interfaces
# listen_address =

# Configuration Options for Logging Instrumentation
[logging]
Expand Down
5 changes: 5 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ type GeneralConfig struct {

// ProxyServerConfig is a collection of configurations for the main http listener for the application
type ProxyServerConfig struct {
// ListenAddress is IP address for the main http listener for the application
ListenAddress string `toml:"listen_address"`
// ListenPort is TCP Port for the main http listener for the application
ListenPort int `toml:"listen_port"`
}

Expand Down Expand Up @@ -70,6 +73,8 @@ type PrometheusOriginConfig struct {

// MetricsConfig is a collection of Metrics Collection configurations
type MetricsConfig struct {
// ListenAddress is IP address from which the Application Metrics are available for pulling at /metrics
ListenAddress string `toml:"listen_address"`
// ListenPort is TCP Port from which the Application Metrics are available for pulling at /metrics
ListenPort int `toml:"listen_port"`
}
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ func main() {
// Catch All for Single-Origin proxy
router.PathPrefix("/").HandlerFunc(t.promFullProxyHandler).Methods("GET")

level.Info(t.Logger).Log("event", "proxy http endpoint starting", "port", t.Config.ProxyServer.ListenPort)
level.Info(t.Logger).Log("event", "proxy http endpoint starting", "address", t.Config.ProxyServer.ListenAddress, "port", t.Config.ProxyServer.ListenPort)

// Start the Server
err := http.ListenAndServe(fmt.Sprintf(":%d", t.Config.ProxyServer.ListenPort), handlers.CompressHandler(router))
err := http.ListenAndServe(fmt.Sprintf("%s:%d", t.Config.ProxyServer.ListenAddress, t.Config.ProxyServer.ListenPort), handlers.CompressHandler(router))
level.Error(t.Logger).Log("event", "exiting", "err", err)
}
4 changes: 2 additions & 2 deletions metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func NewApplicationMetrics(config *Config, logger log.Logger) *ApplicationMetric
if config.Metrics.ListenPort > 0 {
go func() {

level.Info(logger).Log("event", "metrics http endpoint starting", "port", fmt.Sprintf("%d", config.Metrics.ListenPort))
level.Info(logger).Log("event", "metrics http endpoint starting", "address", config.Metrics.ListenAddress, "port", fmt.Sprintf("%d", config.Metrics.ListenPort))

http.Handle("/metrics", promhttp.Handler())
if err := http.ListenAndServe(fmt.Sprintf(":%d", config.Metrics.ListenPort), nil); err != nil {
if err := http.ListenAndServe(fmt.Sprintf("%s:%d", config.Metrics.ListenAddress, config.Metrics.ListenPort), nil); err != nil {
level.Error(logger).Log("event", "unable to start metrics http server", "detail", err.Error())
os.Exit(1)
}
Expand Down

0 comments on commit 7f745f3

Please sign in to comment.