diff options
author | 2024-09-08 20:59:13 +0200 | |
---|---|---|
committer | 2024-09-08 21:31:18 +0200 | |
commit | 051131f03d46515307c2c19bf20ccdac36bd5fb6 (patch) | |
tree | a529fab3a6a60a80402ee8e8ba0560e35b458244 | |
parent | feat: reusable HTTP server runnable (diff) | |
download | cgit-httpd-051131f03d46515307c2c19bf20ccdac36bd5fb6.tar.xz |
feat: add pprof endpoints
-rw-r--r-- | config.go | 1 | ||||
-rw-r--r-- | contrib/config.example.edn | 1 | ||||
-rw-r--r-- | main.go | 19 |
3 files changed, 21 insertions, 0 deletions
@@ -11,6 +11,7 @@ import ( type Config struct { HTTP HTTPConfig `edn:"http"` + Pprof HTTPConfig `edn:"pprof"` CGit CGitConfig `edn:"cgit"` Git GitConfig `edn:"git"` ReposRoot string `edn:"repos-root"` diff --git a/contrib/config.example.edn b/contrib/config.example.edn index b66317f..41f7cee 100644 --- a/contrib/config.example.edn +++ b/contrib/config.example.edn @@ -1,5 +1,6 @@ ; Example configuration for cgit-httpd for Debian. {:http {:port 8080} + :pprof {:host "127.0.0.1" :port 8181} :repos-root "/srv/git" :cgit {:cgi "/usr/lib/cgit/cgit.cgi" :config-file "/etc/cgitrc" ; See cgitrc(5). @@ -7,6 +7,7 @@ import ( "flag" "net" "net/http" + "net/http/pprof" "os" "strconv" "time" @@ -68,6 +69,24 @@ func main() { }, }) + if cfg.Pprof.Port != 0 { + mux := http.NewServeMux() + + mux.HandleFunc("/debug/pprof/", pprof.Index) + mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) + mux.HandleFunc("/debug/pprof/profile", pprof.Profile) + mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) + mux.HandleFunc("/debug/pprof/trace", pprof.Trace) + + m.Add(&server.Server{ + Name: "pprof", + Server: &http.Server{ + Addr: net.JoinHostPort(cfg.Pprof.Host, strconv.Itoa(cfg.Pprof.Port)), + Handler: mux, + }, + }) + } + if err := m.Start(signals.SetupSignalHandler()); err != nil { logger.Info().Err(err).Msg("manager stopped") } |