profile_server.hbs
9.34 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
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
287
288
289
290
291
292
293
294
295
<div class="pageheader">
<div class="media">
<div class="pageicon pull-left">
<i class="fa fa-th-list"></i>
</div>
<div class="media-body">
<ul class="breadcrumb">
<li><a href=""><i class="glyphicon glyphicon-home"></i></a></li>
<li><a href="">性能监控</a></li>
<li>服务器调用时间统计</li>
</ul>
<h4>服务器调用时间统计</h4>
</div>
</div>
<!-- media -->
</div>
<!-- pageheader -->
<div class="contentpanel page-servers">
<div class="panel panel-primary-head">
<div class="panel-heading" style="overflow: hidden">
<div class="pull-left">
<select id="selectedServer" class="selectpicker show-menu-arrow form-control" style="margin-left: 10px;">
<option value="aws" selected>aws</option>
<option value="qcloud">qcloud</option>
</select>
</div>
<div id="reportrange" class="pull-left"
style="display: inline-block; background: #fff; cursor: pointer; padding: 9px 10px; border: 1px solid #ccc; width: 250px; color: black; margin-left: 20px;">
<i class="glyphicon glyphicon-calendar fa fa-calendar"></i>
<span></span> <b class="caret"></b>
</div>
<div class="pull-left">
<select id="selectedApp" class="selectpicker show-menu-arrow form-control" style="margin-left: 10px;">
<option value="default">全部</option>
<option value="pc">PC</option>
<option value="h5">H5</option>
</select>
</div>
<div class="pull-left">
<button id="search" class="btn btn-info" style="margin-left: 20px;">查询</button>
</div>
</div>
<!-- panel-heading -->
<table id="table-servers" class="table table-striped table-bordered">
<thead class="">
<tr>
<td >接口名称</td>
<td >调用次数</td>
<td >耗时</td>
<td >调用接口数</td>
<td >详细情况</td>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog modal-lg" role="document" style="display:table;">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">详细信息</h4>
</div>
<div class="modal-body">
<table id="table-detail" class="table table-striped table-bordered">
<thead class="">
<tr>
<td >time</td>
<td >api</td>
<td >count</td>
<td >mean</td>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
</div>
</div>
</div>
</div>
<!-- panel -->
</div>
<script>
var selectedServer, selectedStarTime, selectedEndTime, selectedApp, lastTime;
var data_end_point = '/profile/server.json';
var dataTable = null, detailTable = null;
function ajaxUrl() {
let url = `${data_end_point}?app=${selectedApp}&server=${selectedServer}`;
if (selectedEndTime && selectedEndTime) {
url += `&start=${selectedStarTime}&end=${selectedEndTime}`;
}
if (lastTime) {
url += `&lastTime=${lastTime}`
}
return url
}
$(function() {
init();
initTable();
initDatePicker();
initSelect();
});
function init() {
selectedServer = 'aws';
selectedApp = 'default';
}
function initTable() {
dataTable = $("#table-servers").DataTable({
pageLength: 20,
retrieve: true,
searching: true,
dataSrc: 'data',
pageLength: 25,
columns: [
{data: 'route'},
{data: 'count'},
{data: 'mean'},
{data: 'length'},
{data: 'detail'}
],
data: [{
route: '',
count: 0,
mean: 0,
length: 0,
detail: []
}],
order: [[ 2, "desc" ]],
columnDefs: [ {
targets: -1,
data: null,
render: function ( data, type, row ) {
if (data.length) {
return '<button data-toggle="modal" data-target="#myModal">查看</button>';
} else {
return '—';
}
},
}, {
targets: -2,
data: null,
render: function ( data, type, row ) {
if (data) {
return data;
} else {
return '—';
}
},
}]
});
$('#table-servers tbody').on( 'click', 'button', function (e) {
var data = dataTable.row($(this).parents('tr')).data();
var modal = $('#myModal');
modal.on('show.bs.modal', function () {
detailTable.clear().rows.add(data.detail).draw();
});
e.preventDefault();
});
detailTable = $("#table-detail").DataTable({
pageLength: 20,
retrieve: true,
searching: true,
dataSrc: 'data',
pageLength: 25,
columns: [
{data: 'time'},
{data: 'api'},
{data: 'count'},
{data: 'mean'}
],
data: [{
time: '',
api: '',
count: '',
mean: ''
}],
order: [[ 0, "desc" ]],
columnDefs: [
{
render: function(data, type, row) {
return moment(data).format('YYYY/MM/DD HH:MM:ss');
},
targets: 0
}
],
});
}
const TIME = {
'最近1分钟': '1m',
'最近30分钟': '30m',
'最近1小时': '1h',
'最近3小时': '3h',
'最近6小时': '6h',
'最近12小时': '12h'
};
function initDatePicker() {
var start = selectedStarTime;
var end = selectedEndTime;
var first = '最近1分钟';
$('#reportrange span').html(first);
lastTime = TIME[first];
function cb(start, end, label) {
if (label && label !== '自定义日期') {
$('#reportrange span').html(label);
lastTime = TIME[label];
} else if (label && label === '自定义日期'){
$('#reportrange span').html(start.format('YYYY-MM-DD') + ' 至 ' + end.format('YYYY-MM-DD'));
selectedStarTime = start.format('YYYY-MM-DD');
selectedEndTime = end.format('YYYY-MM-DD');
lastTime = null
}
}
$('#reportrange').daterangepicker({
startDate: start,
endDate: end,
timePicker: true,
timePicker24Hour: true,
dateLimit: {
days: 7
},
ranges: {
'最近1分钟': [moment().subtract(1, 'minutes'), moment()],
'最近30分钟': [moment().subtract(30, 'minutes'), moment()],
'最近1小时': [moment().subtract(1, 'hours'), moment()],
'最近3小时': [moment().subtract(3, 'hours'), moment()],
'最近6小时': [moment().subtract(6, 'hours'), moment()],
'最近12小时': [moment().subtract(12, 'hours'), moment()]
},
locale: {
format: "YYYY-MM-DD",
applyLabel: '确定',
cancelLabel: '取消',
weekLabel: 'W',
customRangeLabel: '自定义日期',
daysOfWeek: '一_二_三_四_五_六_日'.split('_'),
monthNames: '1月_2月_3月_4月_5月_6月_7月_8月_9月_10月_11月_12月'.split('_'),
firstDay: 1
},
}, cb);
cb(start, end);
}
function initSelect() {
$('#selectedServer').change(function() {
selectedServer = $('#selectedServer').val();
});
$('#selectedApp').change(function() {
selectedApp = $('#selectedApp').val();
});
$('#search').on('click', () => {
_handleChanged();
})
}
function _handleChanged() {
dataTable && dataTable.ajax.url(ajaxUrl()).load();
}
</script>