startJmeter.sh
3.16 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
112
113
114
115
116
#!/bin/bash
function usage(){
echo "----------------------------------"
echo "参数说明:"
echo "-s : 脚本相对路径"
echo "-e : 要修改的hosts"
echo "-c 不带参数,表示关闭jmeter"
echo ""
echo "举例:sh startJmeter.sh -s \"/script/test.jmx\" -e \"10.10.11.1 test.test.com\" -e \"192.168.1.1 test.yoho.cn\""
echo "----------------------------------"
}
if [[ $# -lt 1 ]];then
usage
exit 1
fi
while getopts "cs:e:h" arg
do
case $arg in
c)
c="close"
;;
s)
s=$OPTARG
;;
e)
if [ ! $e ];then
e=$OPTARG
else
e="$e\n$OPTARG"
fi
;;
h)
usage
exit 1
;;
?)
echo "未知的参数!"
exit 1
;;
esac
done
PATH_JMETER_HOME="/opt/jmeter"
PATH_JMETER_LOG="/Data/logs/jmeter"
#CMD_PS_JMETER="ps -ef| grep -e \"${PATH_JMETER_HOME}/bin/jmeter.*-n.*-t.*-X\" -e \"java -server -XX:+HeapDumpOnOutOfMemoryError.*-XX:+CMSClassUnloadingEnabled -jar ${PATH_JMETER_HOME}/bin/ApacheJMeter.jar -n -t\" -e \"${PATH_JMETER_HOME}/bin/jmeter-server\" -e \"${PATH_JMETER_HOME}/bin/jmeter.*-Djava.rmi.server.hostname=\" -e \"java -server -XX:+HeapDumpOnOutOfMemoryError.*-jar ${PATH_JMETER_HOME}/bin/ApacheJMeter.jar -Dserver_port=\" | grep -v grep";
CMD_PS_JMETER="ps -ef | grep \"jar /opt/jmeter/bin/.*-n -t ${PATH_JMETER_HOME}${s}\" | grep -v grep"
CMD_KILL_JMETER="${CMD_PS_JMETER} | cut -c 9-15 | xargs kill -9"
CMD_CLEAR_JMETERLOG="echo > ${PATH_JMETER_LOG}/jmeter.jtl;echo > ${PATH_JMETER_LOG}/jmeterRun.log;echo > ${PATH_JMETER_LOG}/runtime.log;"
CMD_RESTART_MONITOR="${PATH_JMETER_HOME}/shell/restart_YPT_AUTO_MONITOR.sh"
CMD_STOP_MONITOR="${CMD_RESTART_MONITOR} stop"
#CMD_UPDATE_SVN="svn up ${PATH_JMETER_HOME}"
CMD_SYNC_SYSTEMTIME="ntpdate asia.pool.ntp.org"
HOST_NAME=$(hostname)
IP=$(/sbin/ip addr show | grep eth | grep inet | awk '{print $2}' | awk -F '/' '{print $1}')
function startJmeter(){
echo "[startJmeter]脚本路径:${PATH_JMETER_HOME}${s}"
#${PATH_JMETER_HOME}/bin/jmeter -n -t ${PATH_JMETER_HOME}${s} -l ${PATH_JMETER_LOG}/jmeter.jtl -j ${PATH_JMETER_LOG}/jmeterRun.log -X > ${PATH_JMETER_LOG}/runtime.log &
${PATH_JMETER_HOME}/bin/jmeter -n -t ${PATH_JMETER_HOME}${s} -l /dev/null -j ${PATH_JMETER_LOG}/jmeterRun.log -X > ${PATH_JMETER_LOG}/runtime.log &
}
function stopJmeter(){
eval $CMD_KILL_JMETER
}
function clearJmeterLogs(){
eval $CMD_CLEAR_JMETERLOG
}
function restartMonitor(){
eval $CMD_RESTART_MONITOR
}
function stopMonitor(){
eval $CMD_STOP_MONITOR
}
#function updateSvn(){
#eval $CMD_UPDATE_SVN
#}
function gitUpdate(){
cd $PATH_JMETER_HOME
git reset --hard origin/master
git pull
}
function modifyHosts(){
echo "[modifyHosts]HOSTS:127.0.0.1 localhost\n::1 localhost\n$IP $HOST_NAME\n$e"
echo -e "127.0.0.1 localhost\n::1 localhost\n$IP $HOST_NAME\n$e" > /etc/hosts
}
function syncSystemTime(){
eval $CMD_SYNC_SYSTEMTIME
}
function runJmeter(){
START_TIME=$(date)
echo "[START][$START_TIME]-----------------------------"
stopJmeter
clearJmeterLogs
modifyHosts
#updateSvn
gitUpdate
restartMonitor
syncSystemTime
startJmeter
echo "[Now Start!]"
}
if [ ! $c ];then
if [ ! $s ];then
echo "脚本相对路径不能为空,使用 -s 配置脚本路径!"
else
runJmeter
fi
else
stopJmeter
stopMonitor
END_TIME=$(date)
echo "[STOPPED][$END_TIME]-----------------------------"
fi