|
@@ -13,6 +13,8 @@ import (
|
13
|
13
|
"log"
|
14
|
14
|
"math/rand"
|
15
|
15
|
"net"
|
|
16
|
+ "net/http"
|
|
17
|
+ _ "net/http/pprof"
|
16
|
18
|
"os"
|
17
|
19
|
"os/signal"
|
18
|
20
|
"strconv"
|
|
@@ -120,6 +122,7 @@ type Server struct {
|
120
|
122
|
recoverFromErrors bool
|
121
|
123
|
rehashMutex sync.Mutex // tier 4
|
122
|
124
|
rehashSignal chan os.Signal
|
|
125
|
+ pprofServer *http.Server
|
123
|
126
|
proxyAllowedFrom []string
|
124
|
127
|
signals chan os.Signal
|
125
|
128
|
snomasks *SnoManager
|
|
@@ -968,6 +971,8 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
|
968
|
971
|
}
|
969
|
972
|
}
|
970
|
973
|
|
|
974
|
+ server.setupPprofListener(config)
|
|
975
|
+
|
971
|
976
|
// we are now open for business
|
972
|
977
|
server.setupListeners(config)
|
973
|
978
|
|
|
@@ -987,6 +992,32 @@ func (server *Server) applyConfig(config *Config, initial bool) error {
|
987
|
992
|
return nil
|
988
|
993
|
}
|
989
|
994
|
|
|
995
|
+func (server *Server) setupPprofListener(config *Config) {
|
|
996
|
+ pprofListener := ""
|
|
997
|
+ if config.Debug.PprofListener != nil {
|
|
998
|
+ pprofListener = *config.Debug.PprofListener
|
|
999
|
+ }
|
|
1000
|
+ if server.pprofServer != nil {
|
|
1001
|
+ if pprofListener == "" || (pprofListener != server.pprofServer.Addr) {
|
|
1002
|
+ server.logger.Info("rehash", "Stopping pprof listener", server.pprofServer.Addr)
|
|
1003
|
+ server.pprofServer.Close()
|
|
1004
|
+ server.pprofServer = nil
|
|
1005
|
+ }
|
|
1006
|
+ }
|
|
1007
|
+ if pprofListener != "" && server.pprofServer == nil {
|
|
1008
|
+ ps := http.Server{
|
|
1009
|
+ Addr: pprofListener,
|
|
1010
|
+ }
|
|
1011
|
+ go func() {
|
|
1012
|
+ if err := ps.ListenAndServe(); err != nil {
|
|
1013
|
+ server.logger.Error("rehash", fmt.Sprintf("pprof listener failed: %v", err))
|
|
1014
|
+ }
|
|
1015
|
+ }()
|
|
1016
|
+ server.pprofServer = &ps
|
|
1017
|
+ server.logger.Info("rehash", "Started pprof listener", server.pprofServer.Addr)
|
|
1018
|
+ }
|
|
1019
|
+}
|
|
1020
|
+
|
990
|
1021
|
func (server *Server) loadMOTD(motdPath string, useFormatting bool) error {
|
991
|
1022
|
server.logger.Info("rehash", "Using MOTD", motdPath)
|
992
|
1023
|
motdLines := make([]string, 0)
|