1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| 2.1 克隆仓库 gitpod ~ $ git clone https://github.com/prometheus/prometheus.git Cloning into 'prometheus'... remote: Enumerating objects: 135723, done. remote: Counting objects: 100% (229/229), done. remote: Compressing objects: 100% (166/166), done. remote: Total 135723 (delta 148), reused 63 (delta 63), pack-reused 135494 (from 4) Receiving objects: 100% (135723/135723), 253.46 MiB | 40.53 MiB/s, done. Resolving deltas: 100% (83480/83480), done.
2.2 进入目录 gitpod ~ $ cd prometheus/
2.3 查询与pprof相关的文件 gitpod ~/prometheus (main) $ grep -r "pprof" ./* ... ./web/web.go: "net/http/pprof" ./web/web.go: if subpath == "/pprof" { ./web/web.go: if !strings.HasPrefix(subpath, "/pprof/") { ./web/web.go: subpath = strings.TrimPrefix(subpath, "/pprof/") ...
2.4 修改./web/web.go`(只修改web.go文件)` 16 import ( 17 "bytes" 23 "math" 24 "net" 25 "net/http" 26 "net/http/pprof" //删除/注释 27 "net/url" ----------------------------------------------------------------------------以下内容全部注释/删除 566 func serveDebug(w http.ResponseWriter, req *http.Request) { 567 ctx := req.Context() 568 subpath := route.Param(ctx, "subpath") 569 570 if subpath == "/pprof" { 571 http.Redirect(w, req, req.URL.Path+"/", http.StatusMovedPermanently) 572 return 573 } 574 575 if !strings.HasPrefix(subpath, "/pprof/") { 576 http.NotFound(w, req) 577 return 578 } 579 subpath = strings.TrimPrefix(subpath, "/pprof/") 580 581 switch subpath { 582 case "cmdline": 583 pprof.Cmdline(w, req) 584 case "profile": 585 pprof.Profile(w, req) 586 case "symbol": 587 pprof.Symbol(w, req) 588 case "trace": 589 pprof.Trace(w, req) 590 default: 591 req.URL.Path = "/debug/pprof/" + subpath 592 pprof.Index(w, req) 593 } 594 }
2.5 构建二进制文件 gitpod ~/prometheus (main) $ make build cd web/ui && npm install npm warn deprecated inflight@1.0.6: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. ...
2.6 修改当前Dockerfile内容 原: COPY .build/${OS}-${ARCH}/prometheus /bin/prometheus COPY .build/${OS}-${ARCH}/promtool /bin/promtool 修改为: COPY ./prometheus /bin/prometheus COPY ./promtool /bin/promtool
2.7 构建镜像 gitpod ~/prometheus $ docker build -t registry.cn-hangzhou.aliyuncs.com/xx/xx:prometheus-pprof .
2.8 推送到个人仓库本地部署 gitpod ~/prometheus $ docker push registry.cn-hangzhou.aliyuncs.com/xx/xx:prometheus-pprof
|