forked from tanglijiong/MyJavaStudio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache-admin.html
More file actions
230 lines (193 loc) · 6.77 KB
/
Copy pathcache-admin.html
File metadata and controls
230 lines (193 loc) · 6.77 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
<!DOCTYPE html>
<html>
<head>
<title>Cache Admin</title>
<meta name="content-type" content="text/html; charset=UTF-8">
<script src="./resources/js/jquery-2.1.4.js" charset="UTF-8" type="text/javascript"></script>
<link href="./resources/css/common.css" rel="stylesheet" />
<link href="./resources/css/table.css" rel="stylesheet" />
</head>
<body>
<div>
<div id="operations">
Cache列表:
<input type="button" value="刷新" onClick="refreshStatsAll();">
<input type="checkbox" id="autoRefresh" onClick="toggleAutoRefreshStats();"><label for="autoRefresh">自动刷新(3s)</label>
</div>
<div><pre id="response" class="attention"></pre></div>
<div><br><pre id="responseRawData" ></pre></div>
</div>
</body>
<script>
var autoRefreshInterval = 3000;
var autoRefershObject;
var requestStatsAll = {url : "/cache/admin/stats/all", params : "*", callback: requestStatsAllCallback};
$(function() {
refreshStatsAll();
});
function refreshStatsAll(){
ajaxRequest(requestStatsAll.url, requestStatsAll.params, requestStatsAll.callback);
}
function sizeStatistics(obj){
var c = "当前数据量/上限:" + obj.size + "/" + obj.maximumSize;
c += "\n历史最高数据量:" + obj.highestSize;
c += "\n最高数据量时间:" + obj.highestTime;
return c;
}
function hitStatistics(obj){
var c = "命中数量:" + obj.hitCount;
c += "\n命中比例:" + obj.hitRate;
c += "\n读库比例:" + obj.missRate;
return c;
}
function loadStatistics(obj){
var c = "成功加载数:" + obj.loadSuccessCount;
c += "\n失败加载数:" + obj.loadExceptionCount;
c += "\n总加载毫秒:" + obj.totalLoadTime;
return c;
}
function requestStatsAllCallback(jsonResult){
var html = "<table><tr><th>Cache名称</th> <th>数据量统计</th> <th>命中统计</th> <th>加载统计</th> <th>开始/重置时间</th> <th>操作</th> </tr>";
$.each(jsonResult.data, function(idx, obj){
html += "<tr><th>" + obj.cacheName + "</th>"
+ "<td>" + sizeStatistics(obj) + "</td>"
+ "<td>" + hitStatistics(obj) + "</td>"
+ "<td>" + loadStatistics(obj) + "</td>"
+ "<td>" + obj.resetTime +"\n\n失效时长:" + obj.survivalDuration + "(分钟)</td>"
+ "<td>"
+ "<a href='javascript:void(0)' onclick='resetCache(\""+obj.cacheName+"\");'>清空缓存</a>"
+ "\t<a href='javascript:void(0)' onclick='queryDataByPage(\""+obj.cacheName+"\");'>显示详情</a>"
+ "</td>"
+ "</tr>";
});
html += "</table>";
$("#response").html(html);
}
function resetCache(cacheName){
$.ajax({
type : "POST",
url : getRootPath()+"/cache/admin/reset",
dataType : "json", //表示返回值类型
data : {"cacheName":cacheName},
success : function(jsonResult){alert(jsonResult.message);refreshStatsAll();}
});
}
//定时刷新开关
function toggleAutoRefreshStats(){
if($("#autoRefresh").prop("checked")==true){
autoRefershObject = setInterval(refreshStatsAll, autoRefreshInterval);
}else{
clearInterval(autoRefershObject);
}
}
var pageParam = {pageNo : 1, pageSize : 10, cacheName : null};
function resetpageParam(){
pageParam.pageNo = 1;
pageParam.totalPage = 0;
}
function queryDataByPage(cacheName){
resetpageParam();
pageParam.cacheName = cacheName;
ajaxRequest("/cache/admin/queryDataByPage", pageParam, pageQueryCallback);
}
function pageQueryCallback(jsonResult){
pageParam.totalPage = jsonResult.totalPage;
var html = "<label class='highlight'>Cache名称:" + pageParam.cacheName + "</label><br/><br/>";
html += "<a href='javascript:void(0)' onclick='firstPage();'>首页 </a>\t";
html += "<a href='javascript:void(0)' onclick='previousPage();'>上一页 </a>\t";
html += "第<input type='number' id='pageNo' min='1' max='" + jsonResult.totalPage + "' value='" + jsonResult.pageNo + "' size='" + lengthOfNum(jsonResult.totalPage) + "' />页(共" + jsonResult.totalPage + "页)\t";
html += "<a href='javascript:void(0)' onclick='nextPage();'>下一页 </a>\t";
html += "<a href='javascript:void(0)' onclick='lastPage();'>末页</a>\t";
html += "<br/><br/>";
html += JSON.stringify(jsonResult.results[0], null, "\t");
$("#responseRawData").html(html);
$("#pageNo").blur(function(){
pn = $("#pageNo").val();
if(pn < 1){
pn = 1;
$("#pageNo").val(pn);
}else if(pn > pageParam.totalPage){
pn = pageParam.totalPage;
$("#pageNo").val(pn);
}
pageParam.pageNo=pn;
ajaxRequest("/cache/admin/queryDataByPage", pageParam, pageQueryCallback);
});
//回车
$("#pageNo").keyup(function(event){
if(event.which != 13){
return;
}
pn = $("#pageNo").val();
if(pn < 1){
pn = 1;
$("#pageNo").val(pn);
}else if(pn > pageParam.totalPage){
pn = pageParam.totalPage;
$("#pageNo").val(pn);
}
pageParam.pageNo=pn;
ajaxRequest("/cache/admin/queryDataByPage", pageParam, pageQueryCallback);
});
}
function firstPage(){
pageParam.pageNo=1;
ajaxRequest("/cache/admin/queryDataByPage", pageParam, pageQueryCallback);
}
function lastPage(){
pageParam.pageNo=pageParam.totalPage;
ajaxRequest("/cache/admin/queryDataByPage", pageParam, pageQueryCallback);
}
function nextPage(){
if(pageParam.pageNo==pageParam.totalPage){
alert("已经是最后一页了!");
return;
}
pageParam.pageNo++;
ajaxRequest("/cache/admin/queryDataByPage", pageParam, pageQueryCallback);
}
function previousPage(){
if(pageParam.pageNo==1){
alert("已经是第一页了!");
return;
}
pageParam.pageNo--;
ajaxRequest("/cache/admin/queryDataByPage", pageParam, pageQueryCallback);
}
//js获取项目根路径,如: http://localhost:8083/uimcardprj
function getRootPath() {
//获取当前网址,如: http://localhost:8083/uimcardprj/share/meun.jsp
var curWwwPath = window.document.location.href;
//获取主机地址之后的目录,如: uimcardprj/share/meun.jsp
var pathName = window.document.location.pathname;
var pos = curWwwPath.indexOf(pathName);
//获取主机地址,如: http://localhost:8083
var localhostPath = curWwwPath.substring(0, pos);
//获取带"/"的项目名,如:/uimcardprj
var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1);
return (localhostPath + projectName);
}
//发送ajax请求
function ajaxRequest(url, params, successCallback, contentType, errorCallback, async) {
var _async = async || true;
$.ajax({
type : "POST",
url : getRootPath() + url,
async : _async,
contentType : contentType,
dataType : "json", //表示返回值类型
data : params,
success : successCallback,
error : errorCallback
});
}
function lengthOfNum(num){
var length = 1;
var _num = num;
while((_num=_num/10) >= 1){
length++;
}
return length;
}
</script>
</html>