-
Notifications
You must be signed in to change notification settings - Fork 30
/
index.html
286 lines (266 loc) · 12.1 KB
/
index.html
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
<!DOCTYPE html>
<html lang="zh-CN" style="height: 100%">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts@5/dist/echarts.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>
</head>
<body style="height: 100%; margin: 0">
<div id="container"
style="height: 70%; margin: auto; width:98%; padding: 10px; box-sizing: border-box; box-shadow: rgba(0, 0, 0, 0.3) 0px 0px 20px;">
</div>
<div id="app" style="margin: 20px;">
<el-row>
<el-button type="primary" :loading="g_running" @click="submitStart">Stress Start</el-button>
<el-button type="danger" @click="submitStop">Stress Stop</el-button>
</el-row>
<el-input placeholder="Metrics Duration, default 2000ms" v-model="time_metrics" style="margin: 4px 0;">
<template slot="prepend">Metrics Duration</template>
</el-input>
<el-input placeholder="request url" v-model="url" style="margin: 4px 0;">
<template slot="prepend">Stress Url</template>
</el-input>
<el-input placeholder="GET, POST, PUT, DELETE, HEAD, OPTIONS" v-model="request_method" style="margin: 4px 0;">
<template slot="prepend">Request method</template>
</el-input>
<el-input placeholder="Request body" v-model="request_body" type="textarea"
:autosize="{ minRows: 5, maxRows: 100}" style="margin: 4px 0;">
<template slot="prepend">Request body</template>
</el-input>
<el-input placeholder="empty, hex, default empty" v-model="request_bodytype" style="margin: 4px 0;">
<template slot="prepend">Request bodytype</template>
</el-input>
<el-input placeholder="http1, http2, ws, wss, default http1" v-model="request_type" style="margin: 4px 0;">
<template slot="prepend">Request type</template>
</el-input>
<el-input placeholder="n" v-model="n" style="margin: 4px 0;">
<template slot="prepend">N</template>
</el-input>
<el-input placeholder="c" v-model="c" style="margin: 4px 0;">
<template slot="prepend">C</template>
</el-input>
<el-input placeholder="duration(s)" v-model="duration" style="margin: 4px 0;">
<template slot="prepend">Duration</template>
</el-input>
<el-input placeholder="timeout(ms)" v-model="timeout" style="margin: 4px 0;">
<template slot="prepend">Timeout</template>
</el-input>
<el-input placeholder="qps" v-model="qps" style="margin: 4px 0;">
<template slot="prepend">QPS</template>
</el-input>
<el-input placeholder="/api" v-model="worker_api" style="margin: 4px 0;">
<template slot="prepend">Worker API</template>
</el-input>
</div>
<script type="text/javascript">
Date.prototype.format = function (fmt) {
let o = {
"M+": this.getMonth() + 1,
"d+": this.getDate(),
"h+": this.getHours(),
"m+": this.getMinutes(),
"s+": this.getSeconds(),
"q+": Math.floor((this.getMonth() + 3) / 3),
"S": this.getMilliseconds()
};
if (/(y+)/.test(fmt)) {
fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
}
for (let k in o) {
if (new RegExp("(" + k + ")").test(fmt)) {
fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) : (("00" + o[k]).substr(("" + o[k]).length)));
}
}
return fmt;
}
const contentType = { 'Content-Type': 'application/json;charset=utf-8' };
const workerApiPath = "/api";
let dom = document.getElementById('container');
let stressChart = echarts.init(dom, 'dark', {
renderer: 'canvas',
useDirtyRect: false
});
function metricsLoad(timeList, qpsList, codeList) {
let option = {
legend: {
data: ['qps']
},
tooltip: {
trigger: 'axis',
axisPointer: { type: 'cross' }
},
xAxis: {
type: 'category',
data: timeList
},
yAxis: {
type: 'value'
},
series: [
{
name: "qps",
data: qpsList,
type: 'line',
smooth: true
},
]
};
for (let key in codeList) {
option.series.push({
name: key,
data: codeList[key],
type: 'line',
smooth: true
});
option.legend.data.push(key);
}
if (option && typeof option === 'object') {
stressChart.setOption(option);
}
}
metricsLoad([new Date().format("hh:mm:ss")], [0])
window.addEventListener('resize', stressChart.resize);
new Vue({
el: '#app',
data: {
time_metrics: 2000,
request_method: "GET",
request_body: "",
request_bodytype: "",
request_type: "http1",
n: 0,
c: 1,
duration: 1000,
timeout: 3000,
qps: 0,
disable_compression: false,
disable_keepalives: false,
auth_username: "",
auth_password: "",
url: "http://127.0.0.1:8000?data=1",
worker_api: "",
g_running: false,
g_seqid: Math.floor(Math.random() * 1000000) + 1,
g_interval: undefined,
},
methods: {
submitStart: function (e) {
let request_data = {
cmd: 0,
sequence_id: this.g_seqid,
request_method: this.request_method,
request_body: this.request_body,
request_bodytype: this.request_bodytype,
request_type: this.request_type,
n: parseInt(this.n),
c: parseInt(this.c),
duration: parseInt(this.duration),
timeout: parseInt(this.timeout),
qps: parseInt(this.qps),
disable_compression: this.disable_compression || this.disable_compression == "true" ? true : false,
disable_keepalives: this.disable_keepalives || this.disable_keepalives == "true" ? true : false,
auth_username: this.auth_username,
auth_password: this.auth_password,
url: this.url,
};
let worker_api = workerApiPath;
if (this.worker_api.length > 0) {
worker_api = this.worker_api;
}
fetch(worker_api, {
method: 'POST',
headers: contentType,
body: JSON.stringify(request_data)
}).then(response => response.json()).then(data => {
if (data.err_code != 0) {
this.g_running = false;
this.g_interval && clearInterval(this.g_interval);
this.$message({
showClose: true,
message: 'error:' + data.err_msg,
type: 'error',
duration: 5000,
});
return;
}
this.$message({
showClose: true,
message: 'Start Stress',
type: 'success',
duration: 2000,
});
});
let time_list = [], qps_list = [], lats_total = 0;
let status_code_list = {}, lats_status_code_list = {};
let time_metrics = this.time_metrics > 0 ? this.time_metrics : 2000;
this.g_running = true;
this.g_interval = setInterval(function () {
request_data.cmd = 2; // get metrics
fetch(worker_api, {
method: 'POST',
headers: contentType,
body: JSON.stringify(request_data)
}).then(response => response.json()).then(data => {
if (data && data.lats_total && (data.lats_total - lats_total) >= 0) {
time_list.push(new Date().format("hh:mm:ss"));
qps_list.push((data.lats_total - lats_total) * 1000 / time_metrics);
lats_total = data.lats_total;
if (data.status_code_dist) {
for (let key in data.status_code_dist) {
if (!status_code_list.hasOwnProperty(key)) {
status_code_list[key] = [];
}
if (!lats_status_code_list.hasOwnProperty(key)) {
lats_status_code_list[key] = 0;
}
status_code_list[key].push(
(data.status_code_dist[key] - lats_status_code_list[key]) * 1000 / time_metrics)
}
lats_status_code_list = data.status_code_dist;
}
}
metricsLoad(time_list, qps_list, status_code_list);
})
}, time_metrics);
},
submitStop: function (e) {
this.g_running = false;
this.g_interval && clearInterval(this.g_interval);
let request_data = {
cmd: 1, // stop
sequence_id: this.g_seqid,
};
let worker_api = workerApiPath;
if (this.worker_api.length > 0) {
worker_api = this.worker_api;
}
fetch(worker_api, {
method: 'POST',
headers: contentType,
body: JSON.stringify(request_data)
}).then(response => response.json()).then(data => {
if (data.err_code != 0) {
this.$message({
showClose: true,
message: 'error:' + data.err_msg,
type: 'error',
duration: 5000,
});
return;
}
this.$message({
showClose: true,
message: 'Stop Stress',
type: 'success',
duration: 2000,
});
});
}
}
})
</script>
</body>
</html>