From 30edfb12092f261b7401d18ebc79a6c48120ab81 Mon Sep 17 00:00:00 2001 From: Marius Date: Tue, 19 Jul 2016 10:45:07 +0200 Subject: [PATCH] Add -metrics-path flag for configuring the metrics endpoint Addresses #52 --- cmd/tusd/cli/flags.go | 2 ++ cmd/tusd/cli/metrics.go | 3 ++- cmd/tusd/cli/serve.go | 3 ++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/tusd/cli/flags.go b/cmd/tusd/cli/flags.go index 20c8af2..f8f4dcf 100644 --- a/cmd/tusd/cli/flags.go +++ b/cmd/tusd/cli/flags.go @@ -17,6 +17,7 @@ var Flags struct { HooksDir string ShowVersion bool ExposeMetrics bool + MetricsPath string BehindProxy bool HooksInstalled bool @@ -34,6 +35,7 @@ func ParseFlags() { flag.StringVar(&Flags.HooksDir, "hooks-dir", "", "Directory to search for available hooks scripts") flag.BoolVar(&Flags.ShowVersion, "version", false, "Print tusd version information") flag.BoolVar(&Flags.ExposeMetrics, "expose-metrics", true, "Expose metrics about tusd usage") + flag.StringVar(&Flags.MetricsPath, "metrics-path", "/metrics", "Path under which the metrics endpoint will be accessible") flag.BoolVar(&Flags.BehindProxy, "behind-proxy", false, "Respect X-Forwarded-* and similar headers which may be set by proxies") flag.Parse() diff --git a/cmd/tusd/cli/metrics.go b/cmd/tusd/cli/metrics.go index 2894b0e..921d67a 100644 --- a/cmd/tusd/cli/metrics.go +++ b/cmd/tusd/cli/metrics.go @@ -18,5 +18,6 @@ func SetupMetrics(handler *tusd.Handler) { prometheus.MustRegister(MetricsOpenConnections) prometheus.MustRegister(prometheuscollector.New(handler.Metrics)) - http.Handle("/metrics", prometheus.Handler()) + stdout.Printf("Using %s as the metrics path.\n", Flags.MetricsPath) + http.Handle(Flags.MetricsPath, prometheus.Handler()) } diff --git a/cmd/tusd/cli/serve.go b/cmd/tusd/cli/serve.go index 53cad7e..37d6317 100644 --- a/cmd/tusd/cli/serve.go +++ b/cmd/tusd/cli/serve.go @@ -27,7 +27,6 @@ func Serve() { stdout.Printf("Using %s as address to listen.\n", address) stdout.Printf("Using %s as the base path.\n", basepath) - stdout.Printf(Composer.Capabilities()) SetupPostHooks(handler) @@ -35,6 +34,8 @@ func Serve() { SetupMetrics(handler) } + stdout.Printf(Composer.Capabilities()) + // Do not display the greeting if the tusd handler will be mounted at the root // path. Else this would cause a "multiple registrations for /" panic. if basepath != "/" {