From df70fe4ac79548bb0513e59235c62fb8756aa82a Mon Sep 17 00:00:00 2001 From: Tommi Virtanen <tv@eagain.net> Date: Tue, 28 Apr 2015 16:36:48 -0700 Subject: [PATCH] Serve expvars and pprof on the API port --- cmd/ipfs/daemon.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmd/ipfs/daemon.go b/cmd/ipfs/daemon.go index 0e6aae370..37b860976 100644 --- a/cmd/ipfs/daemon.go +++ b/cmd/ipfs/daemon.go @@ -1,7 +1,10 @@ package main import ( + _ "expvar" "fmt" + "net/http" + _ "net/http/pprof" "os" "strings" @@ -76,6 +79,17 @@ the port as you would other services or database (firewall, authenticated proxy, Run: daemonFunc, } +// defaultMux tells mux to serve path using the default muxer. This is +// mostly useful to hook up things that register in the default muxer, +// and don't provide a convenient http.Handler entry point, such as +// expvar and http/pprof. +func defaultMux(path string) func(node *core.IpfsNode, mux *http.ServeMux) (*http.ServeMux, error) { + return func(node *core.IpfsNode, mux *http.ServeMux) (*http.ServeMux, error) { + mux.Handle(path, http.DefaultServeMux) + return mux, nil + } +} + func daemonFunc(req cmds.Request, res cmds.Response) { // let the user know we're going. fmt.Printf("Initializing daemon...\n") @@ -281,6 +295,8 @@ func daemonFunc(req cmds.Request, res cmds.Response) { corehttp.WebUIOption, gateway.ServeOption(), corehttp.VersionOption(), + defaultMux("/debug/vars"), + defaultMux("/debug/pprof/"), } if rootRedirect != nil { -- GitLab