我有一个现有的http服务器,我想分析.我已经包含_ "net/http/pprof"
了我的导入,并且我已经运行了http服务器:
router := createRouter()
server := &http.Server {
Addr: ":8080",
Handler: router,
ReadTimeout: 15*time.Second,
WriteTimeout: 15*time.Second,
// MaxHeaderBytes: 4096,
}
log.Fatal(server.ListenAndServe())
Run Code Online (Sandbox Code Playgroud)
当我试图访问http:// localhost:8080/debug/pprof /我得到404 page not found
.
这是我go tool pprof
在本地机器上使用时得到的:
userver@userver:~/Desktop/gotest$ go tool pprof http://192.168.0.27:8080/
Use of uninitialized value $prefix in concatenation (.) or string at /usr/lib/go/pkg/tool/linux_amd64/pprof line 3019.
Read http://192.168.0.27:8080/pprof/symbol
Failed to get the number of symbols from http://192.168.0.27:8080/pprof/symbol
userver@userver:~/Desktop/gotest$ go tool pprof http://localhost:8080/debug/pprof/profile
Read http://localhost:8080/debug/pprof/symbol
Failed to get the number of symbols from http://localhost:8080/debug/pprof/symbol
Run Code Online (Sandbox Code Playgroud)
对于远程客户端也是如此:
MacBookAir:~ apple$ go tool pprof http://192.168.0.27:8080/
Use of uninitialized value $prefix in concatenation (.) or string at /usr/local/Cellar/go/1.3.2/libexec/pkg/tool/darwin_amd64/pprof line 3027.
Read http://192.168.0.27:8080/pprof/symbol
Failed to get the number of symbols from http://192.168.0.27:8080/pprof/symbol
Run Code Online (Sandbox Code Playgroud)
Dav*_*e C 19
它没有在文档中明确提到,但net/http/pprof
只注册其处理程序http.DefaultServeMux
.
从来源:
func init() {
http.Handle("/debug/pprof/", http.HandlerFunc(Index))
http.Handle("/debug/pprof/cmdline", http.HandlerFunc(Cmdline))
http.Handle("/debug/pprof/profile", http.HandlerFunc(Profile))
http.Handle("/debug/pprof/symbol", http.HandlerFunc(Symbol))
http.Handle("/debug/pprof/trace", http.HandlerFunc(Trace))
}
Run Code Online (Sandbox Code Playgroud)
如果您没有使用默认的多路复用器,您只需要使用您正在使用的任何多路复用器注册任何/所有那些,例如mymux.HandleFunc("…", pprof.Index)
,等等.
或者,您可以使用默认的多路复用器监听单独的端口(如果需要,也可能仅绑定到localhost),如您所示.
Max*_*ysh 12
看起来,问题是在*mux.Router
使用从github.com/gorilla/mux
我作为一个Handler
在我的http.Server
实例.
解决方案:只需为以下内容启动另一台服务器pprof
:
server := &http.Server {
Addr: ":8080",
Handler: router,
ReadTimeout: 15*time.Second,
WriteTimeout: 15*time.Second,
}
go func() {
log.Println(http.ListenAndServe(":6060", nil))
}()
log.Fatal(server.ListenAndServe())
Run Code Online (Sandbox Code Playgroud)
如果您使用的是github.com/gorilla/mux.Router
你可以简单的手头宽裕前缀的任何请求/debug/
的http.DefaultServeMux
。
import _ "net/http/debug"
router := mux.NewRouter()
router.PathPrefix("/debug/").Handler(http.DefaultServeMux)
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
5208 次 |
最近记录: |