From 211ed6af991534a7a95437c9e6d0178927c008eb Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Tue, 13 Mar 2018 14:46:39 -0400 Subject: [PATCH 1/2] add an option to expose a pprof http endpoint --- irc/config.go | 3 ++- irc/server.go | 31 +++++++++++++++++++++++++++++++ oragono.yaml | 6 ++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/irc/config.go b/irc/config.go index a5600663..f0561e00 100644 --- a/irc/config.go +++ b/irc/config.go @@ -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 } diff --git a/irc/server.go b/irc/server.go index 8bd8bda0..9e6e0a22 100644 --- a/irc/server.go +++ b/irc/server.go @@ -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) diff --git a/oragono.yaml b/oragono.yaml index 76d11980..b4875e4f 100644 --- a/oragono.yaml +++ b/oragono.yaml @@ -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 From 288203152a090f44650bd2f29c644f344cc3861f Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Tue, 13 Mar 2018 18:04:15 -0400 Subject: [PATCH 2/2] comment out the pprof setting in the example config --- oragono.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oragono.yaml b/oragono.yaml index b4875e4f..af856724 100644 --- a/oragono.yaml +++ b/oragono.yaml @@ -320,7 +320,7 @@ debug: # 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" + # pprof-listener: "localhost:6060" # enabling StackImpact profiling stackimpact: