Skip to content

Instantly share code, notes, and snippets.

@cirocosta
Created May 29, 2019 19:59
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save cirocosta/8658c5ada0cb4735046458e13b1d82b4 to your computer and use it in GitHub Desktop.
Save cirocosta/8658c5ada0cb4735046458e13b1d82b4 to your computer and use it in GitHub Desktop.
Get golang dumps from BOSH deployed concourse
#!/bin/bash
set -o errexit
set -o nounset
set -o xtrace
readonly DUMP_PREFIX="/tmp/dump.$(date +%Y-%m-%d)"
readonly INSTANCE_GROUP=${INSTANCE_GROUP:-web}
main () {
goroutine_dumps::retrieve
golang_cpu_profile::retrieve
golang_mem_profile::retrieve
copy
clean
}
goroutine_dumps::retrieve () {
echo "INFO: retrieving goroutines info"
local command='curl -s 0.0.0.0:8079/debug/pprof/goroutine?debug=2 > '$DUMP_PREFIX'.goroutines.$(hostname).dump'
bosh -n -e $BOSH_ENVIRONMENT -d $BOSH_DEPLOYMENT \
ssh -c "$command" $INSTANCE_GROUP
}
golang_mem_profile::retrieve () {
echo "INFO: retrieving golang memory profile"
local command='curl -s 0.0.0.0:8079/debug/pprof/heap > '$DUMP_PREFIX'.heap.$(hostname).dump'
bosh -n -e $BOSH_ENVIRONMENT -d $BOSH_DEPLOYMENT \
ssh -c "$command" $INSTANCE_GROUP
}
golang_cpu_profile::retrieve () {
echo "INFO: retrieving golang cpu profile"
local command='curl -s 0.0.0.0:8079/debug/pprof/profile?seconds=30 > '$DUMP_PREFIX'.profile.$(hostname).dump'
bosh -n -e $BOSH_ENVIRONMENT -d $BOSH_DEPLOYMENT \
ssh -c "$command" $INSTANCE_GROUP
}
copy () {
echo "INFO: copying"
bosh -n -e $BOSH_ENVIRONMENT -d $BOSH_DEPLOYMENT \
scp $INSTANCE_GROUP:$DUMP_PREFIX*.dump ./
}
clean () {
echo "INFO: cleaning"
bosh -n -e $BOSH_ENVIRONMENT -d $BOSH_DEPLOYMENT \
ssh -c "rm $DUMP_PREFIX.*.dump" $INSTANCE_GROUP
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment