|
4 | 4 | "context" |
5 | 5 | "errors" |
6 | 6 | "net/http" |
| 7 | + "net/http/pprof" |
7 | 8 | "os" |
8 | 9 | "os/signal" |
9 | 10 | "syscall" |
@@ -64,17 +65,31 @@ func New(cfg *config.Config) (*Server, error) { |
64 | 65 | s.rpc = rpc |
65 | 66 | } |
66 | 67 |
|
67 | | - mux := http.NewServeMux() |
68 | | - mux.Handle("/", promhttp.Handler()) |
69 | | - mux.Handle("/metrics", promhttp.Handler()) |
70 | | - |
71 | | - s.metrics = &http.Server{ |
72 | | - Addr: cfg.Metrics.ListenAddress, |
73 | | - Handler: mux, |
74 | | - MaxHeaderBytes: 1024, |
75 | | - ReadHeaderTimeout: 30 * time.Second, |
76 | | - ReadTimeout: 30 * time.Second, |
77 | | - WriteTimeout: 30 * time.Second, |
| 68 | + { |
| 69 | + mux := http.NewServeMux() |
| 70 | + mux.Handle("/", promhttp.Handler()) |
| 71 | + mux.Handle("/metrics", promhttp.Handler()) |
| 72 | + |
| 73 | + s.metrics = &http.Server{ |
| 74 | + Addr: cfg.Metrics.ListenAddress, |
| 75 | + Handler: mux, |
| 76 | + MaxHeaderBytes: 1024, |
| 77 | + ReadHeaderTimeout: 30 * time.Second, |
| 78 | + ReadTimeout: 30 * time.Second, |
| 79 | + WriteTimeout: 30 * time.Second, |
| 80 | + } |
| 81 | + } |
| 82 | + |
| 83 | + if cfg.Pprof.ListenAddress != "" { |
| 84 | + go func() { |
| 85 | + mux := http.NewServeMux() |
| 86 | + mux.HandleFunc("/debug/pprof/", pprof.Index) |
| 87 | + mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline) |
| 88 | + mux.HandleFunc("/debug/pprof/profile", pprof.Profile) |
| 89 | + mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol) |
| 90 | + mux.HandleFunc("/debug/pprof/trace", pprof.Trace) |
| 91 | + _ = http.ListenAndServe(cfg.Pprof.ListenAddress, mux) |
| 92 | + }() |
78 | 93 | } |
79 | 94 |
|
80 | 95 | return s, nil |
|
0 commit comments