Skip to content

Commit

Permalink
Merge pull request #115 from martin-helmich/feature/change-metrics-en…
Browse files Browse the repository at this point in the history
…dpoint

Add option to change metrics endpoint
  • Loading branch information
martin-helmich authored May 1, 2020
2 parents f2f463a + 0975b09 commit 77d3a99
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ is expected to be either in https://github.com/hashicorp/hcl[HCL] or YAML format
listen {
port = 4040
address = "10.1.2.3"
metrics_endpoint = "/metrics"
}
consul {
Expand Down Expand Up @@ -126,6 +127,7 @@ The same file as YAML file:
listen:
port: 4040
address: "10.1.2.3"
metrics_endpoint: "/metrics"
consul:
enable: true
Expand Down
5 changes: 3 additions & 2 deletions config/loader_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ package config
// values from command-line flags.
func LoadConfigFromFlags(config *Config, flags *StartupFlags) error {
config.Listen = ListenConfig{
Port: flags.ListenPort,
Address: "0.0.0.0",
Port: flags.ListenPort,
Address: "0.0.0.0",
MetricsEndpoint: flags.MetricsEndpoint,
}
config.Namespaces = []NamespaceConfig{
{
Expand Down
6 changes: 4 additions & 2 deletions config/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type StartupFlags struct {
Namespace string
ListenPort int
EnableExperimentalFeatures bool
MetricsEndpoint string

CPUProfile string
MemProfile string
Expand All @@ -29,8 +30,9 @@ type Config struct {

// ListenConfig is a struct describing the built-in webserver configuration
type ListenConfig struct {
Port int
Address string
Port int
Address string
MetricsEndpoint string `hcl:"metrics_endpoint" yaml:"metrics_endpoint"`
}

// ConsulConfig describes the connection to a Consul server that the exporter should
Expand Down
5 changes: 5 additions & 0 deletions example-config.hcl
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
listen {
port = 4040

// "metrics_endpoint" can be used to configure an alternative metrics URL
// path. Default value is "/metrics".
//
// metrics_endpoint = "/metrics"
}

consul {
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ func main() {
var opts config.StartupFlags
var cfg = config.Config{
Listen: config.ListenConfig{
Port: 4040,
Address: "0.0.0.0",
Port: 4040,
Address: "0.0.0.0",
MetricsEndpoint: "/metrics",
},
}

Expand All @@ -145,6 +146,7 @@ func main() {
flag.BoolVar(&opts.EnableExperimentalFeatures, "enable-experimental", false, "Set this flag to enable experimental features")
flag.StringVar(&opts.CPUProfile, "cpuprofile", "", "write cpu profile to `file`")
flag.StringVar(&opts.MemProfile, "memprofile", "", "write memory profile to `file`")
flag.StringVar(&opts.MetricsEndpoint, "metrics-endpoint", cfg.Listen.MetricsEndpoint, "URL path at which to serve metrics")
flag.Parse()

opts.Filenames = flag.Args()
Expand Down

0 comments on commit 77d3a99

Please sign in to comment.