debugJmx.sh
4.66 KB
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
#!/bin/bash
function usage(){
echo "----------------------------------"
echo "参数说明:"
echo "-p : jmx文件全父路径"
echo "-n : jmx文件名称"
echo "-t : 线程数"
echo "-c : 运行次数"
echo ""
echo "举例:sh debugJmx.sh -p /opt/jmeter/script/default -n test123.jmx -t 1 -c 1"
echo "----------------------------------"
}
if [[ $# -lt 1 ]];then
usage
exit 1
fi
while getopts "p:n:t:c:" arg
do
case $arg in
p)
jmxPath=$OPTARG
;;
n)
jmxName=$OPTARG
;;
t)
threadCount=$OPTARG
;;
c)
loops=$OPTARG
;;
h)
usage
exit 1
;;
?)
echo "未知的参数!"
exit 1
;;
esac
done
DEBUG_JMX_PATH=/tmp/debugJmx
DEBUG_LOG_PATH=$DEBUG_JMX_PATH/${jmxName}.debug.log
ResultCollector="<ResultCollector guiclass=\"StatVisualizer\" testclass=\"ResultCollector\" testname=\"聚合报告\" enabled=\"true\">\n"
ResultCollector="${ResultCollector} <boolProp name=\"ResultCollector.error_logging\">false<\/boolProp>\n"
ResultCollector="${ResultCollector} <objProp>\n"
ResultCollector="${ResultCollector} <name>saveConfig<\/name>\n"
ResultCollector="${ResultCollector} <value class=\"SampleSaveConfiguration\">\n"
ResultCollector="${ResultCollector} <time>true<\/time>\n"
ResultCollector="${ResultCollector} <latency>true<\/latency>\n"
ResultCollector="${ResultCollector} <timestamp>true<\/timestamp>\n"
ResultCollector="${ResultCollector} <success>true<\/success>\n"
ResultCollector="${ResultCollector} <label>true<\/label>\n"
ResultCollector="${ResultCollector} <code>true<\/code>\n"
ResultCollector="${ResultCollector} <message>true<\/message>\n"
ResultCollector="${ResultCollector} <threadName>true<\/threadName>\n"
ResultCollector="${ResultCollector} <dataType>true<\/dataType>\n"
ResultCollector="${ResultCollector} <encoding>true<\/encoding>\n"
ResultCollector="${ResultCollector} <assertions>true<\/assertions>\n"
ResultCollector="${ResultCollector} <subresults>true<\/subresults>\n"
ResultCollector="${ResultCollector} <responseData>true<\/responseData>\n"
ResultCollector="${ResultCollector} <samplerData>true<\/samplerData>\n"
ResultCollector="${ResultCollector} <xml>true<\/xml>\n"
ResultCollector="${ResultCollector} <fieldNames>true<\/fieldNames>\n"
ResultCollector="${ResultCollector} <responseHeaders>true<\/responseHeaders>\n"
ResultCollector="${ResultCollector} <requestHeaders>true<\/requestHeaders>\n"
ResultCollector="${ResultCollector} <responseDataOnError>false<\/responseDataOnError>\n"
ResultCollector="${ResultCollector} <saveAssertionResultsFailureMessage>true<\/saveAssertionResultsFailureMessage>\n"
ResultCollector="${ResultCollector} <assertionsResultsToSave>0<\/assertionsResultsToSave>\n"
ResultCollector="${ResultCollector} <bytes>true<\/bytes>\n"
ResultCollector="${ResultCollector} <sentBytes>true<\/sentBytes>\n"
ResultCollector="${ResultCollector} <url>true<\/url>\n"
ResultCollector="${ResultCollector} <fileName>true<\/fileName>\n"
ResultCollector="${ResultCollector} <hostname>true<\/hostname>\n"
ResultCollector="${ResultCollector} <threadCounts>true<\/threadCounts>\n"
ResultCollector="${ResultCollector} <sampleCount>true<\/sampleCount>\n"
ResultCollector="${ResultCollector} <idleTime>true<\/idleTime>\n"
ResultCollector="${ResultCollector} <connectTime>true<\/connectTime>\n"
ResultCollector="${ResultCollector} <\/value>\n"
ResultCollector="${ResultCollector} <\/objProp>\n"
ResultCollector="${ResultCollector} <stringProp name=\"filename\">${DEBUG_LOG_PATH//\//\\/}<\/stringProp>\n"
ResultCollector="${ResultCollector} <\/ResultCollector>\n"
ResultCollector="${ResultCollector} <hashTree\/>"
if [[ ! -d $DEBUG_JMX_PATH ]];then
mkdir -p $DEBUG_JMX_PATH
fi
if [[ -n $jmxPath && -n $jmxName ]];then
\cp -f $jmxPath/$jmxName $DEBUG_JMX_PATH
if [[ -n $threadCount ]];then
sed -i "s/<stringProp name=\"ThreadGroup.num_threads\">.*<\/stringProp>/<stringProp name=\"ThreadGroup.num_threads\">${threadCount}<\/stringProp>/g" $DEBUG_JMX_PATH/$jmxName
fi
if [[ -n $loops ]];then
sed -i "s/<intProp name=\"LoopController.loops\">.*<\/intProp>/<intProp name=\"LoopController.loops\">${loops}<\/intProp>/g" $DEBUG_JMX_PATH/$jmxName
fi
sed -i "s/<hashTree\/>.*<\/hashTree>/<hashTree\/>${ResultCollector}<\/hashTree>/g" $DEBUG_JMX_PATH/$jmxName
if [[ -f $DEBUG_LOG_PATH ]];then
echo > $DEBUG_LOG_PATH
fi
/opt/jmeter/bin/jmeter -n -t $DEBUG_JMX_PATH/$jmxName -l /dev/null -j /dev/null 1>/dev/null 2>&1
fi