猿问

profile kubectl using pprof

在 kubernetes 源代码中,有一个代码块处理性能分析部分,但我不能访问端点:


in kubernetes/pkgs/kubelet/server/stats/server.go


func (s *Server) InstallProfilingHandler(enableProfilingLogHandler bool, enableContentionProfiling bool) {

    s.addMetricsBucketMatcher("debug")

    if !enableProfilingLogHandler {

        s.restfulCont.Handle(pprofBasePath, getHandlerForDisabledEndpoint("profiling endpoint is disabled."))

        return

    }


    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)

        case "trace":

            pprof.Trace(resp, req.Request)

        default:

            pprof.Index(resp, req.Request)

        }

    }


    // Setup pprof handlers.

    ws := new(restful.WebService).Path(pprofBasePath)

    ws.Route(ws.GET("/{subpath:*}").To(handlePprofEndpoint)).Doc("pprof endpoint")

    s.restfulCont.Add(ws)


    if enableContentionProfiling {

        goruntime.SetBlockProfileRate(1)

    }

}

我不知道pprof工具使用的端口,但我发现它使用:


controller-0:/home/sysadmin/go/bin# netstat -atlpn | grep kubelet

tcp        0      0 127.0.0.1:10248         0.0.0.0:*               LISTEN      184856/kubelet      

tcp        0      0 192.168.206.2:49720     192.168.206.1:6443      ESTABLISHED 184856/kubelet      

tcp6       0      0 :::10250                :::*                    LISTEN      184856/kubelet 

然后我试过了


controller-0:/home/sysadmin/go/bin# ./go tool pprof  http://localhost:6443/debug/pprof/mutex

Fetching profile over HTTP from http://localhost:6443/debug/pprof/mutex

http://localhost:6443/debug/pprof/mutex: server response: 400 Bad Request

failed to fetch any source profiles


有没有人知道我应该尝试什么来访问 pprof 端点?或者如何尝试不同的方法来分析kubelet过程?


皈依舞
浏览 133回答 1
1回答

海绵宝宝撒

尝试:$ kubectl proxy &Starting to serve on 127.0.0.1:8001$ go tool pprof "http://localhost:8001/api/v1/nodes/${NODE}/proxy/debug/pprof/profile"当你启动时,所有请求都去 kubelet 运行在 .您可以添加所需的任何路径和它。让它成为或或你想要的任何东西。kubectl proxyhttp://localhost:8001/api/v1/nodes/${NODE}/proxy/${NODE}/debug/pprof/profiledebug/pprof/heap
随时随地看视频慕课网APP

相关分类

Go
我要回答