Sergio Slobodrian | ee417fa | 2017-08-11 09:34:50 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | # This script will collect all of the pertinent logs from a voltha |
| 4 | # HA swarm cluster, tar, and bizip them to facilitate sending them |
| 5 | # to the suspected issue owner. |
| 6 | |
| 7 | volthaDir="/cord/incubator/voltha" |
| 8 | |
| 9 | # Get the list of the other hosts that make up the cluster |
| 10 | hosts=`docker node ls | tail -n +2 | awk '{print $2}' | grep -v "*"` |
| 11 | |
| 12 | # Create a temporary directory for temporary storage of all the logs |
| 13 | mkdir ${volthaDir}/log_tmp |
| 14 | pushd ${volthaDir}/log_tmp |
| 15 | |
| 16 | # Docker health in general. |
| 17 | |
| 18 | echo "Getting docker node ls" |
| 19 | docker node ls > docker_node_ls.log 2>&1 |
| 20 | echo "Getting docker service ls" |
| 21 | docker service ls > docker_service_ls.log 2>&1 |
| 22 | |
| 23 | # Get the list of services to ps each one and get logs for each one. |
| 24 | svcs=`docker service ls | tail -n +2 | awk '{print $2}'` |
| 25 | |
| 26 | # Get the PS information |
| 27 | for i in $svcs |
| 28 | do |
| 29 | echo "Getting docker service ps $i" |
| 30 | docker service ps ${i} > docker_service_ps_${i} 2>&1 |
| 31 | done |
| 32 | |
| 33 | # Get the logs for each service |
| 34 | for i in $svcs |
| 35 | do |
| 36 | echo "Getting docker service logs $i" |
| 37 | docker service logs ${i} > docker_service_logs_${i} 2>&1 & |
| 38 | done |
| 39 | |
| 40 | patience=10 |
| 41 | while [ ! -z "`jobs -p`" ] |
| 42 | do |
| 43 | echo "*** Waiting on log collection to complete. Outstanding jobs: `jobs -p | wc -l`" |
| 44 | sleep 10 |
| 45 | patience=`expr $patience - 1` |
| 46 | if [ $patience -eq 0 ]; then |
| 47 | echo "Log collection stuck, killing any active collectors" |
| 48 | for i in `jobs -p` |
| 49 | do |
| 50 | kill -s TERM $i |
| 51 | done |
| 52 | break |
| 53 | fi |
| 54 | done |
| 55 | |
| 56 | # Get the image list from this host |
| 57 | echo "Getting docker image ls from `hostname`" |
| 58 | docker image ls > docker_image_ls_`hostname` 2>&1 |
| 59 | for i in $hosts |
| 60 | do |
| 61 | echo "Getting docker image ls from $i" |
| 62 | ssh voltha@$i "docker image ls" > docker_image_ls_$i 2>&1 |
| 63 | done |
| 64 | |
| 65 | |
| 66 | popd |
| 67 | tar cjvf logs.tar.bz2 log_tmp/* |
| 68 | rm -fr log_tmp |
| 69 | |
| 70 | |
| 71 | |