rabbit.js
11.3 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
$(
initRabbitSelect()
);
function updateOverView(moId) {
$.ajax({
url: contextPath + "rabbitmq/overview",
type: "post",
dataType: "json",
data: {
moId: moId
},
success: function (response) {
updateOverview(response);
},
error: function (e) {
}
});
}
function updateOverview(response) {
var div = document.getElementById("overviewDiv");
div.innerHTML = "";
var connections = $("<div>").addClass("micro-highlight").html("Connections:").appendTo(div);
var conValue = $("<strong>").html(response.data.connections).appendTo(connections);
var channels = $("<div>").addClass("micro-highlight").html("Channels:").appendTo(div);
var chaValue = $("<strong>").html(response.data.channels).appendTo(channels);
var exchanges = $("<div>").addClass("micro-highlight").html("Exchanges:").appendTo(div);
var excValue = $("<strong>").html(response.data.exchanges).appendTo(exchanges);
var Queues = $("<div>").addClass("micro-highlight").html("Queues:").appendTo(div);
var quevalue = $("<strong>").html(response.data.queues).appendTo(Queues);
var consumers = $("<div>").addClass("micro-highlight").html("Consumers:").appendTo(div);
var consValue = $("<strong>").html(response.data.consumers).appendTo(consumers);
var Messages_Ready = $("<div>").addClass("micro-highlight").html("Message_Ready:").appendTo(div);
var readyValue = $("<strong>").html(response.data.messages_ready).appendTo(Messages_Ready);
var Messages_unack = $("<div>").addClass("micro-highlight").html("Message_Unack:").appendTo(div);
var unValue = $("<strong>").html(response.data.messages_unack).appendTo(Messages_unack);
var Messages_total = $("<div>").addClass("micro-highlight").html("Message_Total:").appendTo(div);
var totValue = $("<strong>").html(response.data.messages).appendTo(Messages_total);
}
function updateClusterView(moId) {
$("#clusterViewTable").table(
{
url: contextPath + "rabbitmq/clusterView",
queryParams: {
moId: moId
}, //调用url传递的参数
method: "POST",
striped: true,
panelClass: "panel-success",
pagination: true,
pageSize: 5,
loadFilter: function (data) {
return defaultLoadFilter(data);
},
columns: [{
title: "Name",
formatter: function (value, rowData) {
/*alert(rowData.name);*/
var div = $("<div align='center'>").html(rowData.name);
return div;
}
},
{
title: "File descriptors",
formatter: function (value, rowData) {
var div = $("<div style='width: 240px;'>").addClass("status-bar");
var nameDiv = $("<div style='margin-bottom: 5px;background-repeat: no-repeat;'>")
.addClass("status-bar-main green")
.html(rowData.fd_used);
var nameAvliable = $("<sub>").html(rowData.fd_total + " vailable");
div.append(nameDiv);
div.append(nameAvliable);
return div;
}
},
{
title: "Socket descriptors",
formatter: function (value, rowData) {
var div = $("<div style='width: 240px;'>").addClass("status-bar");
var nameDiv = $("<div style='margin-bottom: 5px;background-repeat: no-repeat;'>")
.addClass("status-bar-main green")
.html(rowData.sockets_used);
var nameAvliable = $("<sub>").html(rowData.sockets_total + " available");
div.append(nameDiv);
div.append(nameAvliable);
return div;
}
},
{
title: "Erlang processes",
formatter: function (value, rowData) {
var div = $("<div style='width: 240px;'>").addClass("status-bar");
var nameDiv = $("<div style='margin-bottom: 5px;background-repeat: no-repeat;'>")
.addClass("status-bar-main green")
.html(rowData.proc_used);
var nameAvliable = $("<sub>").html(rowData.proc_used + " available");
div.append(nameDiv);
div.append(nameAvliable);
return div;
}
},
{
title: "Memory",
formatter: function (value, rowData) {
var div = $("<div style='width: 240px;'>").addClass("status-bar");
var nameDiv = $("<div style='margin-bottom: 5px;background-repeat: no-repeat;'>")
.addClass("status-bar-main green")
.html(rowData.mem_used);
var nameAvliable = $("<sub>").html(rowData.mem_limit + " vailable");
div.append(nameDiv);
div.append(nameAvliable);
return div;
}
},
{
title: "Disk space",
formatter: function (value, rowData) {
var div = $("<div style='width: 240px;'>").addClass("status-bar");
var nameDiv = $("<div style='margin-bottom: 5px;background-repeat: no-repeat;'>")
.addClass("status-bar-main green")
.html(rowData.disk_free);
var nameAvliable = $("<sub>").html(rowData.disk_free_limit + " available");
div.append(nameDiv);
div.append(nameAvliable);
return div;
}
}
]
});
}
function updateQueuesView(moId) {
$("#queueViewTable").table(
{
url: contextPath + "rabbitmq/queueView",
method: "POST",
queryParams: {
moId: moId
}, //调用url传递的参数
striped: true,
panelClass: "panel-success",
pagination: true,
pageSize: 5,
loadFilter: function (data) {
return defaultLoadFilter(data);
},
columns: [{
title: "Virtual host",
formatter: function (value, rowData) {
/*alert(rowData.name);*/
var div = $("<div align='center'>").html(rowData.vhost);
return div;
}
}, {
title: "Name",
formatter: function (value, rowData) {
/*alert(rowData.name);*/
var div = $("<div align='center'>").html(rowData.name);
return div;
}
}, {
title: "State",
formatter: function (value, rowData) {
/*alert(rowData.name);*/
var div = $("<div align='center'>").html(rowData.state);
return div;
}
}, {
title: "Messages_Ready",
formatter: function (value, rowData) {
/*alert(rowData.name);*/
var div = $("<div align='center'>").html(rowData.messages_ready);
return div;
}
}, {
title: "Messages_Unack",
formatter: function (value, rowData) {
/*alert(rowData.name);*/
var div = $("<div align='center'>").html(rowData.messages_unacknowledged);
return div;
}
}, {
title: "Messages_Total",
formatter: function (value, rowData) {
/*alert(rowData.name);*/
var div = $("<div align='center'>").html(rowData.messages);
return div;
}
},
{
title: "Alert_High_Watermark",
formatter: function (value, rowData, rowIndex) {
/*alert(rowData.name);*/
var div = $("<div>");
var input = $("<input type='text' id='msg_alert_high_" + rowIndex + "' class='form-control' style='width: 120px;' height='50%'>");
input.val(rowData.alert_high);
var submit = $("<button >").addClass("btn btn-xs btn-danger").html("设置");
submit.click(function () {
fixAlertHigh(rowData, rowIndex);
});
div.append(input);
div.append(" ");
div.append(" ");
div.append(" ");
div.append(submit);
return div;
}
}
]
}
)
}
function fixAlertHigh(rowData, rowIndex) {
/* alert(rowIndex);
alert(rowData.name);
alert($("#msg_alert_high_" + rowIndex + "").val());*/
$.ajax({
url: contextPath + "rabbitmq/fixAlertHigh",
type: "post",
dataType: "json",
data: {
moId: $('#rabbitMqSelected option:selected').val(),
queueName: rowData.name,
alertHigh: $("#msg_alert_high_" + rowIndex + "").val()
}
})
}
function initRabbitSelect() {
$.ajax({
url: contextPath + "rabbitmq/allRabbitMq",
type: "post",
dataType: "json",
success: function (response) {
//将查询到的数据,update到选择框中
genarateRabbitSelectOption(response.data);
updateOverView((response.data)[0].moId);
updateClusterView((response.data)[0].moId);
updateQueuesView((response.data)[0].moId);
},
error: function (e) {
}
})
}
function genarateRabbitSelectOption(optionList) {
var innerHTML = "<select id='rabbitMqSelected' class='form-control' style='width:50%; height: 20%; margin-left: 20%' onchange='rabbitUpdateSelectOnChange()'>";
for (var i = 0; i < optionList.length; i++) {
innerHTML += "<option value='" + optionList[i].moId + "'>" + optionList[i].moName + "</option>";
}
innerHTML += "</select>";
console.log(document.getElementById("selectRabbitDiv"));
document.getElementById("selectRabbitDiv").innerHTML = innerHTML;
document.getElementById("selectRabbitDiv").value = optionList[0].moName;
}
/**
* 主机组选择框选中属性发生变化时,则异步查询当前主机组号下的ip列表,并且刷新ip列表
*/
function rabbitUpdateSelectOnChange() {
var rabbitId = $('#rabbitMqSelected option:selected').val().replace(/\'/g, '\"');
updateOverView(rabbitId);
$("#clusterViewTable").table("load", {
'moId': rabbitId
});
$("#queueViewTable").table("load", {
'moId': rabbitId
});
}