Files
PrivateCaptcha/pkg/monitoring/service_pprof.go
Taras Kushnir 2b36f8d10b Improve monitoring
- split metrics by service (API, portal, cdn, "common")
- fix domain name appended to path in metrics
- fix built-in http dashboard in Grafana
2025-06-08 13:27:37 +03:00

28 lines
773 B
Go

//go:build profile
package monitoring
import (
"context"
"log/slog"
"net/http"
"net/http/pprof"
)
// NOTE: (default) alternative would be to _ import the pprof package and start http server on :6060
func (s *Service) setupProfiling(ctx context.Context, mux *http.ServeMux) {
slog.DebugContext(ctx, "Enabling profiling endpoints")
mux.HandleFunc("/debug/pprof/", pprof.Index)
profiles := []string{"goroutine", "heap", "allocs", "threadcreate", "block", "mutex"}
for _, p := range profiles {
mux.Handle("/debug/pprof/"+p, pprof.Handler(p))
}
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)
}