diff --git a/web.go b/web.go index 445a83bce..d6093db7e 100644 --- a/web.go +++ b/web.go @@ -2,9 +2,11 @@ package main import ( "encoding/json" + "expvar" "fmt" "io/ioutil" "net/http" + "runtime" log "github.com/Sirupsen/logrus" "github.com/containous/traefik/autogen" @@ -33,6 +35,14 @@ var ( }) ) +func init() { + expvar.Publish("Goroutines", expvar.Func(goroutines)) +} + +func goroutines() interface{} { + return runtime.NumGoroutine() +} + // Provide allows the provider to provide configurations to traefik // using the given configuration channel. func (provider *WebProvider) Provide(configurationChan chan<- types.ConfigMessage, pool *safe.Pool) error { @@ -97,6 +107,11 @@ func (provider *WebProvider) Provide(configurationChan chan<- types.ConfigMessag } } }() + + // expvars + if provider.server.globalConfiguration.Debug { + systemRouter.Methods("GET").Path("/debug/vars").HandlerFunc(expvarHandler) + } return nil } @@ -231,3 +246,17 @@ func (provider *WebProvider) getRouteHandler(response http.ResponseWriter, reque } http.NotFound(response, request) } + +func expvarHandler(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json; charset=utf-8") + fmt.Fprintf(w, "{\n") + first := true + expvar.Do(func(kv expvar.KeyValue) { + if !first { + fmt.Fprintf(w, ",\n") + } + first = false + fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value) + }) + fmt.Fprintf(w, "\n}\n") +}