Last active
May 27, 2019 07:18
-
-
Save felixbarny/1b5c69edcea5e5d53169346da4e7dcfc to your computer and use it in GitHub Desktop.
Attach Elastic APM Java agent to docker containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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