From 6a55169e2e0d039f7404b236b321fa7c76b99618 Mon Sep 17 00:00:00 2001 From: Paul Nasrat Date: Tue, 3 Dec 2013 13:04:18 -0500 Subject: [PATCH] Expose expvar endpoint during debugging. Fixes #3017 --- api.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/api.go b/api.go index da16044410..62486ca9d8 100644 --- a/api.go +++ b/api.go @@ -6,6 +6,7 @@ import ( "code.google.com/p/go.net/websocket" "encoding/base64" "encoding/json" + "expvar" "fmt" "github.com/dotcloud/docker/archive" "github.com/dotcloud/docker/auth" @@ -1063,7 +1064,23 @@ func makeHttpHandler(srv *Server, logging bool, localMethod string, localRoute s } } +// Replicated from expvar.go as not public. +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") +} + func AttachProfiler(router *mux.Router) { + router.HandleFunc("/debug/vars", expvarHandler) router.HandleFunc("/debug/pprof/", pprof.Index) router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) router.HandleFunc("/debug/pprof/profile", pprof.Profile)