Can';不要对现有服务器使用go工具pprof
我有一个现有的http服务器,我想配置它。我已将Can';不要对现有服务器使用go工具pprof,go,gorilla,pprof,Go,Gorilla,Pprof,我有一个现有的http服务器,我想配置它。我已将\unet/http/pprof“包含到我的导入中,并且我已经让http服务器运行: router := createRouter() server := &http.Server { Addr: ":8080", Handler: router, ReadTimeout: 15*time.Second, WriteTimeout: 15*time.Second,
\unet/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())
当我试图访问时,我发现404页面未找到
这就是我在本地机器上使用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
看起来问题出在
github.com/gorilla/mux
中使用的*mux.Router
中,我在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())
文档中没有明确提到它,只是在http.DefaultServeMux
中注册了它的处理程序
import _ "net/http/debug"
router := mux.NewRouter()
router.PathPrefix("/debug/").Handler(http.DefaultServeMux)
从:
如果您不使用默认的mux,您只需将任何/所有您想要的注册到您正在使用的任何mux,例如类似于mymux.HandleFunc(“…”,pprof.Index)
,等等
或者,您可以在一个单独的端口上侦听(如果需要,也可能只绑定到本地主机)。如果您使用的是
github.com/gorilla/mux.Router
,您只需将任何前缀为/debug/
的请求转交给http.DefaultServeMux
import _ "net/http/debug"
router := mux.NewRouter()
router.PathPrefix("/debug/").Handler(http.DefaultServeMux)
我有一个问题:一旦进入
/debug/pprof/
,就会有几个链接指向404页。特别是heap
和allocs
404。正如您上面所示,我没有看到net/http/pprof/pprof.go
的init()
func中提供的那些路径的路由。我该如何让他们可以访问?您知道我如何获得这些@Dave C吗?如果您使用router.PathPrefix(“/debug/”).Handler(http.DefaultServeMux)
将添加堆端点。如果应用init
处理程序,则不会出现这种情况。不知道为什么。。。