From e31cf7b1375bf5ea45c649e81fc19070c218ae6f Mon Sep 17 00:00:00 2001 From: j4ckstraw Date: Sun, 8 Oct 2023 10:49:24 +0800 Subject: [PATCH] fix: fix pprof by register handlers explicitly see https://pkg.go.dev/net/http/pprof > By default, all the profiles listed in runtime/pprof.Profile are available (via Handler), in addition to the Cmdline, Profile, Symbol, and Trace profiles defined in this package. If you are not using DefaultServeMux, you will have to register handlers with the mux you are using. Signed-off-by: j4ckstraw --- pkg/exporters/k8sexporter/k8s_exporter.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/exporters/k8sexporter/k8s_exporter.go b/pkg/exporters/k8sexporter/k8s_exporter.go index e6161570..31ec9c79 100644 --- a/pkg/exporters/k8sexporter/k8s_exporter.go +++ b/pkg/exporters/k8sexporter/k8s_exporter.go @@ -20,7 +20,7 @@ import ( "context" "net" "net/http" - _ "net/http/pprof" + "net/http/pprof" "strconv" "k8s.io/klog/v2" @@ -95,6 +95,13 @@ func (ke *k8sExporter) startHTTPReporting(npdo *options.NodeProblemDetectorOptio util.ReturnHTTPJson(w, ke.conditionManager.GetConditions()) }) + // register pprof + 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) + addr := net.JoinHostPort(npdo.ServerAddress, strconv.Itoa(npdo.ServerPort)) go func() { err := http.ListenAndServe(addr, mux)