Add -metrics-path flag for configuring the metrics endpoint

Addresses #52
This commit is contained in:
Marius 2016-07-19 10:45:07 +02:00
parent 930a63c058
commit 30edfb1209
3 changed files with 6 additions and 2 deletions

View File

@ -17,6 +17,7 @@ var Flags struct {
HooksDir string HooksDir string
ShowVersion bool ShowVersion bool
ExposeMetrics bool ExposeMetrics bool
MetricsPath string
BehindProxy bool BehindProxy bool
HooksInstalled bool HooksInstalled bool
@ -34,6 +35,7 @@ func ParseFlags() {
flag.StringVar(&Flags.HooksDir, "hooks-dir", "", "Directory to search for available hooks scripts") 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.ShowVersion, "version", false, "Print tusd version information")
flag.BoolVar(&Flags.ExposeMetrics, "expose-metrics", true, "Expose metrics about tusd usage") 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.BoolVar(&Flags.BehindProxy, "behind-proxy", false, "Respect X-Forwarded-* and similar headers which may be set by proxies")
flag.Parse() flag.Parse()

View File

@ -18,5 +18,6 @@ func SetupMetrics(handler *tusd.Handler) {
prometheus.MustRegister(MetricsOpenConnections) prometheus.MustRegister(MetricsOpenConnections)
prometheus.MustRegister(prometheuscollector.New(handler.Metrics)) 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())
} }

View File

@ -27,7 +27,6 @@ func Serve() {
stdout.Printf("Using %s as address to listen.\n", address) stdout.Printf("Using %s as address to listen.\n", address)
stdout.Printf("Using %s as the base path.\n", basepath) stdout.Printf("Using %s as the base path.\n", basepath)
stdout.Printf(Composer.Capabilities())
SetupPostHooks(handler) SetupPostHooks(handler)
@ -35,6 +34,8 @@ func Serve() {
SetupMetrics(handler) SetupMetrics(handler)
} }
stdout.Printf(Composer.Capabilities())
// Do not display the greeting if the tusd handler will be mounted at the root // 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. // path. Else this would cause a "multiple registrations for /" panic.
if basepath != "/" { if basepath != "/" {