mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-14 07:59:31 +01:00
add an option to expose a pprof http endpoint
This commit is contained in:
parent
b211fd35da
commit
211ed6af99
@ -237,7 +237,8 @@ type Config struct {
|
|||||||
Logging []logger.LoggingConfig
|
Logging []logger.LoggingConfig
|
||||||
|
|
||||||
Debug struct {
|
Debug struct {
|
||||||
RecoverFromErrors *bool `yaml:"recover-from-errors"`
|
RecoverFromErrors *bool `yaml:"recover-from-errors"`
|
||||||
|
PprofListener *string `yaml:"pprof-listener"`
|
||||||
StackImpact StackImpactConfig
|
StackImpact StackImpactConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,6 +13,8 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
|
_ "net/http/pprof"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -120,6 +122,7 @@ type Server struct {
|
|||||||
recoverFromErrors bool
|
recoverFromErrors bool
|
||||||
rehashMutex sync.Mutex // tier 4
|
rehashMutex sync.Mutex // tier 4
|
||||||
rehashSignal chan os.Signal
|
rehashSignal chan os.Signal
|
||||||
|
pprofServer *http.Server
|
||||||
proxyAllowedFrom []string
|
proxyAllowedFrom []string
|
||||||
signals chan os.Signal
|
signals chan os.Signal
|
||||||
snomasks *SnoManager
|
snomasks *SnoManager
|
||||||
@ -968,6 +971,8 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
server.setupPprofListener(config)
|
||||||
|
|
||||||
// we are now open for business
|
// we are now open for business
|
||||||
server.setupListeners(config)
|
server.setupListeners(config)
|
||||||
|
|
||||||
@ -987,6 +992,32 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (server *Server) setupPprofListener(config *Config) {
|
||||||
|
pprofListener := ""
|
||||||
|
if config.Debug.PprofListener != nil {
|
||||||
|
pprofListener = *config.Debug.PprofListener
|
||||||
|
}
|
||||||
|
if server.pprofServer != nil {
|
||||||
|
if pprofListener == "" || (pprofListener != server.pprofServer.Addr) {
|
||||||
|
server.logger.Info("rehash", "Stopping pprof listener", server.pprofServer.Addr)
|
||||||
|
server.pprofServer.Close()
|
||||||
|
server.pprofServer = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pprofListener != "" && server.pprofServer == nil {
|
||||||
|
ps := http.Server{
|
||||||
|
Addr: pprofListener,
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
if err := ps.ListenAndServe(); err != nil {
|
||||||
|
server.logger.Error("rehash", fmt.Sprintf("pprof listener failed: %v", err))
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
server.pprofServer = &ps
|
||||||
|
server.logger.Info("rehash", "Started pprof listener", server.pprofServer.Addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (server *Server) loadMOTD(motdPath string, useFormatting bool) error {
|
func (server *Server) loadMOTD(motdPath string, useFormatting bool) error {
|
||||||
server.logger.Info("rehash", "Using MOTD", motdPath)
|
server.logger.Info("rehash", "Using MOTD", motdPath)
|
||||||
motdLines := make([]string, 0)
|
motdLines := make([]string, 0)
|
||||||
|
@ -316,6 +316,12 @@ debug:
|
|||||||
# this to false.
|
# this to false.
|
||||||
recover-from-errors: true
|
recover-from-errors: true
|
||||||
|
|
||||||
|
# optionally expose a pprof http endpoint: https://golang.org/pkg/net/http/pprof/
|
||||||
|
# it is strongly recommended that you don't expose this on a public interface;
|
||||||
|
# if you need to access it remotely, you can use an SSH tunnel.
|
||||||
|
# set to `null`, "", leave blank, or omit to disable
|
||||||
|
pprof-listener: "localhost:6060"
|
||||||
|
|
||||||
# enabling StackImpact profiling
|
# enabling StackImpact profiling
|
||||||
stackimpact:
|
stackimpact:
|
||||||
# whether to use StackImpact
|
# whether to use StackImpact
|
||||||
|
Loading…
Reference in New Issue
Block a user