frostfs-s3-gw/cmd/s3-gw/app_profiler.go
Denis Kirillov e5c1acf1e5 [] Sync metrics and pprof configuration
Signed-off-by: Denis Kirillov <denis@nspcc.ru>
2022-07-29 09:32:08 +03:00

34 lines
1,022 B
Go

package main
import (
"net/http"
"net/http/pprof"
"github.com/spf13/viper"
"go.uber.org/zap"
)
// NewPprofService creates a new service for gathering pprof metrics.
func NewPprofService(v *viper.Viper, l *zap.Logger) *Service {
handler := http.NewServeMux()
handler.HandleFunc("/debug/pprof/", pprof.Index)
handler.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
handler.HandleFunc("/debug/pprof/profile", pprof.Profile)
handler.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
handler.HandleFunc("/debug/pprof/trace", pprof.Trace)
// Manually add support for paths linked to by index page at /debug/pprof/
for _, item := range []string{"allocs", "block", "heap", "goroutine", "mutex", "threadcreate"} {
handler.Handle("/debug/pprof/"+item, pprof.Handler(item))
}
return &Service{
Server: &http.Server{
Addr: v.GetString(cfgPProfAddress),
Handler: handler,
},
enabled: v.GetBool(cfgPProfEnabled),
serviceType: "Pprof",
log: l.With(zap.String("service", "Pprof")),
}
}