mirror of
https://github.com/lightninglabs/aperture.git
synced 2025-12-17 17:14:19 +01:00
multi: add pprof
This commit adds a config option that can be set inorder to spin up a pprof profile server on the given port.
This commit is contained in:
24
aperture.go
24
aperture.go
@@ -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},
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user