-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrunrubis
More file actions
executable file
·164 lines (136 loc) · 3.62 KB
/
runrubis
File metadata and controls
executable file
·164 lines (136 loc) · 3.62 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
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
#!/bin/bash
target=c11node10
#target=10.5.147.210
#postcopy=on
postcopy=off
#masterpost=on
masterpost=off
ram=1024
vcpu=1
# boot up vm
preptime=90
# sleep interval
sleeptime=5
#ports=( 4446 4447 4448 4449 )
ports=( 4450 4451 4452 4453 )
#nports=${#ports[@]}
#nports=1
nports=4
remain=$nports
#migspeed=30
migspeed=125
# for cpu utilization
PREV_TOTAL=0
PREV_IDLE=0
function startcluster() {
# generate a random mac address for the qemu nic
#mac=`printf 'DE:AD:BE:EF:%02X:%02X\n' $((RANDOM%256)) $((RANDOM%256))`
# filename ram vcpu telnetport vncport listenport mac_address
# tomcat 10.244.38.13
mac=DE:AD:BE:EF:30:80
./runvm-daemon "rubis/tomcat.qcow2" $ram $vcpu ${ports[0]} 5 $mac
# jboss 10.244.37.74
mac=DE:AD:BE:EF:CA:8B
#./runvm-daemon "rubis/jboss.qcow2" $ram $vcpu ${ports[1]} 6 $mac
# slave2 10.244.38.71
mac=DE:AD:BE:EF:FF:57
# ./runvm-daemon slave2.qcow2 $ram $vcpu 4448 3 $mac
# slave3 10.244.38.70
mac=DE:AD:BE:EF:A6:75
#mac=DE:AD:BE:EF:92:C8
#./runvm-daemon slave3.qcow2 $ram $vcpu 4449 4 $mac
}
function migrate() {
# filename ram vcpu telnetport vncport listenport postcopy migration_speed
./ncmigrate "rubis/tomcat.qcow2" $ram $vcpu ${ports[0]} 5 5450 $masterpost $migspeed
./ncmigrate "rubis/jboss.qcow2" $ram $vcpu ${ports[1]} 6 5451 $postcopy $migspeed
./ncmigrate slave2.qcow2 $ram $vcpu 4448 3 5448 $postcopy $migspeed
./ncmigrate slave3.qcow2 $ram $vcpu 4449 4 5449 $postcopy $migspeed
}
function check() {
#while [ $remain -gt 0 ];
while [ 1 ];
do
#remain=${#ports[@]}
remain=$nports
for port in ${ports[@]};
do
info=`./checkstatus localhost $port`
if [[ -z $info ]]; then
(( remain -- ))
continue
fi
status=`echo "$info" | grep -a complete | awk '{print $3}'`
#echo $status
if [[ $status == *completed* ]]; then
echo $port
echo "$info"
./stopvm localhost $port
#./stopvm $target $port
(( remain -- ))
continue
fi
# ./checkstatus $target $port
done
echo remaining: $remain
if [ $remain -le 0 ]; then
break
fi
sleep $sleeptime
done
}
function finish() {
for port in ${ports[@]};
do
echo $port
./stopvm localhost $port
# ./stopvm $target $port
done
}
# average cpu usage since the last measurement
function cpusage() {
CPU=(`grep '^cpu ' /proc/stat`) # Get the total CPU statistics.
unset CPU[0] # Discard the "cpu" prefix.
IDLE=${CPU[4]} # Get the idle CPU time.
# Calculate the total CPU time.
TOTAL=0
for VALUE in "${CPU[@]}"; do
let "TOTAL=$TOTAL+$VALUE"
done
# Calculate the CPU usage since we last checked.
let "DIFF_IDLE=${IDLE}-${PREV_IDLE}"
let "DIFF_TOTAL=${TOTAL}-${PREV_TOTAL}"
let "DIFF_USAGE=(1000*(${DIFF_TOTAL}-${DIFF_IDLE})/${DIFF_TOTAL}+5)/10"
#echo -e "$DIFF_USAGE"
echo -e "CPU: $DIFF_USAGE %"
#echo -e "\rCPU: $DIFF_USAGE % \b\b"
# Remember the total and idle CPU times for the next check.
PREV_TOTAL="$TOTAL"
PREV_IDLE="$IDLE"
}
function migratecluster() {
dstatfile=src.dstat
dstatdest=dest.dstat
dstat -cmdngy -N eth0 --noheaders > $dstatfile &
ssh $target "dstat -cmdngy -N eth0 --noheaders" > $dstatdest &
# sleep $preptime
migrate
check
# stop dstat
pgrep -fl dstat| awk '{print $1}' | xargs kill -9
ssh $target "pgrep -fl dstat| awk '{print $1}' | xargs kill -9"
# plot host cpu/net usage
# fix to add both send/receive
plotcpu="./plotcpu"
plotnet="./plotnet"
$plotcpu $dstatfile
$plotnet $dstatfile
$plotcpu $dstatdest
$plotnet $dstatdest
}
#cpusage
startcluster
#migratecluster
#migratecluster > migrate.log
#finish
#cpusage