@cryptotaxi247 / kubo / commits / df70fe4ac

Serve expvars and pprof on the API port

Tommi Virtanen committed Apr 28, 2015 at 16:36 UTC df70fe4ac79548bb0513e59235c62fb8756aa82a
1 file changed +16
cmd/ipfs/daemon.go
+16
@@ -1,7 +1,10 @@
1 package main
2
3 import (
4 + _ "expvar"
5 "fmt"
6 + "net/http"
7 + _ "net/http/pprof"
8 "os"
9 "strings"
10
@@ -76,6 +79,17 @@ the port as you would other services or database (firewall, authenticated proxy,
79 Run: daemonFunc,
80 }
81
82 +// defaultMux tells mux to serve path using the default muxer. This is
83 +// mostly useful to hook up things that register in the default muxer,
84 +// and don't provide a convenient http.Handler entry point, such as
85 +// expvar and http/pprof.
86 +func defaultMux(path string) func(node *core.IpfsNode, mux *http.ServeMux) (*http.ServeMux, error) {
87 + return func(node *core.IpfsNode, mux *http.ServeMux) (*http.ServeMux, error) {
88 + mux.Handle(path, http.DefaultServeMux)
89 + return mux, nil
90 + }
91 +}
92 +
93 func daemonFunc(req cmds.Request, res cmds.Response) {
94 // let the user know we're going.
95 fmt.Printf("Initializing daemon...\n")
@@ -281,6 +295,8 @@ func daemonFunc(req cmds.Request, res cmds.Response) {
295 corehttp.WebUIOption,
296 gateway.ServeOption(),
297 corehttp.VersionOption(),
298 + defaultMux("/debug/vars"),
299 + defaultMux("/debug/pprof/"),
300 }
301
302 if rootRedirect != nil {