本文整理汇总了Golang中net/http/pprof.Handler函数的典型用法代码示例。如果您正苦于以下问题:Golang Handler函数的具体用法?Golang Handler怎么用?Golang Handler使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Handler函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Start
func (app *Application) Start() {
address := Config.GetString("Address")
port := Config.GetInt("Port")
debug := Config.GetBool("Debug")
tmplPath := Config.GetString("TemplatePath")
listen := fmt.Sprintf("%s:%d", address, port)
templates = loadTemplate()
watcher = NewWatcher()
watcher.Listen(tmplPath)
mux := http.NewServeMux()
if debug {
mux.Handle("/debug/pprof", http.HandlerFunc(pprof.Index))
mux.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
mux.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
mux.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
mux.Handle("/debug/pprof/heap", pprof.Handler("heap"))
mux.Handle("/debug/pprof/block", pprof.Handler("block"))
mux.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
mux.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
}
mux.Handle("/", app.Route)
l, err := net.Listen("tcp", listen)
if err != nil {
log.Fatal(err)
}
log.Println("Listening on " + listen + "...")
log.Fatal(http.Serve(l, mux))
}
示例2: ServeHTTP
func (s *httpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
switch req.URL.Path {
case "/registration":
s.registerHandler(w, req)
case "/ping":
s.pingHandler(w, req)
case "/info":
s.infoHandler(w, req)
case "/debug/pprof":
httpprof.Index(w, req)
case "/debug/pprof/cmdline":
httpprof.Cmdline(w, req)
case "/debug/pprof/symbol":
httpprof.Symbol(w, req)
case "/debug/pprof/heap":
httpprof.Handler("heap").ServeHTTP(w, req)
case "/debug/pprof/goroutine":
httpprof.Handler("goroutine").ServeHTTP(w, req)
case "/debug/pprof/profile":
httpprof.Profile(w, req)
case "/debug/pprof/block":
httpprof.Handler("block").ServeHTTP(w, req)
case "/debug/pprof/threadcreate":
httpprof.Handler("threadcreate").ServeHTTP(w, req)
default:
log.Printf("ERROR: 404 %s", req.URL.Path)
util.ApiResponse(w, 404, "NOT_FOUND", nil)
}
}
示例3: Run
// Run starts the web application and serves HTTP requests for s
func (s *Server) Run(addr string) {
s.initServer()
if s.muxrouter == nil {
s.muxrouter = mux.NewRouter()
}
if s.Config.Profiler {
s.muxrouter.Handle("/debug/pprof", http.HandlerFunc(pprof.Index))
s.muxrouter.Handle("/debug/pprof/cmdline", http.HandlerFunc(pprof.Cmdline))
s.muxrouter.Handle("/debug/pprof/profile", http.HandlerFunc(pprof.Profile))
s.muxrouter.Handle("/debug/pprof/symbol", http.HandlerFunc(pprof.Symbol))
s.muxrouter.Handle("/debug/pprof/heap", pprof.Handler("heap"))
s.muxrouter.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
s.muxrouter.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
s.muxrouter.Handle("/debug/pprof/block", pprof.Handler("block"))
}
s.muxrouter.Handle("/", s)
s.Logger.Printf("serving %s\n", addr)
l, err := net.Listen("tcp", addr)
if err != nil {
log.Fatal("ListenAndServe:", err)
}
s.l = l
err = http.Serve(s.l, s.muxrouter)
s.l.Close()
}
示例4: main
func main() {
doProfile := flag.Bool("profile", false, "profile app")
flag.Parse()
go cpu.Monitor()
go net.Monitor("eth0")
r := martini.Classic()
r.Get("/containers/:id/mem", containerMemUsageHandler)
r.Get("/containers/:id/cpu", containerCpuUsageHandler)
r.Get("/containers/:id/net", containerNetUsageHandler)
if *doProfile {
log.Println("Enable profiling")
r.Get("/debug/pprof", pprof.Index)
r.Get("/debug/pprof/cmdline", pprof.Cmdline)
r.Get("/debug/pprof/profile", pprof.Profile)
r.Get("/debug/pprof/symbol", pprof.Symbol)
r.Post("/debug/pprof/symbol", pprof.Symbol)
r.Get("/debug/pprof/block", pprof.Handler("block").ServeHTTP)
r.Get("/debug/pprof/heap", pprof.Handler("heap").ServeHTTP)
r.Get("/debug/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP)
r.Get("/debug/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP)
}
r.Run()
}
示例5: debugRouter
func (s *httpServer) debugRouter(w http.ResponseWriter, req *http.Request) error {
switch req.URL.Path {
case "/debug":
util.NegotiateAPIResponseWrapper(w, req,
func() (interface{}, error) { return s.doDebug(req) })
case "/debug/pprof":
httpprof.Index(w, req)
case "/debug/pprof/cmdline":
httpprof.Cmdline(w, req)
case "/debug/pprof/symbol":
httpprof.Symbol(w, req)
case "/debug/pprof/heap":
httpprof.Handler("heap").ServeHTTP(w, req)
case "/debug/pprof/goroutine":
httpprof.Handler("goroutine").ServeHTTP(w, req)
case "/debug/pprof/profile":
httpprof.Profile(w, req)
case "/debug/pprof/block":
httpprof.Handler("block").ServeHTTP(w, req)
case "/debug/pprof/threadcreate":
httpprof.Handler("threadcreate").ServeHTTP(w, req)
default:
return errors.New(fmt.Sprintf("404 %s", req.URL.Path))
}
return nil
}
示例6: RegisterDebug
// RegisterDebug adds handlers for /debug/vars (expvar) and /debug/pprof (net/http/pprof) support
func (this *HttpWeb) RegisterDebug(m *martini.ClassicMartini) {
m.Get("/debug/vars", func(w http.ResponseWriter, r *http.Request) {
// from expvar.go, since the expvarHandler isn't exported :(
w.Header().Set("Content-Type", "application/json; charset=utf-8")
fmt.Fprintf(w, "{\n")
first := true
expvar.Do(func(kv expvar.KeyValue) {
if !first {
fmt.Fprintf(w, ",\n")
}
first = false
fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value)
})
fmt.Fprintf(w, "\n}\n")
})
// list all the /debug/ endpoints we want
m.Get("/debug/pprof", pprof.Index)
m.Get("/debug/pprof/cmdline", pprof.Cmdline)
m.Get("/debug/pprof/profile", pprof.Profile)
m.Get("/debug/pprof/symbol", pprof.Symbol)
m.Post("/debug/pprof/symbol", pprof.Symbol)
m.Get("/debug/pprof/block", pprof.Handler("block").ServeHTTP)
m.Get("/debug/pprof/heap", pprof.Handler("heap").ServeHTTP)
m.Get("/debug/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP)
m.Get("/debug/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP)
}
示例7: newHTTPServer
func newHTTPServer(ctx *Context) *httpServer {
log := http_api.Log(nsqlookupLog)
// debug log only print when error or the level is larger than debug.
debugLog := http_api.DebugLog(nsqlookupLog)
router := httprouter.New()
router.HandleMethodNotAllowed = true
router.PanicHandler = http_api.LogPanicHandler(nsqlookupLog)
router.NotFound = http_api.LogNotFoundHandler(nsqlookupLog)
router.MethodNotAllowed = http_api.LogMethodNotAllowedHandler(nsqlookupLog)
s := &httpServer{
ctx: ctx,
router: router,
}
router.Handle("GET", "/ping", http_api.Decorate(s.pingHandler, log, http_api.PlainText))
// v1 negotiate
router.Handle("GET", "/debug", http_api.Decorate(s.doDebug, log, http_api.NegotiateVersion))
router.Handle("GET", "/lookup", http_api.Decorate(s.doLookup, debugLog, http_api.NegotiateVersion))
router.Handle("GET", "/topics", http_api.Decorate(s.doTopics, log, http_api.NegotiateVersion))
router.Handle("GET", "/channels", http_api.Decorate(s.doChannels, log, http_api.NegotiateVersion))
router.Handle("GET", "/nodes", http_api.Decorate(s.doNodes, log, http_api.NegotiateVersion))
router.Handle("GET", "/listlookup", http_api.Decorate(s.doListLookup, log, http_api.NegotiateVersion))
router.Handle("GET", "/cluster/stats", http_api.Decorate(s.doClusterStats, debugLog, http_api.V1))
router.Handle("POST", "/cluster/node/remove", http_api.Decorate(s.doRemoveClusterDataNode, log, http_api.V1))
router.Handle("POST", "/cluster/upgrade/begin", http_api.Decorate(s.doClusterBeginUpgrade, log, http_api.V1))
router.Handle("POST", "/cluster/upgrade/done", http_api.Decorate(s.doClusterFinishUpgrade, log, http_api.V1))
router.Handle("POST", "/cluster/lookupd/tombstone", http_api.Decorate(s.doClusterTombstoneLookupd, log, http_api.V1))
// only v1
router.Handle("POST", "/loglevel/set", http_api.Decorate(s.doSetLogLevel, log, http_api.V1))
router.Handle("POST", "/topic/create", http_api.Decorate(s.doCreateTopic, log, http_api.V1))
router.Handle("PUT", "/topic/create", http_api.Decorate(s.doCreateTopic, log, http_api.V1))
router.Handle("POST", "/topic/delete", http_api.Decorate(s.doDeleteTopic, log, http_api.V1))
router.Handle("POST", "/topic/partition/expand", http_api.Decorate(s.doChangeTopicPartitionNum, log, http_api.V1))
router.Handle("POST", "/topic/partition/move", http_api.Decorate(s.doMoveTopicParition, log, http_api.V1))
router.Handle("POST", "/topic/meta/update", http_api.Decorate(s.doChangeTopicDynamicParam, log, http_api.V1))
//router.Handle("POST", "/channel/create", http_api.Decorate(s.doCreateChannel, log, http_api.V1))
//router.Handle("POST", "/channel/delete", http_api.Decorate(s.doDeleteChannel, log, http_api.V1))
router.Handle("POST", "/topic/tombstone", http_api.Decorate(s.doTombstoneTopicProducer, log, http_api.V1))
router.Handle("GET", "/info", http_api.Decorate(s.doInfo, log, http_api.NegotiateVersion))
// debug
router.HandlerFunc("GET", "/debug/pprof", pprof.Index)
router.HandlerFunc("GET", "/debug/pprof/cmdline", pprof.Cmdline)
router.HandlerFunc("GET", "/debug/pprof/symbol", pprof.Symbol)
router.HandlerFunc("POST", "/debug/pprof/symbol", pprof.Symbol)
router.HandlerFunc("GET", "/debug/pprof/profile", pprof.Profile)
router.HandlerFunc("GET", "/debug/pprof/trace", pprof.Trace)
router.Handler("GET", "/debug/pprof/heap", pprof.Handler("heap"))
router.Handler("GET", "/debug/pprof/goroutine", pprof.Handler("goroutine"))
router.Handler("GET", "/debug/pprof/block", pprof.Handler("block"))
router.Handle("PUT", "/debug/setblockrate", http_api.Decorate(HandleBlockRate, log, http_api.PlainText))
router.Handler("GET", "/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
return s
}
示例8: AttachProfiler
func AttachProfiler(router *mux.Router) {
router.HandleFunc("/debug/pprof/", pprof.Index)
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
router.HandleFunc("/debug/pprof/heap", pprof.Handler("heap").ServeHTTP)
router.HandleFunc("/debug/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP)
router.HandleFunc("/debug/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP)
}
示例9: ServeHTTP
func (s *httpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
switch req.URL.Path {
case "/pub":
fallthrough
case "/put":
s.putHandler(w, req)
case "/mpub":
fallthrough
case "/mput":
s.mputHandler(w, req)
case "/stats":
s.statsHandler(w, req)
case "/ping":
s.pingHandler(w, req)
case "/info":
s.infoHandler(w, req)
case "/empty_topic":
s.emptyTopicHandler(w, req)
case "/delete_topic":
s.deleteTopicHandler(w, req)
case "/pause_topic":
s.pauseTopicHandler(w, req)
case "/unpause_topic":
s.pauseTopicHandler(w, req)
case "/empty_channel":
s.emptyChannelHandler(w, req)
case "/delete_channel":
s.deleteChannelHandler(w, req)
case "/pause_channel":
s.pauseChannelHandler(w, req)
case "/unpause_channel":
s.pauseChannelHandler(w, req)
case "/create_topic":
s.createTopicHandler(w, req)
case "/create_channel":
s.createChannelHandler(w, req)
case "/debug/pprof":
httpprof.Index(w, req)
case "/debug/pprof/cmdline":
httpprof.Cmdline(w, req)
case "/debug/pprof/symbol":
httpprof.Symbol(w, req)
case "/debug/pprof/heap":
httpprof.Handler("heap").ServeHTTP(w, req)
case "/debug/pprof/goroutine":
httpprof.Handler("goroutine").ServeHTTP(w, req)
case "/debug/pprof/profile":
httpprof.Profile(w, req)
case "/debug/pprof/block":
httpprof.Handler("block").ServeHTTP(w, req)
case "/debug/pprof/threadcreate":
httpprof.Handler("threadcreate").ServeHTTP(w, req)
default:
log.Printf("ERROR: 404 %s", req.URL.Path)
util.ApiResponse(w, 404, "NOT_FOUND", nil)
}
}
示例10: main
func main() {
log.Println("Starting go-sig/web")
if path := os.Getenv("IMG_PATH"); path != "" {
imageRoot = path
}
log.Printf("Using image root: %s", imageRoot)
if _, err := os.Stat(imageRoot); os.IsNotExist(err) {
os.MkdirAll(imageRoot, 0750)
}
if procs := os.Getenv("PROCS"); procs != "" {
if p, err := strconv.Atoi(procs); err != nil {
runtime.GOMAXPROCS(p)
}
}
if key := os.Getenv("AES_KEY"); key != "" {
util.AES_KEY = []byte(key)
}
disableLogging := os.Getenv("DISABLE_LOGGING")
if disableLogging == "1" || disableLogging == "true" {
log.SetOutput(new(NullWriter))
}
// Routes
log.Println("Mapping routes...")
goji.Get("/", index)
// Setup static files
static := web.New()
static.Get("/assets/*", http.StripPrefix("/assets/", http.FileServer(http.Dir(publicPath))))
http.Handle("/assets/", static)
profile := os.Getenv("ENABLE_DEBUG")
if profile == "1" || profile == "true" {
log.Println("Mapping debug routes...")
goji.Handle("/debug/pprof/", pprof.Index)
goji.Handle("/debug/pprof/cmdline", pprof.Cmdline)
goji.Handle("/debug/pprof/profile", pprof.Profile)
goji.Handle("/debug/pprof/symbol", pprof.Symbol)
goji.Handle("/debug/pprof/block", pprof.Handler("block").ServeHTTP)
goji.Handle("/debug/pprof/heap", pprof.Handler("heap").ServeHTTP)
goji.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP)
goji.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP)
}
// Generators
log.Println("Registering generators...")
registerGenerator(new(rs3.BoxGoalGenerator))
registerGenerator(new(multi.MultiGoalGenerator))
//registerGenerator(new(rs3.ExampleGenerator))
// Serve
goji.Serve()
}
示例11: registerProfilerController
func registerProfilerController(router *mux.Router) {
router.HandleFunc("/debug/pprof/", pprof.Index)
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
router.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
router.Handle("/debug/pprof/heap", pprof.Handler("heap"))
router.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
router.Handle("/debug/pprof/block", pprof.Handler("block"))
}
示例12: newHTTPServer
func newHTTPServer(ctx *Context) *httpServer {
log := http_api.Log(ctx.nsqlookupd.opts.Logger)
router := httprouter.New()
router.HandleMethodNotAllowed = true
router.PanicHandler = http_api.LogPanicHandler(ctx.nsqlookupd.opts.Logger)
router.NotFound = http_api.LogNotFoundHandler(ctx.nsqlookupd.opts.Logger)
router.MethodNotAllowed = http_api.LogMethodNotAllowedHandler(ctx.nsqlookupd.opts.Logger)
s := &httpServer{
ctx: ctx,
router: router,
}
router.Handle("GET", "/ping", http_api.Decorate(s.pingHandler, log, http_api.PlainText))
// v1 negotiate
router.Handle("GET", "/debug", http_api.Decorate(s.doDebug, log, http_api.NegotiateVersion))
router.Handle("GET", "/lookup", http_api.Decorate(s.doLookup, log, http_api.NegotiateVersion))
router.Handle("GET", "/topics", http_api.Decorate(s.doTopics, log, http_api.NegotiateVersion))
router.Handle("GET", "/channels", http_api.Decorate(s.doChannels, log, http_api.NegotiateVersion))
router.Handle("GET", "/nodes", http_api.Decorate(s.doNodes, log, http_api.NegotiateVersion))
// only v1
router.Handle("POST", "/topic/create", http_api.Decorate(s.doCreateTopic, log, http_api.V1))
router.Handle("POST", "/topic/delete", http_api.Decorate(s.doDeleteTopic, log, http_api.V1))
router.Handle("POST", "/channel/create", http_api.Decorate(s.doCreateChannel, log, http_api.V1))
router.Handle("POST", "/channel/delete", http_api.Decorate(s.doDeleteChannel, log, http_api.V1))
router.Handle("POST", "/topic/tombstone", http_api.Decorate(s.doTombstoneTopicProducer, log, http_api.V1))
// deprecated, v1 negotiate
router.Handle("GET", "/info", http_api.Decorate(s.doInfo, log, http_api.NegotiateVersion))
router.Handle("POST", "/create_topic", http_api.Decorate(s.doCreateTopic, log, http_api.NegotiateVersion))
router.Handle("POST", "/delete_topic", http_api.Decorate(s.doDeleteTopic, log, http_api.NegotiateVersion))
router.Handle("POST", "/create_channel", http_api.Decorate(s.doCreateChannel, log, http_api.NegotiateVersion))
router.Handle("POST", "/delete_channel", http_api.Decorate(s.doDeleteChannel, log, http_api.NegotiateVersion))
router.Handle("POST", "/tombstone_topic_producer", http_api.Decorate(s.doTombstoneTopicProducer, log, http_api.NegotiateVersion))
router.Handle("GET", "/create_topic", http_api.Decorate(s.doCreateTopic, log, http_api.NegotiateVersion))
router.Handle("GET", "/delete_topic", http_api.Decorate(s.doDeleteTopic, log, http_api.NegotiateVersion))
router.Handle("GET", "/create_channel", http_api.Decorate(s.doCreateChannel, log, http_api.NegotiateVersion))
router.Handle("GET", "/delete_channel", http_api.Decorate(s.doDeleteChannel, log, http_api.NegotiateVersion))
router.Handle("GET", "/tombstone_topic_producer", http_api.Decorate(s.doTombstoneTopicProducer, log, http_api.NegotiateVersion))
// debug
router.HandlerFunc("GET", "/debug/pprof", pprof.Index)
router.HandlerFunc("GET", "/debug/pprof/cmdline", pprof.Cmdline)
router.HandlerFunc("GET", "/debug/pprof/symbol", pprof.Symbol)
router.HandlerFunc("POST", "/debug/pprof/symbol", pprof.Symbol)
router.HandlerFunc("GET", "/debug/pprof/profile", pprof.Profile)
router.Handler("GET", "/debug/pprof/heap", pprof.Handler("heap"))
router.Handler("GET", "/debug/pprof/goroutine", pprof.Handler("goroutine"))
router.Handler("GET", "/debug/pprof/block", pprof.Handler("block"))
router.Handler("GET", "/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
return s
}
示例13: Enable
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)
}
示例14: profilerSetup
func profilerSetup(mainRouter *mux.Router) {
var r = mainRouter.PathPrefix(debugPathPrefix).Subrouter()
r.HandleFunc("/vars", expVars)
r.HandleFunc("/pprof/", pprof.Index)
r.HandleFunc("/pprof/cmdline", pprof.Cmdline)
r.HandleFunc("/pprof/profile", pprof.Profile)
r.HandleFunc("/pprof/symbol", pprof.Symbol)
r.HandleFunc("/pprof/block", pprof.Handler("block").ServeHTTP)
r.HandleFunc("/pprof/heap", pprof.Handler("heap").ServeHTTP)
r.HandleFunc("/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP)
r.HandleFunc("/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP)
}
示例15: AttachProfiler
func AttachProfiler(router *mux.Router) {
router.HandleFunc("/debug/pprof/", pprof.Index)
router.HandleFunc("/debug/pprof/cmdline", pprof.Cmdline)
router.HandleFunc("/debug/pprof/profile", pprof.Profile)
router.HandleFunc("/debug/pprof/symbol", pprof.Symbol)
// Manually add support for paths linked to by index page at /debug/pprof/
router.Handle("/debug/pprof/goroutine", pprof.Handler("goroutine"))
router.Handle("/debug/pprof/heap", pprof.Handler("heap"))
router.Handle("/debug/pprof/threadcreate", pprof.Handler("threadcreate"))
router.Handle("/debug/pprof/block", pprof.Handler("block"))
}