Last active
January 22, 2018 23:58
-
-
Save squizzi/c18ac2ab6a3227bca02885ed9bd669fb to your computer and use it in GitHub Desktop.
Inspect failed and running tasks of all services
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
## Diagnostic data capture for Docker services and their associated tasks | |
## Run where client bundle is loaded or on a swarm manager | |
## Use something like: | |
## docker service ps $each | grep -v 'ID' | awk '{print $1 " " $6}' | egrep -i 'failed|running' | awk '{print $1}'; | |
## to grep out specific states within TASK_ID | |
## --- | |
# Create a directory to store this data in | |
DIRECTORY="$(pwd)/docker-service-info/" | |
mkdir -p $DIRECTORY | |
# Capture node, service and stack level information | |
echo "Capturing node, service and stack level information..." | |
docker node ls > $DIRECTORY/docker-node-ls.out | |
docker stack ls > $DIRECTORY/docker-stack-ls.out | |
docker service ls > $DIRECTORY/docker-service-ls.out | |
# Iterate through each of the running services and collect info | |
echo "Starting service info capture..." | |
SERVICES=$(docker service ls -q) | |
for each in $SERVICES | |
do | |
SERVICENAME=$(docker inspect $each --format {{.Spec.Name}}) | |
mkdir -p $DIRECTORY/$SERVICENAME | |
docker service ps $each > $DIRECTORY/$SERVICENAME/docker-ps.out | |
docker service inspect $each > $DIRECTORY/$SERVICENAME/docker-service-inspect.out | |
# Back to awk: Provide backwards compat for engines which lack --format | |
for TASK_ID in $( | |
docker service ps $each | grep -v 'ID' | awk '{print $1}'; | |
) | |
do | |
docker inspect --type=task $TASK_ID > $DIRECTORY/$SERVICENAME/$TASK_ID-task-inspect.out | |
done | |
echo $SERVICENAME" captured" | |
done | |
# Create a tarball of the directory contents, if tar exists | |
if [ -e /bin/tar ]; then | |
echo "Creating docker-service-info.tar.gz of captured information..." | |
tar czf docker-service-info.tar.gz $DIRECTORY | |
echo "Done." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment