mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-05-06 21:52:54 +08:00
fix(webconsole,monitor): pprof handlers of gorilla mux
This commit is contained in:
@@ -20,6 +20,8 @@ import (
|
||||
"net/http"
|
||||
"net/http/pprof"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"yunion.io/x/pkg/util/version"
|
||||
)
|
||||
|
||||
@@ -85,3 +87,26 @@ func profSymbol(_ context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
func profTrace(_ context.Context, w http.ResponseWriter, r *http.Request) {
|
||||
pprof.Trace(w, r)
|
||||
}
|
||||
|
||||
func AddMiscHandlersToMuxRouter(app *Application, root *mux.Router, enableProfiling bool) {
|
||||
adapterF := func(appHandleFunc func(ctx context.Context, w http.ResponseWriter, r *http.Request)) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
appHandleFunc(app.GetContext(), w, r)
|
||||
}
|
||||
}
|
||||
root.HandleFunc("/version", adapterF(VersionHandler))
|
||||
root.HandleFunc("/stats", adapterF(StatisticHandler))
|
||||
root.HandleFunc("/ping", adapterF(PingHandler))
|
||||
root.HandleFunc("/worker_stats", adapterF(WorkerStatsHandler))
|
||||
if enableProfiling {
|
||||
pp := "/debug/pprof"
|
||||
ppPath := func(sufix string) string {
|
||||
return fmt.Sprintf("%s/%s", pp, sufix)
|
||||
}
|
||||
root.HandleFunc(ppPath(""), pprof.Index)
|
||||
root.HandleFunc(ppPath("cmdline"), pprof.Cmdline)
|
||||
root.HandleFunc(ppPath("profile"), pprof.Profile)
|
||||
root.HandleFunc(ppPath("symbol"), pprof.Symbol)
|
||||
root.HandleFunc(ppPath("trace"), pprof.Trace)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"strconv"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
@@ -31,6 +30,7 @@ import (
|
||||
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
|
||||
common_options "yunion.io/x/onecloud/pkg/cloudcommon/options"
|
||||
"yunion.io/x/onecloud/pkg/monitor/models"
|
||||
"yunion.io/x/onecloud/pkg/monitor/options"
|
||||
)
|
||||
|
||||
func InitHandlers(app *appsrv.Application) {
|
||||
@@ -126,13 +126,5 @@ func addMiscHandlers(app *appsrv.Application, root *mux.Router) {
|
||||
}
|
||||
}
|
||||
root.HandleFunc("/subscriptions/write", adapterF(performHandler))
|
||||
|
||||
// ref: pkg/appsrv/appsrv:addDefaultHandlers
|
||||
root.HandleFunc("/version", adapterF(appsrv.VersionHandler))
|
||||
root.HandleFunc("/stats", adapterF(appsrv.StatisticHandler))
|
||||
root.HandleFunc("/ping", adapterF(appsrv.PingHandler))
|
||||
root.HandleFunc("/worker_stats", adapterF(appsrv.WorkerStatsHandler))
|
||||
|
||||
// pprof handler
|
||||
root.PathPrefix("/debug/pprof/").Handler(http.DefaultServeMux)
|
||||
appsrv.AddMiscHandlersToMuxRouter(app, root, options.Options.EnableAppProfiling)
|
||||
}
|
||||
|
||||
@@ -15,10 +15,8 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"net/url"
|
||||
"os"
|
||||
"strconv"
|
||||
@@ -111,7 +109,7 @@ func start() {
|
||||
root.Handle(webconsole.WebsocketProxyPathPrefix, srv)
|
||||
|
||||
// misc handler
|
||||
addMiscHandlers(app, root)
|
||||
appsrv.AddMiscHandlersToMuxRouter(app, root, o.Options.EnableAppProfiling)
|
||||
|
||||
cron := cronman.InitCronJobManager(true, o.Options.CronJobWorkerCount)
|
||||
|
||||
@@ -137,20 +135,3 @@ func start() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func addMiscHandlers(app *appsrv.Application, root *mux.Router) {
|
||||
adapterF := func(appHandleFunc func(ctx context.Context, w http.ResponseWriter, r *http.Request)) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
appHandleFunc(app.GetContext(), w, r)
|
||||
}
|
||||
}
|
||||
|
||||
// ref: pkg/appsrv/appsrv:addDefaultHandlers
|
||||
root.HandleFunc("/version", adapterF(appsrv.VersionHandler))
|
||||
root.HandleFunc("/stats", adapterF(appsrv.StatisticHandler))
|
||||
root.HandleFunc("/ping", adapterF(appsrv.PingHandler))
|
||||
root.HandleFunc("/worker_stats", adapterF(appsrv.WorkerStatsHandler))
|
||||
|
||||
// pprof handler
|
||||
root.PathPrefix("/debug/pprof/").Handler(http.DefaultServeMux)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user