首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用pprof的剖面kubectl

使用pprof的剖面kubectl
EN

Stack Overflow用户
提问于 2021-06-11 11:25:21
回答 1查看 941关注 0票数 0

在kubernetes源代码中,有一个处理分析部分的代码块,但我无法访问端点:

代码语言:javascript
复制
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工具使用的端口,但我发现它使用的是:

代码语言:javascript
复制
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 

那我试过了

代码语言:javascript
复制
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过程?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-06-11 13:29:49

尝试:

代码语言:javascript
复制
$ 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"

启动kubectl proxy时,对http://localhost:8001/api/v1/nodes/${NODE}/proxy/的所有请求都会转到运行在${NODE}上的kubelet。您可以添加任何您想要的路径和它。让它成为/debug/pprof/profiledebug/pprof/heap或者你想要的任何东西。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67936168

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档