dockerLog.jsp
17.7 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
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
<%--
Created by IntelliJ IDEA.
User: meiling.ge
Date: 2018/4/2
Time: 16:25
To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" %>
<%@page import="com.ui.contants.ProjectConstant"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="<%=basePath %>css/bootstrap.min.css"/>
<link rel="stylesheet" href="<%=basePath %>css/bootstrap-datetimepicker.css"/>
<link href="<%=basePath %>js/bootstrap-plugin/css/bootstrap.table.css" rel="stylesheet" media="screen"/>
<link rel="stylesheet" href="<%=basePath %>css/bootstrap-responsive.min.css"/>
<link rel="stylesheet" href="<%=basePath %>css/fullcalendar.css"/>
<link rel="stylesheet" href="<%=basePath %>css/unicorn.main.css"/>
<link rel="stylesheet" href="<%=basePath %>css/unicorn.grey.css"/>
<link rel="stylesheet" href="<%=basePath %>css/jquery-ui.css"/>
<link rel="stylesheet" href="<%=basePath %>css/uniform.css"/>
<%--<link rel="stylesheet" href="<%=basePath %>css/select2.css"/>
<link rel="stylesheet" href="<%=basePath %>js/select2/dist/css/select2.css"/>--%>
<link rel="stylesheet" href="<%=basePath %>css/select2-4.0.3.css"/>
<link rel="stylesheet" href="<%=basePath %>css/yoho.css"/>
<script src="<%=basePath %>js/excanvas.min.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/jquery-1.12.0.min.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/jquery-ui.custom.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>/js/bootstrap.min.js"></script>
<script src="<%=basePath %>/js/unicorn.js"></script>
<script src="<%=basePath %>js/bootstrap-plugin/datetimepicker/moment-with-locales.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/datetimepicker/bootstrap-datetimepicker.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/global.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.pagination.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.table.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.dialog.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.panel.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.alerts.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.accordion.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.breadcrumb.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.validate.js" charset="UTF-8"
type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.form.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/layer/layer.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/bootstrap-plugin/bootstrap.select.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath %>js/jquery.toaster.js"></script>
<script src="<%=basePath %>js/laydate/laydate.js" charset="UTF-8" type="text/javascript"></script>
<script src="<%=basePath%>js/select2-4.0.3.min.js"></script>
<script>
var contextPath = '<%=basePath %>';
</script>
<title>YOHO!运维</title>
</head>
<body>
<div id="head">
</div>
<!-- 右侧具体内容 -->
<div id="content">
<div id="breadcrumb">
<a href="#" title="Go to Home" class="tip-bottom"><i
class="icon-home"></i> Home</a> <a href="#" class="current">Docker日志检索</a>
</div>
<div class="container-fluid">
<div class="widget-box">
<div class="widget-content nopadding">
<div class="widget-title">
<h5>Docker日志检索</h5>
</div>
<div class="widget-title" style="height: 56px;">
<div class="form-inline" role="form" style=" margin-top: 12px;float: left;">
<button class="btn btn-primary dateTimebutton" style="margin-left: 5px;background-color: grey" onclick="setTime(this, 1)">今天</button>
<button class="btn btn-primary dateTimebutton" style="" onclick="setTime(this, -1)">昨天</button>
<button class="btn btn-primary dateTimebutton" style="" onclick="setTime(this, 7)">近7天</button>
<button class="btn btn-primary dateTimebutton" style="" onclick="setTime(this, 30)">近30天</button>
<div class="input-group" >
<span class="input-group-addon">起止时间:</span>
<input id="startTime"type="text" class="form-control dateTimeInput" style="width:150px;" />
</div>
~
<div class="input-group" >
<input id="endTime"type="text" class="form-control dateTimeInput" style="width:150px;" />
</div>
</div>
</div>
<div class="widget-title" style="height: 56px;margin-left: 5px">
<div class="form-inline" role="form" style=" margin-top: 12px;float: left;">
<div class="input-group" >
<span class="input-group-addon">日志集:</span>
<select id="logset_id" class="form-control" style="width:200px;" onchange="changeLogSet()">
<option>--请选择--</option>
<c:forEach items="${logSetInfoList}" var="logset">
<option value="${logset.logset_id}">${logset.logset_name}</option>
</c:forEach>
</select>
</div>
<div class="input-group" >
<span class="input-group-addon">日志主题:</span>
<select id="topic_ids" class="form-control select2" multiple="multiple" style="width:300px;" >
<%-- <option value="all">all</option>
<c:forEach items="${topicInfos}" var="topic">
<option value="${topic.topic_id}">${topic.topic_name}</option>
</c:forEach>--%>
</select>
</div>
<div class="input-group" >
<input id="keywords" type="text" class="form-control" style="width:200px;" placeholder="请输入关键词" />
</div>
<button id="searchBtn" class="btn btn-primary" style="margin-left: 18px;" onclick="search()">搜索</button>
</div>
</div>
</div>
<div style="margin-top: 20px;margin-bottom: 20px" >
<table id="logInfoTable" class="table table-bordered table-hover table-striped" style="margin-left:10px;width: 95%;">
<thead>
<tr>
<th style="width: 25%;text-align: center">日志属性</th>
<th style="width: 75%;text-align: center">日志数据</th>
</tr>
</thead>
<tbody id="loginfoTbody">
</tbody>
</table>
<div id="emptyInfo" style="text-align:center;" >当前列表为空</div>
<div id="showMore" style="text-align:center;display: none" ><a onclick="showMore()">加载更多</a></div>
<div id="loadingDiv" style="text-align:center;display: none" >正在加载<img src="<%=basePath%>js/layer/skin/default/loading-1.gif" ></img></div>
<div id ="nomoreDiv"style="text-align:center;display: none" >已加载全部</div>
</div>
<div>
</div>
</div>
</div>
</div>
</body>
<script src="<%=basePath %>script/common/genarate_left_panel.js?v=<%=ProjectConstant.MENU_VERSION %>"></script>
<script>
$("#li_other").addClass("active open");
$("#li_docker_log").addClass("active");
</script>
<script type="text/javascript">
$(function () {
//初始化时间
lay('.dateTimeInput').each(function(){
laydate.render({
elem: this ,type: 'datetime'
,trigger: 'click'
});
});
//日期设置默认值
//开始时间:当天凌晨
$("#startTime").val(format(new Date(new Date().setHours(0,0,0,0))).substr(0,10)+" 00:00:00");
//结束时间:当天 23:59:59
$("#endTime").val(format(new Date(new Date(new Date().toLocaleDateString()).getTime()+ 24*60*60*1000-1)));
$("#topic_ids").select2({
});
});
//设置时间
function setTime(that, val) {
$(".dateTimebutton").each(function (index, item) {
$(this).css("background-color", "#337ab7");
});
$(that).css("background-color", "grey");//选中的为灰色
//设置起止时间
var startTime;
//结束时间:今天23:59:59
var endTime = new Date(new Date(new Date().toLocaleDateString()).getTime()+24*60*60*1000-1);//23:59:59秒
if( val == 1){//今天的
startTime = new Date(new Date().setHours(0,0,0,0));
}
if( val == -1){//昨天的
startTime = new Date(new Date(new Date().setDate(new Date().getDate() - 1)).setHours(0,0,0,0));
var yestodayTime = new Date(new Date().setDate(new Date().getDate() - 1));
endTime = new Date(new Date(yestodayTime.toLocaleDateString()).getTime()+24*60*60*1000-1);//23:59:59秒
}
if(val == 7){//近7天
startTime = new Date(new Date(new Date().setDate(new Date().getDate() - 7)).setHours(0,0,0,0));
}
if(val == 30){//近30天
startTime = new Date(new Date(new Date().setDate(new Date().getDate() - 30)).setHours(0,0,0,0));
}
$("#startTime").val(format(startTime));
//结束时间:当天 23:59:59
$("#endTime").val(format(endTime));
}
//timeValue---时间戳
function format(timeValue){
var time = new Date(timeValue);
var y = time.getFullYear();
var m = time.getMonth()+1;
var d = time.getDate();
var h = time.getHours();
var mm = time.getMinutes();
var s = time.getSeconds();
return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
}
function add0(m){
return m<10 ? '0'+m : m;
}
var logset_id;
var topic_ids;
var start_time;
var end_time;
var query;
var context;
//搜索--查询日志
function search(){
$("#loginfoTbody").html("");
var logsetId = $("#logset_id").val();
if( logsetId == null || logsetId == ""){
alert("请选择日志集!");
return;
}
var topicIds = $("#topic_ids").val();
if( topicIds == null || topicIds == ""){
alert("请选择日志主题!");
return;
}
//选择全部topic 的情况下,重置topics
if( topicIds.indexOf("all") != -1){//选择全部topics
var arr = new Array();
$("#topic_ids option").each(function () {
var val = $(this).val(); //获取单个value
if( val != "all"){
arr.push(val);
}
});
topicIds = arr;
}
var startTime = $("#startTime").val();
if(startTime == null || startTime == ""){
alert("请选择开始时间!");
return;
}
var endTime = $("#endTime").val();
if(endTime == null || endTime == ""){
alert("请选择结束时间!");
return;
}
if( compareTime(startTime,endTime ) > 0){
alert("开始时间必须小于结束时间!");
return;
}
var queryInfo= $("#keywords").val();
//赋给全局变量--加载table信息
logset_id = logsetId ;
topic_ids = topicIds;
start_time = startTime;
end_time = endTime;
query = queryInfo;
context = "";//context还原
loadTable();
}
function loadTable(){
var params = {
logset_id : logset_id,
topic_ids : topic_ids.join(","),
start_time : start_time,
end_time: end_time,
query: query,
context : context
};
//隐藏所有的div
$("#showMore").css("display","none");
$("#nomoreDiv").css("display","none");
$("#emptyInfo").css("display","none");
//显示正在加载
$("#loadingDiv").css("display","block");
//查询日志信息
$.ajax({
url: contextPath + "dockerLogs/searchlog",
type: 'post',
dataType: "json",
contentType: "application/json",
data: JSON.stringify(params),
success: function (data) {
//返回的时候 隐藏正在加载
$("#loadingDiv").css("display","none");
if(data.code != 200){
alert("查询失败!");
$("#showMore").css("display","block");
return ;
}else{//查询成功
var logInfo = data.data;
//加载更多需要传递的参数
context = logInfo.context;
//展示列表
var logData = logInfo.results;
var logtableBodyHtml = "";
for( var i in logData){
var html = "<tr>" +
"<td style='width: 25%'>Time: "+logData[i].timestamp+"</br>Topic name: "+ logData[i].topic_name +"</br>"+logData[i].descr+"</td>" +
"<td style='width: 75%;word-wrap: break-word; word-break:break-all;' > " +logData[i].simpleContent +"</td></tr>";
logtableBodyHtml += html;
}
if(logtableBodyHtml == ""){
$("#emptyInfo").css("display","block");
}else{
$("#loginfoTbody").append(logtableBodyHtml);
var listover = logInfo.listover;
if( !listover){//未加载完毕
$("#showMore").css("display","block");
$("#nomoreDiv").css("display","none");
}else{
$("#showMore").css("display","none");
$("#nomoreDiv").css("display","block");
}
}
}
},
error: function(data){
alert("请求失败!");
$("#loadingDiv").css("display","none");
$("#showMore").css("display","block");
}
});
}
//加载更多
function showMore() {
loadTable();
}
function compareTime(time_1 , time_2) {
var d1 = new Date(time_1);
var d2 = new Date(time_2);
if(d1 == d2){
return 0;
}
if(d1 > d2){
return 1;
}
return -1;
}
//根据日志集id 获取 日志主题集合
function changeLogSet(){
var logset_id = $("#logset_id").val();
$.ajax({
url: contextPath + "dockerLogs/getTopicList?logset_id=" + logset_id,
type: 'get',
success: function (data) {
if(data.code != 200){
alert("获取日志主题列表失败!");
}else{//查询成功
var topicsInfo = data.data;
$("#topic_ids").empty();//清空下拉列表
var html = "<option value ='all'> all</option>";
$("#topic_ids").append(html);
for( var i in topicsInfo){
html = "<option value =" + topicsInfo[i].topic_id +"> " + topicsInfo[i].topic_name +"</option>"
$("#topic_ids").append(html);
}
}
},
error: function(data){
alert("获取日志主题失败!");
}
});
}
</script>
</html>