-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcollect.sh
95 lines (78 loc) · 2.45 KB
/
collect.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
#!/bin/bash
#This script was developed with minimal testing and error handling, in order
# to investigate JVM related performance issues The script must run as the user that owns the Java
# process in question. The script assumes that you can run the jstack command directly, if not,
# then you'll need to add the full path of the Java home's bin directory before jstack, for example:
# /usr/java/jdk1.8_182/bin/jstack
INTERVAL=2
ROOT_DIR=$(hostname)
mkdir -p ./$ROOT_DIR
CHILD_PID=()
trap cleanup SIGINT INT
cleanup() {
echo "Killing child processes"
for i in "${CHILD_PID[@]}"
do
kill -9 $i
done;
echo "Exiting script: ctrl+c issued."
echo "Copying /var/log/messages"
cp /var/log/messages ./$ROOT_DIR/
echo "Copying /var/log/dmesg"
dmesg -T >> ./$ROOT_DIR/dmesg
echo "Zipping up directory: $ROOT_DIR"
tar cvzf ./$ROOT_DIR.tar.gz ./$ROOT_DIR/*
echo "Cleanup: Deleting directory $ROOT_DIR"
rm -Rf ./$ROOT_DIR
echo "Please locate the file $ROOT_DIR.tar.gz and upload it to the case"
exit 1
}
collectData() {
PID=$1
mkdir -p ./$ROOT_DIR/$PID
cd ./$ROOT_DIR/$PID
echo "Collecting data from Java process with PID $PID run by user $USER"
echo "Host: $(uname -a)" >> ./top.out
echo "Java Process: $PID" >> ./top.out
echo "User ID: $USER" >> ./top.out
echo "Host: $(uname -a)" >> ./topH.out
echo "Java Process: $PID" >> ./topH.out
echo "User ID: $USER" >> ./topH.out
echo "Host: $(uname -a)" >> ./ps.out
echo "Java Process: $PID" >> ./ps.out
echo "User ID: $USER" >> ./ps.out
ps -ef >> ./ps.out
echo "Host: $(uname -a)" >> ./vmstat.out
echo "Java Process: $PID" >> ./vmstat.out
echo "User ID: $USER" >> ./vmstat.out
while :
do
top -b -n 1 >> ./top.out
top -p $PID -b -H -n1 >> ./topH.out
vmstat -wt >> ./vmstat.out
jstack $PID >> ./jstack.out
#If jstack command has an exit status other than 0, then break out of the loop because
#an error occurred. Most likely because the Java process stopped and doesn't exist anymore.
if [ $? -ne 0 ]; then
echo "Java Process ${PID} disappeared. Stopping collection for this process."
break;
fi
sleep $INTERVAL
done
};
jps | while read a
do
PID=$(echo $a | awk '{print $1}')
CLASS_NAME=$(echo $a | awk '{print $2}')
if [ ${CLASS_NAME} == $1 ]
then
collectData ${PID} &
CHILD_PID+=( $! )
fi
done
#Need to make sure the script process remains alive to listen for the interrupt signal to cleanup
while :
do
echo "Press Ctrl+C to stop the script."
a=1
done