Merge pull request #76 from ellemouton/pprof

multi: profile server
This commit is contained in:
Oliver Gugger
2022-09-22 13:57:44 +02:00
committed by GitHub
3 changed files with 31 additions and 0 deletions

View File

@@ -37,6 +37,9 @@ import (
"google.golang.org/grpc/keepalive"
"google.golang.org/protobuf/encoding/protojson"
"gopkg.in/yaml.v2"
// Blank import to set up profiling HTTP handlers.
_ "net/http/pprof"
)
const (
@@ -185,6 +188,27 @@ func (a *Aperture) Start(errChan chan error) error {
"exporter: %v", err)
}
// Enable http profiling and validate profile port number if requested.
if a.cfg.ProfilePort != 0 {
if a.cfg.ProfilePort < 1024 || a.cfg.ProfilePort > 65535 {
return fmt.Errorf("the profile port must be between " +
"1024 and 65535")
}
go func() {
http.Handle("/", http.RedirectHandler(
"/debug/pprof", http.StatusSeeOther,
))
listenAddr := fmt.Sprintf(
"localhost:%d", a.cfg.ProfilePort,
)
log.Infof("Starting profile server at %s", listenAddr)
fmt.Println(http.ListenAndServe(listenAddr, nil))
}()
}
// Initialize our etcd client.
a.etcdClient, err = clientv3.New(clientv3.Config{
Endpoints: []string{a.cfg.Etcd.Host},

View File

@@ -125,6 +125,9 @@ type Config struct {
// BaseDir is a custom directory to store all aperture flies.
BaseDir string `long:"basedir" description:"Directory to place all of aperture's files in."`
// ProfilePort is the port on which the pprof profile will be served.
ProfilePort uint16 `long:"profile" description:"Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65535"`
}
func (c *Config) validate() error {

View File

@@ -19,6 +19,10 @@ debuglevel: "debug"
autocert: false
servername: aperture.example.com
# The port on which the pprof profile will be served. If no port is provided,
# the profile will not be served.
profile: 9999
# Settings for the lnd node used to generate payment requests. All of these
# options are required.
authenticator: