一尘不染

无法在现有服务器上使用Go工具pprof

go

我有一个要配置的现有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())

当我尝试访问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

与远程客户端相同:

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

阅读 311

收藏
2020-07-02

共1个答案

一尘不染

文档中未明确提及它,而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))
}

如果您未使用默认的多路复用器,则只需向您要使用的任何多路复用器注册所需的任何/全部,例如,诸如此类mymux.HandleFunc("…", pprof.Index)

或者,您可以使用默认的mux在单独的端口(如果需要的话,也可以绑定到localhost)上监听。

2020-07-02