neo-go/pkg/services/metrics/pprof.go
Anna Shaleva 9087854b1e services: allow multiple listen addresses for simple services
And deprecate the old way of Address/Port configuration for these services.
2022-12-07 11:23:01 +03:00

36 lines
913 B
Go

package metrics
import (
"net/http"
"net/http/pprof"
"github.com/nspcc-dev/neo-go/pkg/config"
"go.uber.org/zap"
)
// PprofService https://golang.org/pkg/net/http/pprof/.
type PprofService Service
// NewPprofService creates a new service for gathering pprof metrics.
func NewPprofService(cfg config.BasicService, log *zap.Logger) *Service {
if log == nil {
return nil
}
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)
addrs := cfg.GetAddresses()
srvs := make([]*http.Server, len(addrs))
for i, addr := range addrs {
srvs[i] = &http.Server{
Addr: addr,
Handler: handler,
}
}
return NewService("Pprof", srvs, cfg, log)
}