2019-12-04 06:48:32 +00:00
|
|
|
package metrics
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/http/pprof"
|
2019-12-30 07:43:05 +00:00
|
|
|
|
2022-07-08 16:10:46 +00:00
|
|
|
"github.com/nspcc-dev/neo-go/pkg/config"
|
2019-12-30 07:43:05 +00:00
|
|
|
"go.uber.org/zap"
|
2019-12-04 06:48:32 +00:00
|
|
|
)
|
2019-12-17 11:51:07 +00:00
|
|
|
|
2019-12-04 06:48:32 +00:00
|
|
|
// PprofService https://golang.org/pkg/net/http/pprof/.
|
|
|
|
type PprofService Service
|
|
|
|
|
2022-04-20 18:30:09 +00:00
|
|
|
// NewPprofService creates a new service for gathering pprof metrics.
|
2022-07-08 16:10:46 +00:00
|
|
|
func NewPprofService(cfg config.BasicService, log *zap.Logger) *Service {
|
2019-12-30 07:43:05 +00:00
|
|
|
if log == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-12-04 06:48:32 +00:00
|
|
|
handler := http.NewServeMux()
|
2019-12-17 11:49:28 +00:00
|
|
|
handler.HandleFunc("/debug/pprof/", pprof.Index)
|
2019-12-04 06:48:32 +00:00
|
|
|
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)
|
|
|
|
|
2022-11-25 10:20:53 +00:00
|
|
|
addrs := cfg.GetAddresses()
|
|
|
|
srvs := make([]*http.Server, len(addrs))
|
|
|
|
for i, addr := range addrs {
|
|
|
|
srvs[i] = &http.Server{
|
|
|
|
Addr: addr,
|
2019-12-04 06:48:32 +00:00
|
|
|
Handler: handler,
|
2022-11-25 10:20:53 +00:00
|
|
|
}
|
2019-12-04 06:48:32 +00:00
|
|
|
}
|
2022-11-25 10:20:53 +00:00
|
|
|
return NewService("Pprof", srvs, cfg, log)
|
2019-12-04 06:48:32 +00:00
|
|
|
}
|