Refactor api/http to just pprof

Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
Michael Crosby 2016-09-20 10:22:19 -07:00
parent 058eea362a
commit 435a1c825d
3 changed files with 23 additions and 27 deletions

View file

@ -1,23 +0,0 @@
package pprof
import (
// expvar init routine adds the "/debug/vars" handler
_ "expvar"
"net/http"
"net/http/pprof"
"github.com/Sirupsen/logrus"
)
// Enable registers the "/debug/pprof" handler
func Enable(address string) {
http.Handle("/", http.RedirectHandler("/debug/pprof", http.StatusMovedPermanently))
http.Handle("/debug/pprof/block", pprof.Handler("block"))
http.Handle("/debug/pprof/heap", pprof.Handler("heap"))
http.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
http.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
go http.ListenAndServe(address, nil)
logrus.Debug("pprof listening in address %s", address)
}

18
api/pprof/pprof.go Normal file
View file

@ -0,0 +1,18 @@
package pprof
import (
// expvar init routine adds the "/debug/vars" handler
_ "expvar"
"net/http"
"net/http/pprof"
)
// New returns a new handler serving pprof information
func New() http.Handler {
mux := http.NewServeMux()
mux.Handle("/pprof/block", pprof.Handler("block"))
mux.Handle("/pprof/heap", pprof.Handler("heap"))
mux.Handle("/pprof/goroutine", pprof.Handler("goroutine"))
mux.Handle("/pprof/threadcreate", pprof.Handler("threadcreate"))
return mux
}