diff --git a/blockcache/cmd.go b/blockcache/cmd.go index fa7e69cc4..327c482e3 100644 --- a/blockcache/cmd.go +++ b/blockcache/cmd.go @@ -243,15 +243,24 @@ func main() { if profPort != "" { go func() { + mainMux := http.NewServeMux() mux := http.NewServeMux() - mux.HandleFunc(log.SetLogLevelPath, log.SetLogLevel) + http.HandleFunc(log.SetLogLevelPath, log.SetLogLevel) mux.Handle("/debug/pprof", http.HandlerFunc(pprof.Index)) mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace)) mux.Handle("/debug/", http.HandlerFunc(pprof.Index)) - e := http.ListenAndServe(fmt.Sprintf(":%v", profPort), mux) + mainHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + if strings.HasPrefix(req.URL.Path, "/debug/") { + mux.ServeHTTP(w, req) + } else { + http.DefaultServeMux.ServeHTTP(w, req) + } + }) + mainMux.Handle("/", mainHandler) + e := http.ListenAndServe(fmt.Sprintf(":%v", profPort), mainMux) if e != nil { log.LogFlush() err = errors.NewErrorf("cannot listen pprof %v err %v", profPort, err) diff --git a/client/fuse.go b/client/fuse.go index 35ee2f8cd..d55a66165 100644 --- a/client/fuse.go +++ b/client/fuse.go @@ -610,7 +610,7 @@ func mount(opt *proto.MountOptions) (fsConn *fuse.Conn, super *cfs.Super, err er if opt.LocallyProf { pprofAddr = "127.0.0.1:" + opt.Profport } - + mainMux := http.NewServeMux() mux := http.NewServeMux() mux.Handle("/debug/pprof", http.HandlerFunc(pprof.Index)) mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) @@ -618,8 +618,16 @@ func mount(opt *proto.MountOptions) (fsConn *fuse.Conn, super *cfs.Super, err er mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace)) mux.Handle("/debug/", http.HandlerFunc(pprof.Index)) + mainHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + if strings.HasPrefix(req.URL.Path, "/debug/") { + mux.ServeHTTP(w, req) + } else { + http.DefaultServeMux.ServeHTTP(w, req) + } + }) + mainMux.Handle("/", mainHandler) - go waitListenAndServe(statusCh, pprofAddr, mux) + go waitListenAndServe(statusCh, pprofAddr, mainMux) if err = <-statusCh; err != nil { daemonize.SignalOutcome(err) return diff --git a/cmd/cmd.go b/cmd/cmd.go index 469cc8f49..b54bc1c02 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -288,15 +288,24 @@ func main() { if profPort != "" { go func() { + mainMux := http.NewServeMux() mux := http.NewServeMux() - mux.HandleFunc(log.SetLogLevelPath, log.SetLogLevel) + http.HandleFunc(log.SetLogLevelPath, log.SetLogLevel) mux.Handle("/debug/pprof", http.HandlerFunc(pprof.Index)) mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace)) mux.Handle("/debug/", http.HandlerFunc(pprof.Index)) - e := http.ListenAndServe(fmt.Sprintf(":%v", profPort), mux) + mainHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + if strings.HasPrefix(req.URL.Path, "/debug/") { + mux.ServeHTTP(w, req) + } else { + http.DefaultServeMux.ServeHTTP(w, req) + } + }) + mainMux.Handle("/", mainHandler) + e := http.ListenAndServe(fmt.Sprintf(":%v", profPort), mainMux) if e != nil { log.LogFlush() err = errors.NewErrorf("cannot listen pprof %v err %v", profPort, e) diff --git a/preload/sdk/preloadsdk.go b/preload/sdk/preloadsdk.go index eef67ef18..5048f3a42 100644 --- a/preload/sdk/preloadsdk.go +++ b/preload/sdk/preloadsdk.go @@ -22,6 +22,7 @@ import ( "net/http/pprof" "path" gopath "path" + "strings" "sync" "sync/atomic" "time" @@ -94,15 +95,24 @@ func NewClient(config PreloadConfig) *PreLoadClient { if config.ProfPort != "" { go func() { + mainMux := http.NewServeMux() mux := http.NewServeMux() - mux.HandleFunc(log.SetLogLevelPath, log.SetLogLevel) + http.HandleFunc(log.SetLogLevelPath, log.SetLogLevel) mux.Handle("/debug/pprof", http.HandlerFunc(pprof.Index)) mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline)) mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile)) mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol)) mux.Handle("/debug/pprof/trace", http.HandlerFunc(pprof.Trace)) mux.Handle("/debug/", http.HandlerFunc(pprof.Index)) - e := http.ListenAndServe(fmt.Sprintf(":%v", config.ProfPort), mux) + mainHandler := http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { + if strings.HasPrefix(req.URL.Path, "/debug/") { + mux.ServeHTTP(w, req) + } else { + http.DefaultServeMux.ServeHTTP(w, req) + } + }) + mainMux.Handle("/", mainHandler) + e := http.ListenAndServe(fmt.Sprintf(":%v", config.ProfPort), mainMux) if e != nil { log.LogWarnf("newClient newEBSClient cannot listen pprof (%v)", config.ProfPort) }