forked from RomainAnselin/supportWrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrap.sh
executable file
·286 lines (258 loc) · 9.06 KB
/
wrap.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
#!/bin/bash
debug=0
usage() {
if [ $# -ne 1 ]; then
echo "Usage: $0 [-s] [-p] [-h] <Path to Opscenter diag>"
echo " -s solr data"
echo " -p GC per node"
# TODO: Reset -r option to erase existing parsed data if you want to re-run with different options
echo " -h show this help"
exit 1
fi
}
while getopts "sph" option; do
case "${option}" in
s) echo "Solr parsing requested"
solrparse=1 ;;
p) echo "Node per node parsing"
pernode=1 ;;
h) echo "Showing help"
usage ;;
esac
done
template=$(dirname "${BASH_SOURCE[0]}")
if [[ "${BASH_ARGV[0]}" == "." ]]; then opscdiag="$(pwd)"
# else opscdiag="$1"
# depending on what kind of path you provide, I need in any scenario to find the full path
else opscdiag="$(cd "$(dirname "${BASH_ARGV[0]}")"; pwd -P)/$(basename "${BASH_ARGV[0]}")"
fi
if [[ "$template" == "." ]]; then template="$(pwd)"
fi
if [[ -f "$template/wrap.conf" ]]; then
source $template/wrap.conf
else
echo "Missing wrap.conf file under $template"
usage
exit 1
fi
prep() {
mkdir "$opscdiag"/wrapper
cp "$template"/index.html "$opscdiag"/wrapper/index.html
cp "$template"/datastax.png "$opscdiag"/wrapper/datastax.png
}
linkname() {
if [[ "$i" == "Cluster_Configuration_Summary.out" ]]; then link=Summary
elif [[ "$i" == "Node_Configuration_Files_Info.out" ]]; then link=Conf
elif [[ "$i" == "Node_Info.out" ]]; then link=Info
elif [[ "$i" == "Node_Resource_Usage_Info.out" ]]; then link=Resource
elif [[ "$i" == "Node_Status.out" ]]; then link=Status
elif [[ "$i" == "System_Log_Event_Info.out" ]]; then link=SystemLog
elif [[ "$i" == "Table_Statistics.out" ]]; then link=TableStats
elif [[ "$i" == "Thread_Pool_Statistics.out" ]]; then link=ThreadPool
elif [[ "$i" == "sperfgc.txt" ]]; then link=GC
elif [[ "$i" == "sperfgeneral.txt" ]]; then link=General
elif [[ "$i" == "sperfstatuslog.txt" ]]; then link=StatusLogger
elif [[ "$i" == "sperfslow.txt" ]]; then link=SlowQueries
elif [[ "$i" == "sperfschema.txt" ]]; then link=Schema
elif [[ "$i" == "sperfnodegc.txt" ]]; then link=NodeGC
elif [[ "$i" == "sperfnodestatuslog.txt" ]]; then link=NodeStatusLogger
elif [[ "$i" == "sperfsolrcache.txt" ]]; then link=SolrCache
elif [[ "$i" == "sperfsolrscore.txt" ]]; then link=SolrScore
else link=$i
fi
# echo $link
}
# Run tools
nibblerrun() {
echo "Nibbler running"
"$javapath" -jar "$nibblerpath" "$opscdiag"
}
sperfcheck() {
# sperf come in different format and is declared differently on various OS. Need to identify to run accordingly
if [[ "$OSTYPE" == "darwin"* ]]; then
if [[ $(file "$sperfpath" | sed -E 's/.*: ([A-Za-z0-9\-]+) .*/\1/g') == 'Mach-O' ]]; then pyornotpy=0
fi
elif [[ $(file "$sperfpath" | sed -E 's/.*: ([A-Za-z]+) .*/\1/g') == 'ELF' ]]; then pyornotpy=0
elif [[ $(file "$sperfpath" | sed -E 's/.*: ([A-Za-z]+) .*/\1/g') == 'Python' ]]; then pyornotpy=1
fi
if [[ "$debug" == "1" ]]; then
filetype=$(file "$sperfpath")
sedout=$(file "$sperfpath" | sed -E 's/.*: ([A-Za-z0-9\-]+) .*/\1/g')
printf 'DEBUG\t OS: %s FileSperf: %s Sed: %s \n' "$OSTYPE" "$filetype" "$sedout"
fi
}
sperfrun() {
sperfcheck
if [[ "$debug" == "1" ]]; then
printf 'DEBUG\t Pyornotpy: %s\n' "$pyornotpy"
echo "DEBUG Command: "$pythonpath" "$sperfpath" -x -d "$subdiag" > ./wrapper/sperfgeneral.txt"
fi
if [[ "$pyornotpy" == "1" ]]; then
echo "Sperf summary"
"$pythonpath" "$sperfpath" -x -d "$subdiag" > ./wrapper/sperfgeneral.txt
echo "Sperf GC analysis"
"$pythonpath" "$sperfpath" -x -d "$subdiag" core gc > ./wrapper/sperfgc.txt
echo "Sperf StatusLogger"
"$pythonpath" "$sperfpath" -x -d "$subdiag" core statuslogger > ./wrapper/sperfstatuslog.txt
echo "Sperf Slow Query"
"$pythonpath" "$sperfpath" -x core slowquery -d "$subdiag" > ./wrapper/sperfslow.txt
echo "Sperf Schema"
"$pythonpath" "$sperfpath" -x core schema -d "$subdiag" > ./wrapper/sperfschema.txt
if [[ "$pernode" == 1 ]]; then
echo "Sperf GC per node"
"$pythonpath" "$sperfpath" -x -d "$subdiag" core gc -r nodes > ./wrapper/sperfnodegc.txt
echo "Sperf StatusLogger per node"
"$pythonpath" "$sperfpath" -x -d "$subdiag" core statuslogger -r histogram > ./wrapper/sperfnodestatuslog.txt
fi
if [[ "$solrparse" == 1 ]]; then
echo "Sperf Solr Filtercache"
"$pythonpath" "$sperfpath" -x search filtercache -d "$subdiag" > ./wrapper/sperfsolrcache.txt
echo "Sperf Solr Queryscore"
"$pythonpath" "$sperfpath" -x search queryscore -d "$subdiag" > ./wrapper/sperfsolrscore.txt
fi
else
echo "Sperf summary"
"$sperfpath" -x -d "$subdiag" > ./wrapper/sperfgeneral.txt
echo "Sperf GC analysis"
"$sperfpath" -x -d "$subdiag" core gc > ./wrapper/sperfgc.txt
echo "Sperf StatusLogger"
"$sperfpath" -x -d "$subdiag" core statuslogger > ./wrapper/sperfstatuslog.txt
echo "Sperf Slow Query"
"$sperfpath" -x core slowquery -d "$subdiag" > ./wrapper/sperfslow.txt
echo "Sperf Schema"
"$sperfpath" -x core schema -d "$subdiag" > ./wrapper/sperfschema.txt
if [[ "$pernode" == 1 ]]; then
echo "Sperf GC per node"
"$sperfpath" -x -d "$subdiag" core gc -r nodes > ./wrapper/sperfnodegc.txt
echo "Sperf StatusLogger per node"
"$sperfpath" -x -d "$subdiag" core statuslogger -r histogram > ./wrapper/sperfnodestatuslog.txt
fi
if [[ "$solrparse" == 1 ]]; then
echo "Sperf Solr Filtercache"
"$sperfpath" -x search filtercache -d "$subdiag" > ./wrapper/sperfsolrcache.txt
echo "Sperf Solr Queryscore"
"$sperfpath" -x search queryscore -d "$subdiag" > ./wrapper/sperfsolrscore.txt
fi
fi
}
# Time to build the content
header() {
cat > ./wrapper/left_frame.htm << EOF
<!DOCTYPE html>
<html>
<head>
<title>Diag files</title>
</head>
<body>
<img src="./datastax.png" alt="DataStax"><br><br>
EOF
}
# Populate the frame for nibbler files
nibblerpop() {
cat >> ./wrapper/left_frame.htm << EOF
<b>Nibbler</b><br>
EOF
for i in $(ls ./Nibbler)
do
linkname
printf '\t\t\t<a href="../Nibbler/%s" target = "center">%s</a><br>\n' $i $link >> ./wrapper/left_frame.htm
done
}
# Populate the frame for sperf files
sperfpop() {
cat >> ./wrapper/left_frame.htm << EOF
<br>
<b>Sperf</b><br>
EOF
for i in $(ls -tr ./wrapper | grep sperf*)
do
# echo $i
linkname
printf '\t\t\t<a href="./%s" target = "center">%s</a><br>\n' $i $link >> ./wrapper/left_frame.htm
done
}
footer() {
cat >> ./wrapper/left_frame.htm << EOF
</body>
</html>
EOF
}
tarball(){
echo "Compressing the data under "$opscdiag"_parsed.tgz"
tar -czf "$opscdiag"_parsed.tgz Nibbler wrapper
}
browseropen() {
echo "Opening browser"
if [[ "$(sed 's/.*microsoft.*/win/gi' /proc/version)" == "win" ]]; then opscdiag="$(wslpath -m "$opscdiag")"
fi
if [[ "$newwindow" == "1" ]]; then "$browser" --new-window "file:///$opscdiag$1/wrapper/index.html"
else "$browser" "file:///$opscdiag$1/wrapper/index.html"
fi
}
debuginfo() {
echo "*** DEBUG ON: Dumping data ***"
echo "Opscdiag: $opscdiag Subdiag: $subdiag"
echo "Browser: $browser"
echo "Java: $javapath"
$javapath -version
echo "Nibbler: $nibblerpath"
echo "Python: $pythonpath"
$pythonpath -V
echo "Sperf: $sperfpath"
printf 'Current path: "%s"\n' "$(pwd)"
}
### Execution
# Is there multiple diags in there? That may be a problem
if [ $(find "$opscdiag" -maxdepth 1 -name '*-diagnostics-*' -type d | wc -l) -ge 2 ]; then
echo "Found more than one diagnostic folder in here. Please specify the exact diag. Exiting..."
ls -ltr
exit 1
# make sure I am in a diag folder first or abort all
elif [[ -d $(find "$opscdiag" -mindepth 2 -maxdepth 2 -name 'nodes' -type d) ]]; then
# Expected path above the diag. Get the diag path for sperf
subdiag="$(find "$opscdiag" -mindepth 1 -maxdepth 1 -name '*-diagnostics-*' -type d)"
if [[ -z "$subdiag" ]]; then
echo "Cannot find the diagnostics folder. Exiting..."
exit 1
fi
elif [[ -d $(find "$opscdiag" -mindepth 1 -maxdepth 1 -name 'nodes' -type d) ]]; then
# Directly in the directory containing the nodes folder. Setting subdiag as per the current diag.
subdiag="$opscdiag"
else
echo "Cannot find the nodes folder. Exiting..."
exit 1
fi
# Open existing report or process the request
if [[ "$debug" == "1" ]]; then
printf 'DEBUG\t Opscdiag: "%s" Template: "%s" Subdiag: "%s"\n' "$opscdiag" "$template" "$subdiag"
fi
pushd "$opscdiag" > /dev/null
# File was already processed locally
if [[ -f "$opscdiag"/wrapper/index.html ]]; then
browseropen
# If parsed diag was processed and sent to ZD by a fellow supportineer and brought back by ssdownloader.
# This will require more testing
elif [[ -f "$opscdiag"_parsed/wrapper/index.html ]]; then
browseropen _parsed
elif [[ -f "$opscdiag"_parsed.tgz ]]; then
# The tgz exists but wasnt uncompressed
echo "Found parsed archive: "$opscdiag"_parsed.tgz"
echo "Uncompressing existing parsed diag and opening it"
echo "Will open "file:///"$opscdiag"/wrapper/index.html""
tar zxf "$opscdiag"_parsed.tgz
browseropen
else
prep
nibblerrun
sperfrun
header
nibblerpop
sperfpop
footer
# need to revisit tarball generation. Too many issues at the moment
# tarball
browseropen
fi
if [[ "$debug" == "1" ]]; then debuginfo
fi
popd > /dev/null