Add the following line to your Go code:
// create and start the profiler handler
profiler.New().Start()
// ... or with custom values
profiler.New(
profiler.WithSignal(syscall.SIGUSR1),
profiler.WithAddress(":8080"),
profiler.WithTimeout(15 * time.Minute),
)| Parameter | Default |
|---|---|
| Signal | SIGUSR1 |
| Listen | :6666 |
| Timeout | 30m |
pkill -SIGUSR1 <your Go program>After timeout the endpoint will shutdown.
go tool pprof -http $(hostname):8080 http://localhost:6666/debug/pprof/profile... or ...
go tool pprof -http localhost:7007 http://localhost:8080/debug/pprof/profilekubectl get pods
NAME READY STATUS RESTARTS AGE
...
kubectl exec -ti <your pod> -- sh
/ # pkill -SIGUSR1 <your Go program>
/ #After timeout the endpoint will shutdown.
kubectl logs <your pod> -f | grep 'start debug endpoint'kubectl port-forward <your pod> 8080:6666
Forwarding from 127.0.0.1:8080 -> 6666
Forwarding from [::1]:8080 -> 6666
Handling connection for 8080go tool pprof -http $(hostname):8888 http://localhost:8080/debug/pprof/profile... or ...
go tool pprof -http localhost:7007 http://localhost:8080/debug/pprof/profileUse statsviz
Open: http://localhost:8080/debug/statsviz
Use expvarmon
expvarmon -ports=http://localhost:8080