Skip to content

Instantly share code, notes, and snippets.

@felixbarny
Last active May 27, 2019 07:18
Show Gist options
  • Save felixbarny/1b5c69edcea5e5d53169346da4e7dcfc to your computer and use it in GitHub Desktop.
Save felixbarny/1b5c69edcea5e5d53169346da4e7dcfc to your computer and use it in GitHub Desktop.
Attach Elastic APM Java agent to docker containers
#!/usr/bin/env bash
set -ex
attach () {
if [[ $(docker inspect ${container_id} | jq --raw-output .[0].Config.Cmd[0]) == java ]]
then
echo attaching to $(docker ps --no-trunc | grep ${container_id})
docker cp /Users/felixbarnsteiner/Applications/apm/apm-agent-attach-1.6.1.jar ${container_id}:/apm-agent-attach.jar
docker exec ${container_id} java -jar /apm-agent-attach.jar --config
fi
}
for container_id in $(docker ps --quiet --no-trunc) ; do
attach
done
docker events --filter 'event=start' --format '{{.ID}}' |
while IFS= read -r container_id
do
attach
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment