提交 9fa9196b 编写于 作者: Y You Yong

modify the cat problem jsp

上级 9424fc62
package com.dianping.cat.report.page.model.problem;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
......@@ -16,6 +18,7 @@ import com.dianping.cat.consumer.problem.model.transform.DefaultMerger;
import com.dianping.cat.report.page.model.spi.ModelRequest;
import com.dianping.cat.report.page.model.spi.ModelResponse;
import com.dianping.cat.report.page.model.spi.ModelService;
import com.site.helper.Splitters;
import com.site.lookup.annotation.Inject;
public class CompositeProblemService implements ModelService<ProblemReport>, Initializable {
......@@ -91,4 +94,49 @@ public class CompositeProblemService implements ModelService<ProblemReport>, Ini
public void setSerivces(ModelService<ProblemReport>... services) {
m_services = Arrays.asList(services);
}
/**
* Inject remote servers to load transaction model.
* <p>
*
* For example, servers: 192.168.1.1:2281,192.168.1.2,192.168.1.3
*
* @param servers
* server list separated by comma(',')
*/
public void setRemoteServers(String servers) {
List<String> endpoints = Splitters.by(',').split(servers);
String localAddress = null;
String localHost = null;
try {
localAddress = InetAddress.getLocalHost().getHostAddress();
localHost = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
// ignore it
}
for (String endpoint : endpoints) {
int pos = endpoint.indexOf(':');
String host = (pos > 0 ? endpoint.substring(0, pos) : endpoint);
int port = (pos > 0 ? Integer.parseInt(endpoint.substring(pos) + 1) : 2281);
if (port == 2281) {
if ("localhost".equals(host) || host.startsWith("127.0.")) {
// exclude localhost
continue;
} else if (host.equals(localAddress) || host.equals(localHost)) {
// exclude itself
continue;
}
}
RemoteProblemService remote = new RemoteProblemService();
remote.setHost(host);
remote.setPort(port);
m_services.add(remote);
}
}
}
package com.dianping.cat.report.page.problem;
public enum Action implements com.site.web.mvc.Action {
VIEW("view");
VIEW("view"),
DETAIL("detail");
private String m_name;
private Action(String name) {
......
package com.dianping.cat.report.page.problem;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
import com.dianping.cat.consumer.problem.model.entity.Entry;
import com.dianping.cat.consumer.problem.model.entity.JavaThread;
import com.dianping.cat.consumer.problem.model.entity.Machine;
import com.dianping.cat.consumer.problem.model.entity.ProblemReport;
......@@ -92,18 +96,51 @@ public class Handler implements PageHandler<Context> {
Model model = new Model(ctx);
Payload payload = ctx.getPayload();
model.setAction(Action.VIEW);
model.setAction(payload.getAction());
model.setPage(ReportPage.PROBLEM);
switch (payload.getAction()) {
case VIEW:
showSummary(model, payload);
break;
case DETAIL:
showDetail(model, payload);
}
m_jspViewer.view(ctx, model);
}
private void showDetail(Model model, Payload payload) {
ProblemReport report = getReport(payload);
Machine machine = report.getMachines().get(payload.getIpAddress());
JavaThread thread = machine.getThreads().get(payload.getThreadId());
Segment segment = thread.getSegments().get(payload.getMinute());
if (segment == null) {
model.setEntries(new ArrayList<Entry>());
model.setStatistics(new ArrayList<ProblemStatistics>());
return;
}
List<Entry> entries = segment.getEntries();
Map<String, ProblemStatistics> typeCounts = new HashMap<String, ProblemStatistics>();
for (Entry entry : entries) {
String type = entry.getType();
ProblemStatistics staticstics = typeCounts.get(type);
if (staticstics != null) {
staticstics.setCount(staticstics.getCount() + 1);
} else {
ProblemStatistics temp = new ProblemStatistics();
temp.setCount(1).setType(type);
typeCounts.put(type, temp);
}
}
model.setEntries(entries);
model.setStatistics(new ArrayList<ProblemStatistics>(typeCounts.values()));
}
private void showSummary(Model model, Payload payload) {
try {
ModelPeriod period = payload.getPeriod();
......
......@@ -3,6 +3,7 @@ package com.dianping.cat.report.page.problem;
public enum JspFile {
VIEW("/jsp/report/problem.jsp"),
DETAIL("jsp/report/problemDetail.jsp")
;
private String m_path;
......
......@@ -11,6 +11,8 @@ public class JspViewer extends BaseJspViewer<ReportPage, Action, Context, Model>
switch (action) {
case VIEW:
return JspFile.VIEW.getPath();
case DETAIL:
return JspFile.DETAIL.getPath();
}
throw new RuntimeException("Unknown action: " + action);
......
......@@ -2,7 +2,9 @@ package com.dianping.cat.report.page.problem;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import com.dianping.cat.consumer.problem.model.entity.Entry;
import com.dianping.cat.consumer.problem.model.entity.ProblemReport;
import com.dianping.cat.report.page.AbstractReportModel;
......@@ -14,6 +16,10 @@ public class Model extends AbstractReportModel<Action, Context> {
private String m_ipAddress;
private int m_hour;
private List<Entry> m_entries;
private List<ProblemStatistics> m_statistics;
public Model(Context ctx) {
super(ctx);
......@@ -73,4 +79,20 @@ public class Model extends AbstractReportModel<Action, Context> {
public void setIpAddress(String ipAddress) {
m_ipAddress = ipAddress;
}
public List<Entry> getEntries() {
return m_entries;
}
public void setEntries(List<Entry> entries) {
m_entries = entries;
}
public List<ProblemStatistics> getStatistics() {
return m_statistics;
}
public void setStatistics(List<ProblemStatistics> statistics) {
m_statistics = statistics;
}
}
......@@ -11,10 +11,13 @@ public class Payload extends AbstractReportPayload<Action> {
@FieldMeta("ip")
private String m_ipAddress;
@FieldMeta("thread")
private String m_threadId;
@FieldMeta("minute")
private int m_minute;
public Payload() {
super(ReportPage.PROBLEM);
}
......@@ -28,21 +31,30 @@ public class Payload extends AbstractReportPayload<Action> {
return m_ipAddress;
}
public int getMinute() {
return m_minute;
}
public String getThreadId() {
return m_threadId;
}
return m_threadId;
}
public void setAction(Action action) {
m_action = action;
public void setAction(String action) {
m_action = Action.getByName(action, Action.VIEW);
}
public void setIpAddress(String ipAddress) {
m_ipAddress = ipAddress;
}
public void setMinute(int minute) {
m_minute = minute;
}
public void setThreadId(String threadId) {
m_threadId = threadId;
}
m_threadId = threadId;
}
@Override
public void validate(ActionContext<?> ctx) {
if (m_action == null) {
......
package com.dianping.cat.report.page.problem;
public class ProblemStatistics {
private String m_type;
private int m_count;
public String getType() {
return m_type;
}
public ProblemStatistics setType(String type) {
m_type = type;
return this;
}
public int getCount() {
return m_count;
}
public ProblemStatistics setCount(int count) {
m_count = count;
return this;
}
}
......@@ -10,7 +10,7 @@ import com.dianping.cat.consumer.problem.model.entity.Segment;
/* used by problem.jsp */
public class ProblemReportHelper {
public static String showLegends(JavaThread thread, int minute) {
public static String showLegends(JavaThread thread, int minute, String domain, String ipAddress, long date) {
Segment segment = thread.findSegment(minute);
if (segment == null) {
......@@ -35,9 +35,15 @@ public class ProblemReportHelper {
if (messageId == null) {
sb.append("&nbsp;&nbsp;");
} else {
sb.append("<a href=\"/cat/r/m/").append(messageId).append("/logview.html\" class=\"");
sb.append(name);
sb.append("\">&nbsp;&nbsp;</a>");
sb.append("<a href=\"/cat/r/p?op=detail").append("&thread=").append(thread.getId());
sb.append("&domain=").append(domain);
sb.append("&ip=").append(ipAddress);
sb.append("&date=").append(date);
sb.append("&minute=").append(minute);
sb.append("\" class=\"").append(name).append("\">&nbsp;&nbsp;</a>");
//sb.append("<a href=\"/cat/r/m/").append(messageId).append("/logview.html\" class=\"");
//sb.append(name);
//sb.append("\">&nbsp;&nbsp;</a>");
}
}
......
......@@ -44,7 +44,7 @@
<description>show legends for problem summary report</description>
<name>showLegends</name>
<function-class>com.dianping.cat.report.view.ProblemReportHelper</function-class>
<function-signature>String showLegends(com.dianping.cat.consumer.problem.model.entity.JavaThread, int)</function-signature>
<example>${a:showLegends(thread,minute)}</example>
<function-signature>String showLegends(com.dianping.cat.consumer.problem.model.entity.JavaThread, int, java.lang.String, java.lang.String, long)</function-signature>
<example>${a:showLegends(thread, minute, domain, ip, date)}</example>
</function>
</taglib>
\ No newline at end of file
......@@ -39,7 +39,7 @@
<tr class="${minute%2==0 ? 'even' : 'odd'}">
<td>${w:format(model.hour,'00')}:${w:format(minute,'00')}</td>
<c:forEach var="thread" items="${threads}">
<td>${a:showLegends(thread.value, minute)}</td>
<td>${a:showLegends(thread.value, minute, model.domain, model.ipAddress, model.date)}</td>
</c:forEach>
</tr>
</c:forEach>
......
<%@ page contentType="text/html; charset=utf-8" %>
<%@ taglib prefix="a" uri="/WEB-INF/app.tld"%>
<%@ taglib prefix="w" uri="/web/core"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="res" uri="http://www.unidal.org/webres"%>
<jsp:useBean id="ctx" type="com.dianping.cat.report.page.problem.Context" scope="request"/>
<jsp:useBean id="payload" type="com.dianping.cat.report.page.problem.Payload" scope="request"/>
<jsp:useBean id="model" type="com.dianping.cat.report.page.problem.Model" scope="request"/>
<table>
<tr>
<th>Statistics</th>
<c:forEach var="item" items="${model.statistics}">
<td>${item.type} ${item.count}</td>
</c:forEach>
</tr>
</table>
<table >
<tr>
<th>Error</th>
<c:forEach var="entry" items="${model.entries}">
<td>${entry.messageId}</td>
</c:forEach>
</tr>
</table>
\ No newline at end of file
......@@ -102,7 +102,7 @@ public class TestServer extends SimpleServerSupport {
@Test
public void startServer() throws Exception {
// open the page in the default browser
s_adaptor.display("/cat/r");
//s_adaptor.display("/cat/r");
System.out.println(String.format("[%s] Press any key to stop server ... ", getTimestamp()));
System.in.read();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册