Skip to content

Instantly share code, notes, and snippets.

@Oats87
Created July 7, 2022 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Oats87/94f431165de4603db0c927dbf767fa84 to your computer and use it in GitHub Desktop.
Save Oats87/94f431165de4603db0c927dbf767fa84 to your computer and use it in GitHub Desktop.
Collect pprof for Rancher in K8s
#!/bin/sh
for pod in $(kubectl get pods --no-headers -l app=rancher -n cattle-system | cut -d ' ' -f1); do
echo Collecting pprof information for $pod - this will take some time.
kubectl -n cattle-system exec $pod -c rancher -- curl -s http://localhost:6060/debug/pprof/profile -o profile;
kubectl -n cattle-system cp $pod:profile pprof-$pod-profile -c rancher;
kubectl -n cattle-system exec $pod -c rancher -- curl -s http://localhost:6060/debug/pprof/goroutine -o goroutine;
kubectl -n cattle-system cp $pod:goroutine pprof-$pod-goroutine -c rancher;
kubectl -n cattle-system exec $pod -c rancher -- curl -s http://localhost:6060/debug/pprof/heap -o heap;
kubectl -n cattle-system cp $pod:heap pprof-$pod-heap -c rancher;
kubectl -n cattle-system exec $pod -c rancher -- curl -s http://localhost:6060/debug/pprof/threadcreate -o threadcreate;
kubectl -n cattle-system cp $pod:threadcreate pprof-$pod-threadcreate -c rancher;
kubectl -n cattle-system exec $pod -c rancher -- curl -s http://localhost:6060/debug/pprof/block -o block;
kubectl -n cattle-system cp $pod:block pprof-$pod-block -c rancher;
kubectl -n cattle-system exec $pod -c rancher -- curl -s http://localhost:6060/debug/pprof/mutex -o mutex;
kubectl -n cattle-system cp $pod:mutex pprof-$pod-mutex -c rancher;
echo Collection of pprof information for $pod complete
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment