monit.jsp
16.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
<%@page language="java" contentType="text/html;charset=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/jstree/themes/proton/style.css"/>
<link rel="stylesheet" href="<%=basePath %>css/select2.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/jstree/jstree.min.js"></script>
<script src="<%=basePath %>js/jquery.toaster.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">Monit</a>
</div>
<div class="container-fluid">
<div class="widget-box">
<div class="widget-title">
<h5>Monit信息查询</h5>
</div>
<div class="widget-content nopadding">
<div class="widget-title" style="height: 53px;">
<div>
<div class="form-inline" role="form" id="inBoxQueryDiv"
style=" margin-top: 12px;margin-left: 25px;float: left;">
<div class="input-group" style="float: left; margin-left: 20px">
<span class="input-group-addon">IP:</span>
<input type="text" id="hostIp" name="hostIp" class="form-control" placeholder=""/>
</div>
<div class="input-group" style="float: left;margin-left: 20px">
<span class="input-group-addon">标签:</span>
<input type="text" id="tag" name="hostIp" class="form-control" placeholder=""/>
</div>
<button id="searchHostInfoBtn" class="btn btn-primary" style="margin-left: 18px;">搜索
</button>
</div>
</div>
</div>
<div id="monitorTable">
</div>
</div>
</div>
</div>
<div class="modal fade" id="serviceModal" tabindex="-1" role="dialog" aria-labelledby="serviceModalLable"
aria-hidden="true"
style="height: 1000px;overflow :auto">
<div class="modal-dialog" style="width: 1500px">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"
aria-hidden="true">×</button>
<h4 class="modal-title" id="serviceModalTitle"></h4>
</div>
<div class="modal-body">
<div id="body_div">
<div class="blanksegmentation"></div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">关闭</button>
</div>
</div>
<!-- /.modal-content -->
</div>
<!-- /.modal -->
</div>
</div>
</div>
<script src="<%=basePath %>script/common/genarate_left_panel.js?v=<%=ProjectConstant.MENU_VERSION %>"></script>
<script>
$("#li_monitor").addClass("active open");
$("#li_monit").addClass("active");
</script>
<script>
//加载页面 初始化页面
$(
queryAllMonitorService()
);
//设置定时器,一分钟刷新一次页面
/*timename = setInterval("queryAllMonitorService();", 60 * 1000);*/
//查询monitor所有服务信息,并且刷新页面展示
function queryAllMonitorService() {
$("#monitorTable").table(
{
url: contextPath + "/monit/service/allMonit",
method: 'post',
dataType: 'json',
data: {},
striped: true,
panelClass: "panel-success",
loadFilter: function (data) {
console.log(data.data)
return defaultLoadFilter(data);
},
columns: [
{
title: "IP",
field: "ip"
},
{
title: "标签",
field: "tags"
},
{
title: "详情",
formatter: function (value, rowData, rowIndex) {
var div = $("<div>");
//详情
var editBtn = $("<button data-target='#updateModal' data-toggle='modal'>").addClass("btn btn-xs btn-success").html("详情").appendTo(div);
editBtn.click(function () {
searchService(rowData.monitId);
});
return div;
}
}
]
}
);
}
function searchService(monitId) {
$.ajax({
url: contextPath + '/monit/service/searchService',
type: 'POST',
dataType: 'json',
data: {
monitorId: monitId
},
success: function (resp) {
console.log("search rep:" + resp);
genarateMonitorDashboard(resp.data);
$("#serviceModalTitle").text("Monit 详情");
$("#serviceModal").modal('show');
},
error: function (e) {
localAlert("查询失败", "查询失败,请稍后再试:" + e.data);
$("#serviceModal").modal("hide");
$("#monitorTable").table("load");
}
});
}
$("#searchHostInfoBtn").click(
function () {
var ip = $("#hostIp").val();
var tag = $("#tag").val();
$("#monitorTable").table("load", {
query: ip + ";" + tag
});
}
);
//生成monitor dashboard展示页面
function genarateMonitorDashboard(data) {
var innerHTML = "";
var info = data;
console.log("monitorId: " + info.monitorId);
innerHTML += "<div class='blanksegmentation'></div>";
innerHTML += "<div class='panel panel-default'>";
//genarate panel header httpInfo
innerHTML += genarateHttpInfoDiv(info.httpInfo, info.monitorId);
//genarate panel body serviceInfos events
innerHTML += genarateServiceInfosTables(info.servicesInfo, info.eventsInfo, info.monitorId);
innerHTML += "</div>";
document.getElementById("body_div").innerHTML = innerHTML;
}
//HttpInfo panel header
function genarateHttpInfoDiv(httpInfo, monitorId) {
console.log("httpInfo: " + httpInfo);
var innerHTML = "<div class='panel-heading'>";
innerHTML += genarateSpanText("address: " + httpInfo.address, 20);
innerHTML += genarateSpanText("port: " + httpInfo.port, 20);
innerHTML += genarateSpanText("ssl: " + httpInfo.ssl, 20);
innerHTML += "<a href=\"javascript:deleteBtnOnClicked(\'" + monitorId + "\')\"><span class='glyphicon glyphicon-trash' style='color: #FF0000;font-size:18px'></span></a>";
innerHTML += " ";
innerHTML += "<a href=\"javascript:updateBtnOnClicked(\'" + monitorId + "\')\"><span class='glyphicon glyphicon-upload' style='color: #52ff90;font-size:18px'></span></a>";
innerHTML += "</div>";
return innerHTML;
}
//serviceInfos Table events Table
function genarateServiceInfosTables(serviceInfos, events, monitorId) {
var innerHTML = "<div class='panel-body'>";
//genarate serviceInfo table<th>
innerHTML += "<table class='table table-bordered mb30'>";
innerHTML += "<thead><tr><th style='width: 25%;'>serviceName</th><th style='width: 20%;'>serviceStatus</th><th style='width: 10%;'>system</th>";
innerHTML += "<th style='width: 15%;'>start</th><th style='width: 15%;'>stop</th><th style='width: 15%;'>restart</th></tr></thead><tbody>";
//genarate serviceInfo table<tr>
for (var i in serviceInfos) {
var service = serviceInfos[i];
innerHTML += "<tr>"
innerHTML += "<td>" + service.serviceName + "</td>";
//status == NORMAL status font turn green, start button unclickable, and the others potition, turn red stop button unclickable
if (serviceInfos[i].serviceStatus == "NORMAL") {
innerHTML += "<td style='color:#008000;font-weight:bold'>" + service.serviceStatus + "</td>";
innerHTML += "<td>" + service.system + "</td>";
innerHTML += "<td><button class='btn btn-success btn-rounded' onclick=\"actionBtnOnClicked('" + monitorId + "','" + service.serviceName + "', 'start')\">Start</button></td>";
innerHTML += "<td><button class='btn btn-danger btn-rounded' onclick=\"actionBtnOnClicked('" + monitorId + "','" + service.serviceName + "', 'stop')\">Stop</button></td>";
innerHTML += "<td><button class='btn btn-success btn-rounded' onclick=\"actionBtnOnClicked('" + monitorId + "','" + service.serviceName + "', 'restart')\">Restart</button></td>";
} else {
innerHTML += "<td style='color:#FF0000;font-weight:bold'>" + serviceInfos[i].serviceStatus + "</td>";
innerHTML += "<td>" + serviceInfos[i].system + "</td>";
innerHTML += "<td><button class='btn btn-success btn-rounded' onclick=\"actionBtnOnClicked('" + monitorId + "','" + service.serviceName + "', 'start')\">Start</button></td>";
innerHTML += "<td><button class='btn btn-danger btn-rounded' onclick=\"actionBtnOnClicked('" + monitorId + "','" + service.serviceName + "', 'stop')\">Stop</button></td>";
innerHTML += "<td><button class='btn btn-success btn-rounded' onclick=\"actionBtnOnClicked('" + monitorId + "','" + service.serviceName + "', 'restart')\">Restart</button></td>";
}
innerHTML += "</tr>";
}
innerHTML += "</tbody></table>";
//genarate events table<th>
innerHTML += "<table class='table table-bordered mb30'>";
innerHTML += "<thead><tr><th>collected_sec</th><th>service</th><th>type</th>";
innerHTML += "<th>message</th></tr></thead><tbody>";
for (var i in events) {
var event = events[i];
innerHTML += "<tr>"
innerHTML += "<td>" + event.collected_sec + "</td>";
innerHTML += "<td>" + event.service + "</td>";
innerHTML += "<td>" + event.type + "</td>";
innerHTML += "<td>" + event.message + "</td>";
innerHTML += "</tr>";
}
innerHTML += "</tbody></table>"
innerHTML += "</div>";
return innerHTML;
}
//生成data的json字符串
function buildBody(monitorId, serviceName, actionType) {
var actionItem = new Object();
actionItem['hostId'] = monitorId;
actionItem['service'] = serviceName;
actionItem['action'] = actionType;
var actions = new Array();
actions.push(actionItem);
var body = new Object();
body['actions'] = actions;
return JSON.stringify(body);
}
//启停按钮的动作方法
function actionBtnOnClicked(monitorId, serviceName, actionType) {
var body = buildBody(monitorId, serviceName, actionType);
console.log(body);
if (actionType == "delete") {
deleteBtnOnClicked(monitorId);
return;
}
$.ajax({
"url": "/monit/hosts/oneAction",
"type": 'POST',
"dataType": "json",
"data": {
hostId: monitorId,
service: serviceName,
action: actionType
},
success: function (resp) {
searchService(monitorId);
},
error: function (e) {
$("#serviceModal").modal("hide");
queryAllMonitorService();
}
});
}
//delete按钮的动作方法
function deleteBtnOnClicked(monitorId) {
var url = "/monit/hosts/delete/" + monitorId;
console.log(url)
$.ajax({
"url": url,
"type": 'POST',
"dataType": "json",
success: function (data) {
$("#serviceModal").modal("hide");
queryAllMonitorService();
},
error: function (e) {
$("#serviceModal").modal("hide");
queryAllMonitorService();
}
});
}
//delete按钮的动作方法
function updateBtnOnClicked(monitorId) {
searchService(monitorId);
}
function genarateSpanText(text, size) {
return "<span style='font-size:" + size + "px;margin-right:20px'>" + text + "</span>";
}
</script>
</body>
</html>