diff --git a/internal/api/api.go b/internal/api/api.go index 4c3d5e7f..425b22e4 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -6,6 +6,7 @@ import ( "fmt" "net" "net/http" + "net/http/pprof" "os" "strconv" "strings" @@ -32,6 +33,7 @@ func Init() { TLSCert string `yaml:"tls_cert"` TLSKey string `yaml:"tls_key"` UnixListen string `yaml:"unix_listen"` + Pprof bool `yaml:"pprof"` } `yaml:"api"` } @@ -45,6 +47,9 @@ func Init() { return } + // overwrite default mux with new mux to avoid pprof auto registering + http.DefaultServeMux = http.NewServeMux() + basePath = cfg.Mod.BasePath log = app.GetLogger("api") @@ -56,6 +61,14 @@ func Init() { HandleFunc("api/restart", restartHandler) HandleFunc("api/log", logHandler) + if cfg.Mod.Pprof { + HandleFunc("/debug/pprof/", pprof.Index) + HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + HandleFunc("/debug/pprof/profile", pprof.Profile) + HandleFunc("/debug/pprof/symbol", pprof.Symbol) + HandleFunc("/debug/pprof/trace", pprof.Trace) + } + Handler = http.DefaultServeMux // 4th if cfg.Mod.Origin == "*" {