Register pprof handlers

Increase the write timeout to one minute to allow CPU profiling
This commit is contained in:
Stefan Prodan
2018-02-08 13:24:47 +02:00
parent 6b6978a30c
commit 71e5cc6eab
2 changed files with 11 additions and 4 deletions

View File

@@ -3,7 +3,7 @@ package server
import (
"context"
"net/http"
_ "net/http/pprof"
"net/http/pprof"
"runtime"
"sync/atomic"
"time"
@@ -22,7 +22,7 @@ type Server struct {
}
func NewServer(options ...func(*Server)) *Server {
s := &Server{mux: http.DefaultServeMux}
s := &Server{mux: http.NewServeMux()}
for _, f := range options {
f(s)
@@ -40,6 +40,13 @@ func NewServer(options ...func(*Server)) *Server {
s.mux.HandleFunc("/version", s.version)
s.mux.Handle("/metrics", promhttp.Handler())
// Register pprof handlers
s.mux.HandleFunc("/debug/pprof/", pprof.Index)
s.mux.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
s.mux.HandleFunc("/debug/pprof/profile", pprof.Profile)
s.mux.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
s.mux.HandleFunc("/debug/pprof/trace", pprof.Trace)
return s
}
@@ -55,7 +62,7 @@ func ListenAndServe(port string, timeout time.Duration, stopCh <-chan struct{})
Addr: ":" + port,
Handler: inst.Wrap(NewServer()),
ReadTimeout: 5 * time.Second,
WriteTimeout: 10 * time.Second,
WriteTimeout: 1 * time.Minute,
IdleTimeout: 15 * time.Second,
}

View File

@@ -1,4 +1,4 @@
package version
var VERSION = "0.0.4"
var VERSION = "0.0.5"
var GITCOMMIT = "unknown"