-
Notifications
You must be signed in to change notification settings - Fork 28
/
index.html
134 lines (134 loc) · 5.48 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
<!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 href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.1/dist/css/bootstrap.min.css" rel="stylesheet"/>
</head>
<body style="height: 100%; margin: 0">
<div id="container" style="height: 70%"></div>
<div>
<div class="form-group form-inline" style="margin: 5px;">
<label for="requestForm" style="margin-left: 5px;">Input Request:</label>
<button type="button" class="btn btn-success" onclick="submitStart()" style="margin-left: 5px;">Start</button>
<button type="button" class="btn btn-danger" onclick="submitStop()" style="margin-left: 5px;">Stop</button>
</div>
<div class="form-group form-inline" style="margin: 5px;">
<label for="requestForm" style="margin-left: 5px;">Time Metrics:</label>
<input type="text" class="form-control" id="timeMetrics" aria-describedby="Time Metrics" style="margin-left: 5px;" value="1000" />
</div>
<div class="form-group">
<textarea class="form-control" id="requestForm" rows="10">
{
"request_method": "GET",
"request_body": "",
"request_httptype": "http1",
"n": 0,
"c": 1,
"duration": 1000,
"timeout": 3000,
"qps": 0,
"disable_compression": false,
"disable_keepalives": false,
"auth_username": "",
"auth_password": "",
"headers": null,
"urls": ["http://9.134.13.199:8000?data=1"]
}</textarea>
</div>
</div>
<script type="text/javascript">
Date.prototype.format = function(fmt) {
var 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(var 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;
}
var seqid = Math.floor(Math.random() * 1000000) + 1;
var interval;
function submitStart(e) {
seqid = seqid + 1;
var requestData = JSON.parse(document.getElementById("requestForm").value);
var timeMetrics = parseInt(document.getElementById("timeMetrics").value);
timeMetrics = timeMetrics ? timeMetrics : 5000;
requestData.cmd = 0;
requestData.sequence_id = seqid;
fetch('/api', {
method: 'POST',
headers: {'Content-Type': 'application/json;charset=utf-8'},
body: JSON.stringify(requestData)
}).then(response => response.json());
var timeList = [], dataList = [], latsTotal = 0;
interval = setInterval(function() {
requestData.cmd = 2;
fetch('/api', {
method: 'POST',
headers: {'Content-Type': 'application/json;charset=utf-8'},
body: JSON.stringify(requestData)
}).then(response => response.json()).then(data => {
if (data && data.lats_total && (data.lats_total - latsTotal) >= 0) {
timeList.push(new Date().format("hh:mm:ss"));
dataList.push((data.lats_total - latsTotal)*1000/timeMetrics);
metricsLoad(timeList, dataList);
latsTotal = data.lats_total;
}
})
}, timeMetrics)
}
function submitStop(e) {
clearInterval(interval);
var requestData = JSON.parse(document.getElementById("requestForm").value);
requestData.cmd = 1;
requestData.sequence_id = seqid;
fetch('/api', {
method: 'POST',
headers: {'Content-Type': 'application/json;charset=utf-8'},
body: JSON.stringify(requestData)
});
}
var dom = document.getElementById('container');
var stressChart = echarts.init(dom, 'dark', {
renderer: 'canvas',
useDirtyRect: false
});
function metricsLoad(timeList, dataList) {
var option = {
xAxis: {
type: 'category',
data: timeList
},
yAxis: {
type: 'value'
},
series: [
{
data: dataList,
type: 'line',
smooth: true
}
]
};
if (option && typeof option === 'object') {
stressChart.setOption(option);
}
}
metricsLoad([new Date().format("hh:mm:ss")], [0])
window.addEventListener('resize', stressChart.resize);
</script>
</body>
</html>