mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-22 18:52:41 +01:00
Merge pull request #210 from slingamn/pprof.2
add an option to expose a pprof http endpoint
This commit is contained in:
commit
c6124f9d8a
@ -237,7 +237,8 @@ type Config struct {
|
||||
Logging []logger.LoggingConfig
|
||||
|
||||
Debug struct {
|
||||
RecoverFromErrors *bool `yaml:"recover-from-errors"`
|
||||
RecoverFromErrors *bool `yaml:"recover-from-errors"`
|
||||
PprofListener *string `yaml:"pprof-listener"`
|
||||
StackImpact StackImpactConfig
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,8 @@ import (
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
_ "net/http/pprof"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
@ -120,6 +122,7 @@ type Server struct {
|
||||
recoverFromErrors bool
|
||||
rehashMutex sync.Mutex // tier 4
|
||||
rehashSignal chan os.Signal
|
||||
pprofServer *http.Server
|
||||
proxyAllowedFrom []string
|
||||
signals chan os.Signal
|
||||
snomasks *SnoManager
|
||||
@ -968,6 +971,8 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
|
||||
}
|
||||
}
|
||||
|
||||
server.setupPprofListener(config)
|
||||
|
||||
// we are now open for business
|
||||
server.setupListeners(config)
|
||||
|
||||
@ -987,6 +992,32 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
|
||||
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 {
|
||||
server.logger.Info("rehash", "Using MOTD", motdPath)
|
||||
motdLines := make([]string, 0)
|
||||
|
@ -316,6 +316,12 @@ debug:
|
||||
# this to false.
|
||||
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
|
||||
stackimpact:
|
||||
# whether to use StackImpact
|
||||
|
Loading…
Reference in New Issue
Block a user