cpu.jsp
3.97 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
<%@ page import="java.lang.management.*,java.util.*"%>
<%@ page import="weaver.filter.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"%>
<%
java.text.DecimalFormat df = new java.text.DecimalFormat("##.#");
Map<String, Object> resp = MonitorXFilter.getFilterData("getALLCPUValues");
List<Map<String, Object>> data = resp == null ? new ArrayList<Map<String, Object>>() : (List<Map<String, Object>>) resp.get("result");
//List<CPUDataVO> data = MonitorXFilter.getFilterData("getALLCPUValues");
String action = request.getParameter("action");
if ("timePer".equals(action)) {
Collections.sort(data, new Comparator<Map<String, Object>>() {
public int compare(Map<String, Object> o1,
Map<String, Object> o2) {
long d1 = (Long)o1.get("timeSum") / (Long)o1.get("count");
long d2 = (Long)o2.get("timeSum") / (Long)o2.get("count");
if (d1 > d2) {
return -1;
} else if (d1 < d2) {
return 1;
} else {
return 0;
}
}
});
} else if ("clear".equals(action)) {
application.setAttribute("__cpu_lastcleartime", new java.text.SimpleDateFormat("yyyy'-'MM'-'dd' 'HH:mm:ss").format(new java.util.Date()));
MonitorXFilter.setFilterData("clearAllCPU", null);
%>
<script>location.href = "cpu.jsp";</script>
<%
} else if ("count".equals(action)) {
Collections.sort(data, new Comparator<Map<String, Object>>() {
public int compare(Map<String, Object> o1,
Map<String, Object> o2) {
long o1Count = (Long)o1.get("count");
long o2Count = (Long)o2.get("count");
if (o1Count > o2Count) {
return -1;
} else if (o1Count < o2Count) {
return 1;
} else {
return 0;
}
}
});
} else {
Collections.sort(data, new Comparator<Map<String, Object>>() {
public int compare(Map<String, Object> o1,
Map<String, Object> o2) {
float o1SumRatio = (Float)o1.get("sumRatio");
float o2SumRatio = (Float)o2.get("sumRatio");
if (o1SumRatio > o2SumRatio) {
return -1;
} else if (o1SumRatio < o2SumRatio) {
return 1;
} else {
return 0;
}
}
});
}
long sum = 0;
long sumCount = 0;
int dataLength = data.size();
for (int i = 0; i < dataLength; i++) {
sum += ((Long)data.get(i).get("timeSum") + (Long)data.get(i).get("excuteTime"));
sumCount += (Long)data.get(i).get("count");
}
long avgTime = (sumCount == 0 ? 0 : sum/sumCount);
long avgCount = (dataLength == 0 ? 0 : sumCount/dataLength);
%>
<a href="urltime.jsp">browse urltime.jsp</a>
<a href="cpu.jsp?action=clear" title="clear all expire data(not include running threads)">Clear</a>
<a href="cpu.jsp?action=timeSum">TimeRatio Sort</a>
<a href="cpu.jsp?action=count">Count Sort</a>
<a href="cpu.jsp?action=timePer">TimePer Sort</a>
<span title="every url count average">AVG COUNT = <%=avgCount%></span>
<span title="every request cpu average">AVG CPU = <%=avgTime%>ms</span>
<span>LAST CLEAR = <%=application.getAttribute("__cpu_lastcleartime")%></span>
<table border=1>
<tr>
<th>url</th>
<th>time sum(ms)</th>
<th>time ratio</th>
<th>count</th>
<th>time per(ms)</th>
<th>excuting..</th>
</tr>
<%
for (int i = 0; i < data.size() && i < 200; i++) {
%>
<tr>
<td><%=data.get(i).get("key")%></td>
<td><%=data.get(i).get("timeSum")%></td>
<td><%=df.format(data.get(i).get("sumRatio"))%>%</td>
<td><%=data.get(i).get("count")%></td>
<td><%=(Long)data.get(i).get("timeSum") / (Long)data.get(i).get("count")%></td>
<td><%=data.get(i).get("excuteTime")%></td>
</tr>
<%
}
%>
</table>