From 72343fbbec811d50b7909ab558aefe0f0b32f3e3 Mon Sep 17 00:00:00 2001 From: David Anderson Date: Tue, 15 Jun 2021 21:27:54 -0700 Subject: [PATCH] tsweb: register expvars once at startup. Signed-off-by: David Anderson --- tsweb/tsweb.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tsweb/tsweb.go b/tsweb/tsweb.go index a7299b607..80bc8e0c5 100644 --- a/tsweb/tsweb.go +++ b/tsweb/tsweb.go @@ -29,6 +29,11 @@ import ( "tailscale.com/types/logger" ) +func init() { + expvar.Publish("counter_uptime_sec", expvar.Func(func() interface{} { return int64(Uptime().Seconds()) })) + expvar.Publish("gauge_goroutines", expvar.Func(func() interface{} { return runtime.NumGoroutine() })) +} + // DevMode controls whether extra output in shown, for when the binary is being run in dev mode. var DevMode bool @@ -41,8 +46,6 @@ func NewMux(debugHandler http.Handler) *http.ServeMux { } func registerCommonDebug(mux *http.ServeMux) { - expvar.Publish("counter_uptime_sec", expvar.Func(func() interface{} { return int64(Uptime().Seconds()) })) - expvar.Publish("gauge_goroutines", expvar.Func(func() interface{} { return runtime.NumGoroutine() })) mux.Handle("/debug/pprof/", Protected(http.DefaultServeMux)) // to net/http/pprof mux.Handle("/debug/vars", Protected(http.DefaultServeMux)) // to expvar mux.Handle("/debug/varz", Protected(http.HandlerFunc(VarzHandler)))