From 1dd6b0eac2b1da1ee79b1913739032c5b2cb03cf Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Fri, 1 May 2020 14:07:47 +0200 Subject: [PATCH 1/2] Add option to change metrics endpoint --- config/loader_flags.go | 5 +++-- config/structs.go | 6 ++++-- example-config.hcl | 5 +++++ go.sum | 1 + main.go | 6 ++++-- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/config/loader_flags.go b/config/loader_flags.go index f3d5a37..44767e7 100644 --- a/config/loader_flags.go +++ b/config/loader_flags.go @@ -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{ { diff --git a/config/structs.go b/config/structs.go index 72628ca..1f78407 100644 --- a/config/structs.go +++ b/config/structs.go @@ -9,6 +9,7 @@ type StartupFlags struct { Namespace string ListenPort int EnableExperimentalFeatures bool + MetricsEndpoint string CPUProfile string MemProfile string @@ -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 diff --git a/example-config.hcl b/example-config.hcl index fc06918..9adecc0 100644 --- a/example-config.hcl +++ b/example-config.hcl @@ -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 { diff --git a/go.sum b/go.sum index 5f05dba..0273161 100644 --- a/go.sum +++ b/go.sum @@ -110,6 +110,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= diff --git a/main.go b/main.go index c436f4c..901b810 100644 --- a/main.go +++ b/main.go @@ -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", }, } @@ -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() From 0975b098691271b033aba685804dfb0181c3a841 Mon Sep 17 00:00:00 2001 From: Martin Helmich Date: Fri, 1 May 2020 14:08:50 +0200 Subject: [PATCH 2/2] Adjust example in README --- README.adoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.adoc b/README.adoc index aead7e9..74c61d9 100644 --- a/README.adoc +++ b/README.adoc @@ -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 { @@ -126,6 +127,7 @@ The same file as YAML file: listen: port: 4040 address: "10.1.2.3" + metrics_endpoint: "/metrics" consul: enable: true