コード例 #1
0
ファイル: pprof.go プロジェクト: fengbangyue/beego
func (this *ProfController) Get() {
	ptype := this.Ctx.Params[":pp"]
	if ptype == "" {
		pprof.Index(this.Ctx.ResponseWriter, this.Ctx.Request)
	} else if ptype == "cmdline" {
		pprof.Cmdline(this.Ctx.ResponseWriter, this.Ctx.Request)
	} else if ptype == "profile" {
		pprof.Profile(this.Ctx.ResponseWriter, this.Ctx.Request)
	} else if ptype == "symbol" {
		pprof.Symbol(this.Ctx.ResponseWriter, this.Ctx.Request)
	} else {
		pprof.Index(this.Ctx.ResponseWriter, this.Ctx.Request)
	}
	this.Ctx.ResponseWriter.WriteHeader(200)
}
コード例 #2
0
ファイル: pprof.go プロジェクト: johnvilsack/golang-stuff
func (this *ProfController) Get() {
	switch this.Ctx.Params[":pp"] {
	default:
		pprof.Index(this.Ctx.ResponseWriter, this.Ctx.Request)
	case "":
		pprof.Index(this.Ctx.ResponseWriter, this.Ctx.Request)
	case "cmdline":
		pprof.Cmdline(this.Ctx.ResponseWriter, this.Ctx.Request)
	case "profile":
		pprof.Profile(this.Ctx.ResponseWriter, this.Ctx.Request)
	case "symbol":
		pprof.Symbol(this.Ctx.ResponseWriter, this.Ctx.Request)
	}
	this.Ctx.ResponseWriter.WriteHeader(200)
}
コード例 #3
0
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	//h.statMap.Add(statRequest, 1)

	counter := metrics.GetOrRegisterCounter(statRequest, h.statMap)
	counter.Inc(1)

	meter := metrics.GetOrRegisterMeter(statRequestNew, h.statMap)
	meter.Mark(1)

	// FIXME(benbjohnson): Add pprof enabled flag.
	if strings.HasPrefix(r.URL.Path, "/debug/pprof") {
		switch r.URL.Path {
		case "/debug/pprof/cmdline":
			pprof.Cmdline(w, r)
		case "/debug/pprof/profile":
			pprof.Profile(w, r)
		case "/debug/pprof/symbol":
			pprof.Symbol(w, r)
		default:
			pprof.Index(w, r)
		}
	} else {
		h.mux.ServeHTTP(w, r)
		return
	}

}
コード例 #4
0
ファイル: pprof.go プロジェクト: zhenruyan/tsuru
func indexHandler(w http.ResponseWriter, r *http.Request, t auth.Token) error {
	if !permission.Check(t, permission.PermDebug) {
		return permission.ErrUnauthorized
	}
	pprof.Index(w, r)
	return nil
}
コード例 #5
0
ファイル: handler.go プロジェクト: zchee/scuttlebutt
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if strings.HasPrefix(r.URL.Path, "/debug/pprof") {
		switch r.URL.Path {
		case "/debug/pprof/cmdline":
			pprof.Cmdline(w, r)
		case "/debug/pprof/profile":
			pprof.Profile(w, r)
		case "/debug/pprof/symbol":
			pprof.Symbol(w, r)
		default:
			pprof.Index(w, r)
		}
		return
	}

	switch r.URL.Path {
	case "/":
		h.serveRoot(w, r)
	case "/top":
		h.serveTop(w, r)
	case "/top/stats":
		h.serveTopStats(w, r)
	case "/repositories":
		h.serveRepositories(w, r)
	case "/backup":
		h.serveBackup(w, r)
	case "/debug/vars":
		h.serveExpvars(w, r)
	default:
		http.NotFound(w, r)
	}
}
コード例 #6
0
ファイル: handler.go プロジェクト: sstarcher/kapacitor
// ServeHTTP responds to HTTP request to the handler.
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	h.statMap.Add(statRequest, 1)

	// FIXME(benbjohnson): Add pprof enabled flag.
	if strings.HasPrefix(r.URL.Path, "/debug/pprof") {
		switch r.URL.Path {
		case "/debug/pprof/cmdline":
			pprof.Cmdline(w, r)
		case "/debug/pprof/profile":
			pprof.Profile(w, r)
		case "/debug/pprof/symbol":
			pprof.Symbol(w, r)
		default:
			pprof.Index(w, r)
		}
	} else if strings.HasPrefix(r.URL.Path, "/debug/vars") {
		serveExpvar(w, r)
	} else {
		method := r.Method
		if method == "" {
			method = "GET"
		}
		if mux, ok := h.methodMux[method]; ok {
			mux.ServeHTTP(w, r)
		}
	}
}
コード例 #7
0
ファイル: httpSrv.go プロジェクト: vislee/goframe
func (hs *httpSrv) routerV01(w http.ResponseWriter, req *http.Request) {
	switch req.URL.Path {
	case "/ping":
		hs.pingHandler(w, req)
	case "/debug/pprof":
		setPub(w)
		httpprof.Index(w, req)
	case "/debug/pprof/block":
		hs.debugRuntime(w, req, "block")
	case "/debug/pprof/goroutine":
		hs.debugRuntime(w, req, "goroutine")
	case "/debug/pprof/heap":
		hs.debugRuntime(w, req, "heap")
	case "/debug/pprof/threadcreate":
		hs.debugRuntime(w, req, "threadcreate")
	case "/debug/pprof/profile":
		setPub(w)
		httpprof.Profile(w, req)
	case "/debug/pprof/cmdline":
		setPub(w)
		httpprof.Cmdline(w, req)
	case "/debug/pprof/symbol":
		setPub(w)
		httpprof.Symbol(w, req)
	default:
		RespondV1(w, 404, "page not found")
	}
}
コード例 #8
0
ファイル: handlers.go プロジェクト: titilambert/heapster
func setupHandlers(metricSink *metricsink.MetricSink, podLister *cache.StoreToPodLister) http.Handler {

	runningInKubernetes := true

	// Make API handler.
	wsContainer := restful.NewContainer()
	wsContainer.EnableContentEncoding(true)
	wsContainer.Router(restful.CurlyRouter{})
	a := v1.NewApi(runningInKubernetes, metricSink)
	a.Register(wsContainer)
	// Metrics API
	m := metricsApi.NewApi(metricSink, podLister)
	m.Register(wsContainer)

	handlePprofEndpoint := func(req *restful.Request, resp *restful.Response) {
		name := strings.TrimPrefix(req.Request.URL.Path, pprofBasePath)
		switch name {
		case "profile":
			pprof.Profile(resp, req.Request)
		case "symbol":
			pprof.Symbol(resp, req.Request)
		case "cmdline":
			pprof.Cmdline(resp, req.Request)
		default:
			pprof.Index(resp, req.Request)
		}
	}

	// Setup pporf handlers.
	ws := new(restful.WebService).Path(pprofBasePath)
	ws.Route(ws.GET("/{subpath:*}").To(metrics.InstrumentRouteFunc("pprof", handlePprofEndpoint))).Doc("pprof endpoint")
	wsContainer.Add(ws)

	return wsContainer
}
コード例 #9
0
ファイル: handler.go プロジェクト: CrazyUncleJack/influxdb
// ServeHTTP responds to HTTP request to the handler.
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	atomic.AddInt64(&h.stats.Requests, 1)
	atomic.AddInt64(&h.stats.ActiveRequests, 1)
	defer atomic.AddInt64(&h.stats.ActiveRequests, -1)
	start := time.Now()

	// Add version header to all InfluxDB requests.
	w.Header().Add("X-Influxdb-Version", h.Version)

	// FIXME(benbjohnson): Add pprof enabled flag.
	if strings.HasPrefix(r.URL.Path, "/debug/pprof") {
		switch r.URL.Path {
		case "/debug/pprof/cmdline":
			pprof.Cmdline(w, r)
		case "/debug/pprof/profile":
			pprof.Profile(w, r)
		case "/debug/pprof/symbol":
			pprof.Symbol(w, r)
		default:
			pprof.Index(w, r)
		}
	} else if strings.HasPrefix(r.URL.Path, "/debug/vars") {
		h.serveExpvar(w, r)
	} else {
		h.mux.ServeHTTP(w, r)
	}

	atomic.AddInt64(&h.stats.RequestDuration, time.Since(start).Nanoseconds())
}
コード例 #10
0
ファイル: http.go プロジェクト: horryq/nsq
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
}
コード例 #11
0
ファイル: uAdmin.go プロジェクト: henser123/uq
func (s *UnitedAdmin) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	if !utils.AllowMethod(w, req.Method, "HEAD", "GET", "POST", "PUT", "DELETE") {
		return
	}

	if strings.HasPrefix(req.URL.Path, queuePrefixV1) {
		key := req.URL.Path[len(queuePrefixV1):]
		s.queueHandler(w, req, key)
		return
	} else if strings.HasPrefix(req.URL.Path, adminPrefixV1) {
		key := req.URL.Path[len(adminPrefixV1):]
		s.adminHandler(w, req, key)
		return
	} else if strings.HasPrefix(req.URL.Path, pprofPrefixCmd) {
		httpprof.Cmdline(w, req)
		return
	} else if strings.HasPrefix(req.URL.Path, pprofPrefixProfile) {
		httpprof.Profile(w, req)
		return
	} else if strings.HasPrefix(req.URL.Path, pprofPrefixSymbol) {
		httpprof.Symbol(w, req)
		return
	} else if strings.HasPrefix(req.URL.Path, pprofPrefixIndex) {
		httpprof.Index(w, req)
		return
	}

	http.Error(w, "404 Not Found!", http.StatusNotFound)
	return
}
コード例 #12
0
ファイル: http.go プロジェクト: sharewind/push-server
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)
	}
}
コード例 #13
0
ファイル: handler.go プロジェクト: daneroo/go-ted1k
// ServeHTTP responds to HTTP request to the handler.
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	h.statMap.Add(statRequest, 1)
	h.statMap.Add(statRequestsActive, 1)
	start := time.Now()

	// FIXME(benbjohnson): Add pprof enabled flag.
	if strings.HasPrefix(r.URL.Path, "/debug/pprof") {
		switch r.URL.Path {
		case "/debug/pprof/cmdline":
			pprof.Cmdline(w, r)
		case "/debug/pprof/profile":
			pprof.Profile(w, r)
		case "/debug/pprof/symbol":
			pprof.Symbol(w, r)
		default:
			pprof.Index(w, r)
		}
	} else if strings.HasPrefix(r.URL.Path, "/debug/vars") {
		serveExpvar(w, r)
	} else {
		h.mux.ServeHTTP(w, r)
	}

	h.statMap.Add(statRequestsActive, -1)
	h.statMap.Add(statRequestDuration, time.Since(start).Nanoseconds())
}
コード例 #14
0
ファイル: config.go プロジェクト: issue9/web
// 根据 config.Pprof 决定是否包装调试地址
func (cfg *Config) buildPprof(h http.Handler) http.Handler {
	if len(cfg.Pprof) > 0 {
		logs.Debug("web:", "开启了调试功能,地址为:", cfg.Pprof)

		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			if !strings.HasPrefix(r.URL.Path, cfg.Pprof) {
				h.ServeHTTP(w, r)
				return
			}

			path := r.URL.Path[len(cfg.Pprof):]
			switch path {
			case "cmdline":
				pprof.Cmdline(w, r)
			case "profile":
				pprof.Profile(w, r)
			case "symbol":
				pprof.Symbol(w, r)
			case "trace":
				pprof.Trace(w, r)
			default:
				pprof.Index(w, r)
			}
		})
	}

	return h
}
コード例 #15
0
ファイル: pprof.go プロジェクト: dlapiduz/cf-deck
// Index responds with the pprof-formatted profile named by the request.
func (c *PProfContext) Index(rw web.ResponseWriter, req *web.Request) {
	// PPROF will automatically make paths for you. Need to make sure that the index has a / at the end.
	if !strings.HasSuffix(req.URL.Path, "/") {
		http.Redirect(rw, req.Request, req.URL.Path+"/", http.StatusMovedPermanently)
		return
	}
	pprof.Index(rw, req.Request)
}
コード例 #16
0
ファイル: http.go プロジェクト: jsocol/nsq
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)
	}
}
コード例 #17
0
ファイル: glweb.go プロジェクト: nzlov/glweb
func (self *GLWeb) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	log.Infoln("Request ", r.Method, r.URL.Path)
	w.Header().Add("Access-Control-Allow-Origin", "*")

	if r.Method == "GET" && r.URL.Path == "/" {
		if b := auth(w, r); b {
			htasks(self.gls, self.glps, w, r)
		}
		return
	}
	if debugmode && r.Method == "GET" {
		switch r.URL.Path {
		case "/debug/pprof/cmdline":
			if b := auth(w, r); b {
				pprof.Cmdline(w, r)
			}
			return
		case "/debug/pprof/profile":
			if b := auth(w, r); b {
				pprof.Profile(w, r)
			}
			return
		case "/debug/pprof/symbol":
			if b := auth(w, r); b {
				pprof.Symbol(w, r)
			}
			return
			//		case "/debug/vars":
			//			expvarHandler(w, r)
			//			return
		}
		if strings.HasPrefix(r.URL.Path, "/debug/pprof/") {
			if b := auth(w, r); b {
				pprof.Index(w, r)
			}
			return
		}
	}

	cors(w, r)

	for n, route := range self.glsroute {
		match, pmap := route.Match(r.Method, r.URL.Path)
		if match == NoMatch {
			continue
		}
		//		log.Infoln("Test", n, r.URL.Path, match, pmap, "OK")

		route.g.exec(n, w, r, pmap)
		return
	}
	http.NotFound(w, r)
}
コード例 #18
0
ファイル: main.go プロジェクト: prometheus/pushgateway
func handlePprof(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
	switch p.ByName("pprof") {
	case "/cmdline":
		pprof.Cmdline(w, r)
	case "/profile":
		pprof.Profile(w, r)
	case "/symbol":
		pprof.Symbol(w, r)
	default:
		pprof.Index(w, r)
	}
}
コード例 #19
0
ファイル: service.go プロジェクト: jmptrader/rqlite
// servePprof serves pprof information over HTTP.
func servePprof(w http.ResponseWriter, r *http.Request) {
	switch r.URL.Path {
	case "/debug/pprof/cmdline":
		pprof.Cmdline(w, r)
	case "/debug/pprof/profile":
		pprof.Profile(w, r)
	case "/debug/pprof/symbol":
		pprof.Symbol(w, r)
	default:
		pprof.Index(w, r)
	}
}
コード例 #20
0
ファイル: serverconfig.go プロジェクト: kdevroede/camlistore
func (profileHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
	switch req.URL.Path {
	case "/debug/pprof/cmdline":
		pprof.Cmdline(rw, req)
	case "/debug/pprof/profile":
		pprof.Profile(rw, req)
	case "/debug/pprof/symbol":
		pprof.Symbol(rw, req)
	default:
		pprof.Index(rw, req)
	}
}
コード例 #21
0
ファイル: handlers.go プロジェクト: mikedanese/heapster
func setupHandlers(sources []api.Source, sink sinks.ExternalSinkManager, m manager.Manager) http.Handler {
	// Make API handler.
	wsContainer := restful.NewContainer()
	a := v1.NewApi(m)
	a.Register(wsContainer)

	// Validation/Debug handler.
	handleValidate := func(req *restful.Request, resp *restful.Response) {
		err := validate.HandleRequest(resp, sources, sink)
		if err != nil {
			fmt.Fprintf(resp, "%s", err)
		}
	}
	ws := new(restful.WebService).
		Path("/validate").
		Produces("text/plain")
	ws.Route(ws.GET("").To(handleValidate)).
		Doc("get validation information")
	wsContainer.Add(ws)

	// TODO(jnagal): Add a main status page.
	// Redirect root to /validate
	redirectHandler := http.RedirectHandler(validate.ValidatePage, http.StatusTemporaryRedirect)
	handleRoot := func(req *restful.Request, resp *restful.Response) {
		redirectHandler.ServeHTTP(resp, req.Request)
	}
	ws = new(restful.WebService)
	ws.Route(ws.GET("/").To(handleRoot))
	wsContainer.Add(ws)

	handlePprofEndpoint := func(req *restful.Request, resp *restful.Response) {
		name := strings.TrimPrefix(req.Request.URL.Path, pprofBasePath)
		switch name {
		case "profile":
			pprof.Profile(resp, req.Request)
		case "symbol":
			pprof.Symbol(resp, req.Request)
		case "cmdline":
			pprof.Cmdline(resp, req.Request)
		default:
			pprof.Index(resp, req.Request)
		}
	}

	// Setup pporf handlers.
	ws = new(restful.WebService).Path(pprofBasePath)
	ws.Route(ws.GET("/{subpath:*}").To(func(req *restful.Request, resp *restful.Response) {
		handlePprofEndpoint(req, resp)
	})).Doc("pprof endpoint")
	wsContainer.Add(ws)

	return wsContainer
}
コード例 #22
0
ファイル: main.go プロジェクト: dgryski/trifles
func registerPProf(h func(string, func(http.ResponseWriter, *http.Request))) {
	h("/debug/pprof/", func(w http.ResponseWriter, r *http.Request) {
		w.Header().Set("Content-Type", "text/html; charset=utf-8")
		pprof.Index(w, r)
	})
	h("/debug/pprof/cmdline", pprof.Cmdline)
	h("/debug/pprof/profile", pprof.Profile)
	h("/debug/pprof/symbol", pprof.Symbol)
	h("/debug/pprof/block", pprof.Handler("block").ServeHTTP)
	h("/debug/pprof/heap", pprof.Handler("heap").ServeHTTP)
	h("/debug/pprof/goroutine", pprof.Handler("goroutine").ServeHTTP)
	h("/debug/pprof/threadcreate", pprof.Handler("threadcreate").ServeHTTP)
}
コード例 #23
0
ファイル: pprof.go プロジェクト: DavidZhangqin/goweb
func (*Pprof) Index(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
	switch p.ByName("name") {
	case "profile":
		pprof.Profile(w, r)
	case "symbol":
		pprof.Symbol(w, r)
	case "trace":
		pprof.Trace(w, r)
	case "cmdline":
		pprof.Cmdline(w, r)
	default:
		pprof.Index(w, r)
	}
}
コード例 #24
0
ファイル: pprofhandler.go プロジェクト: foolin/gowebapp
// Handler routes the pprof pages using httprouter
func Handler(w http.ResponseWriter, r *http.Request) {

	p := context.Get(r, "params").(httprouter.Params)

	switch p.ByName("pprof") {
	case "/cmdline":
		pprof.Cmdline(w, r)
	case "/profile":
		pprof.Profile(w, r)
	case "/symbol":
		pprof.Symbol(w, r)
	default:
		pprof.Index(w, r)
	}
}
コード例 #25
0
ファイル: handler.go プロジェクト: vijaykanthm28/gulp
// ServeHTTP responds to HTTP request to the handler.
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if strings.HasPrefix(r.URL.Path, "/debug/pprof") {
		switch r.URL.Path {
		case "/debug/pprof/cmdline":
			pprof.Cmdline(w, r)
		case "/debug/pprof/profile":
			pprof.Profile(w, r)
		case "/debug/pprof/symbol":
			pprof.Symbol(w, r)
		default:
			pprof.Index(w, r)
		}
	} else {

	}

	return
}
コード例 #26
0
ファイル: handler.go プロジェクト: rnubel/influxdb
// ServeHTTP responds to HTTP request to the handler.
func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	// FIXME(benbjohnson): Add pprof enabled flag.
	if strings.HasPrefix(r.URL.Path, "/debug/pprof") {
		switch r.URL.Path {
		case "/debug/pprof/cmdline":
			pprof.Cmdline(w, r)
		case "/debug/pprof/profile":
			pprof.Profile(w, r)
		case "/debug/pprof/symbol":
			pprof.Symbol(w, r)
		default:
			pprof.Index(w, r)
		}
		return
	}

	h.mux.ServeHTTP(w, r)
}
コード例 #27
0
ファイル: http.go プロジェクト: pombredanne/sortdb
func (s *httpServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	switch req.URL.Path {
	case "/ping":
		s.pingHandler(w, req)
	case "/get":
		s.getHandler(w, req)
	case "/mget":
		s.mgetHandler(w, req)
	case "/fwmatch":
		s.fwmatchHandler(w, req)
	case "/range":
		s.rangeHandler(w, req)
	case "/stats":
		s.statsHandler(w, req)
	case "/reload":
		s.reloadHandler(w, req)
	// case "/exit":
	// 	s.exitHandler(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)
		http.NotFound(w, req)
	}
}
コード例 #28
0
ファイル: http.go プロジェクト: hank-sunday/nsq
func (s *httpServer) debugRouter(w http.ResponseWriter, req *http.Request) error {
	switch req.URL.Path {
	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 fmt.Errorf("404 %s", req.URL.Path)
	}
	return nil
}
コード例 #29
0
ファイル: pprof.go プロジェクト: peidachang/gos
func pprofDefaultHander(rw http.ResponseWriter, req *http.Request) {
	pprof.Index(rw, req)
}
コード例 #30
0
ファイル: http.go プロジェクト: aonx/momonga
func (self *MyHttpServer) debugRouter(w http.ResponseWriter, req *http.Request) error {
	switch req.URL.Path {
	case "/debug/vars":
		w.Header().Set("Content-Type", "application/json; charset=utf-8")
		fmt.Fprintf(w, "{\n")
		first := true
		expvar.Do(func(kv expvar.KeyValue) {
			if kv.Key == "cmdline" || kv.Key == "memstats" {
				return
			}
			if !first {
				fmt.Fprintf(w, ",\n")
			}
			first = false
			fmt.Fprintf(w, "%q: %s", kv.Key, kv.Value)
		})
		fmt.Fprintf(w, "\n}\n")
	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)
	case "/debug/retain":
		itr := self.Engine.DataStore.Iterator()
		for ; itr.Valid(); itr.Next() {
			k := string(itr.Key())
			fmt.Fprintf(w, "<div>key: %s</div>", k)
		}
	case "/debug/retain/clear":
		itr := self.Engine.DataStore.Iterator()
		var targets []string
		for ; itr.Valid(); itr.Next() {
			x := itr.Key()
			targets = append(targets, string(x))
		}
		for _, s := range targets {
			self.Engine.DataStore.Del([]byte(s), []byte(s))
		}
		fmt.Fprintf(w, "<textarea>%#v</textarea>", self.Engine.DataStore)
	case "/debug/connections":
		for _, v := range self.Engine.Connections {
			fmt.Fprintf(w, "<div>%#v</div>", v)
		}
	case "/debug/connections/clear":
		self.Engine.Connections = make(map[uint32]map[string]*MmuxConnection)
		fmt.Fprintf(w, "cleared")
	case "/debug/qlobber/clear":
		self.Engine.TopicMatcher = util.NewQlobber()
		fmt.Fprintf(w, "cleared")
	case "/debug/qlobber/dump":
		fmt.Fprintf(w, "qlobber:\n")
		self.Engine.TopicMatcher.Dump(w)
	case "/debug/config/dump":
		e := toml.NewEncoder(w)
		e.Encode(self.Engine.Config())

	default:
		return fmt.Errorf("404 %s", req.URL.Path)
	}
	return nil
}