-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlogs.sh
128 lines (102 loc) · 3.16 KB
/
logs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
usage () {
echo "USAGE:"
echo " command [REQUIRED] --app=(seahorse|platform|beacon) [OPTIONAL] --flag"
echo " FLAGS:"
echo " -a=*|--app=* to set the app name"
echo " -i|--init-containers to include logs from pod init containers"
echo " -d|--debug for verbose output"
exit 0
}
set_flags () {
for arg in $@; do
case $arg in
-h|--help)
usage
shift
;;
-a=*|--app=*)
APP="${arg#*=}"
shift
;;
-i|--init-containers)
INIT_CONTAINERS="true"
shift
;;
-d|--debug)
DEBUG="true"
set -x
shift
;;
esac
done
}
sys_req () {
processors=`grep -c "^processor\s" /proc/cpuinfo`
if [ $processors -lt 4 ]; then
echo "Available CPUs/cores ($processors) is less than the minimum system requirement of 4. Correct this before continuing."
exit 1
fi
mem=`grep -i memtotal /proc/meminfo|awk '{print $2}'`
if [ $mem -lt 16284672 ]; then
echo "Available memory appears to be less than the minimum system requirement of 16GB. Correct this before continuing."
exit 1
fi
diskPercentUsed=`df -h / | egrep -o '[0-9]+%'|egrep -o '[0-9]+'`
if [ $diskPercentUsed -gt 80 ]; then
echo "Disk space used on root volume is over 80%. Fix this or Kubernetes will not work."
exit 1
fi
}
get_pod_logs () {
kubectl get pods -A 2>&1 > $tmpdir/pods.status.txt
namespaces=`kubectl get namespaces|awk '{print $1}'|grep -v NAME`
for namespace in $namespaces; do
pods=`kubectl get pods -n $namespace --no-headers=true | awk '{print $1}'`
for pod in $pods; do
if [ ! -z "$DEBUG" ];then
echo "Getting logs for pod $pod"
fi
kubectl -n $namespace describe pod $pod > $tmpdir/$pod.describe;
kubectl -n $namespace logs $pod > $tmpdir/$pod.log;
if [ $INIT_CONTAINERS=="true" ]; then
initContainers=`kubectl -n $namespace get pod $pod -o=jsonpath='{.spec.initContainers[*].name}'`
for initContainer in $initContainers; do
kubectl -n $namespace logs $pod -c $initContainer > $tmpdir/$pod.$initContainer.log;
done
fi
# not every pod will have a previous but it's worth trying
kubectl -n $namespace logs -p $pod > $tmpdir/$pod.previous.log 2>/dev/null ;
done
done
}
bundle_logs () {
logbundle=~/$APP-logs.tar.gz
cd $tmpdir && tar czf $logbundle .
cd && rm -r $tmpdir
}
set_flags $@
if [ -z "$APP" ]; then
APP=$( kubectl config view --minify -o jsonpath='{..namespace}' )
fi
# Verify kubectl is working
kubectl get pods >/dev/null
if [ $? -ne 0 ]; then
echo "ERROR kubectl is not working; this needs to be corrected before this script will work."
exit
fi
echo "Confirming system requirements"
sys_req
tmpdir=/tmp/cfl-logs && rm -rf $tmpdir && mkdir -p $tmpdir
echo "Collecting logs"
get_pod_logs
echo "Adding CPU usage data"
/bin/top -b -n1 > $tmpdir/process-snapshot-from-top.txt
echo "Adding disk usage"
df -h > $tmpdir/disk-usage.txt
echo "Adding node status"
kubectl describe nodes > $tmpdir/nodes.txt
echo "Bundling logs"
bundle_logs
echo "Saved logs to $logbundle"
echo "Please share this file with CoreFiling support to continue diagnosis"