Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(api): add pprof endpoint #1365

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net"
"net/http"
"net/http/pprof"
"os"
"strconv"
"strings"
Expand All @@ -30,6 +31,7 @@ func Init() {
TLSCert string `yaml:"tls_cert"`
TLSKey string `yaml:"tls_key"`
UnixListen string `yaml:"unix_listen"`
Pprof bool `yaml:"pprof"`
} `yaml:"api"`
}

Expand All @@ -43,6 +45,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")

Expand All @@ -54,6 +59,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 == "*" {
Expand Down