2020-07-06 09:18:16 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2022-07-26 13:29:07 +00:00
|
|
|
"net/http"
|
2020-07-06 09:18:16 +00:00
|
|
|
"net/http/pprof"
|
|
|
|
|
|
|
|
"github.com/spf13/viper"
|
2020-07-12 23:00:47 +00:00
|
|
|
"go.uber.org/zap"
|
2020-07-06 09:18:16 +00:00
|
|
|
)
|
|
|
|
|
2022-07-26 13:29:07 +00:00
|
|
|
// 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)
|
2020-07-13 09:51:21 +00:00
|
|
|
|
|
|
|
// Manually add support for paths linked to by index page at /debug/pprof/
|
|
|
|
for _, item := range []string{"allocs", "block", "heap", "goroutine", "mutex", "threadcreate"} {
|
2022-07-26 13:29:07 +00:00
|
|
|
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")),
|
2020-07-13 09:51:21 +00:00
|
|
|
}
|
2020-07-06 09:18:16 +00:00
|
|
|
}
|