Skip to content

Instantly share code, notes, and snippets.

@zhangguanzhang
Last active January 12, 2024 06:34
Show Gist options
  • Save zhangguanzhang/22fade9396d65372869ee8b39ae6a07d to your computer and use it in GitHub Desktop.
Save zhangguanzhang/22fade9396d65372869ee8b39ae6a07d to your computer and use it in GitHub Desktop.
docker_pprof.md

离线环境来从现场获取docker的pprof信息步骤

获取go的镜像

while read img;
  do docker run --rm --entrypoint go $img version 2>/dev/null | grep -qw version && { echo $img;break; }; 
done < <(docker images --format '{{.Repository}}:{{.Tag}}')

转发docker的sock成tcp

socat  -d -d TCP-LISTEN:8081,fork,bind=0.0.0.0 UNIX:/var/run/docker.sock
socat  -d -d TCP-LISTEN:18081,fork,bind=0.0.0.0 TCP4:1.1.1.1:30000

镜像起容器获取pprof文件

go tool pprof http://1x.xxx.45.162:8080/debug/pprof/goroutine

# 或者
curl -s  http://1x.xxx.45.162:8080/debug/pprof/goroutine > test.goroutine
curl -s  http://1x.xxx.45.162:8080/debug/pprof/heap

# 然后把`test.goroutine`拿回来转换成pdf
yum install -y graphviz
go tool pprof --pdf test.goroutine > goroutine.pdf

go tool pprof -http=0.0.0.0:8080 test.goroutine

other:

curl http://192.168.111.2:8001/debug/pprof/

output:

CountProfile
4524allocs
0block
0cmdline
1947goroutine
4524heap
0mutex
0profile
10threadcreate
0trace
@zhangguanzhang
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment