提交 769575a2 编写于 作者: L leon.li

finish alert monitor page backend job

上级 eba7012a
package com.dianping.cat.report.page.alert; package com.dianping.cat.report.page.alert;
public enum Action implements org.unidal.web.mvc.Action { public enum Action implements org.unidal.web.mvc.Action {
ALERT("alert"); ALERT("alert"),
VIEW("view");
private String m_name; private String m_name;
......
package com.dianping.cat.report.page.alert; package com.dianping.cat.report.page.alert;
import java.io.IOException; import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import org.unidal.dal.jdbc.DalException;
import org.unidal.lookup.annotation.Inject; import org.unidal.lookup.annotation.Inject;
import org.unidal.web.mvc.PageHandler; import org.unidal.web.mvc.PageHandler;
import org.unidal.web.mvc.annotation.InboundActionMeta; import org.unidal.web.mvc.annotation.InboundActionMeta;
import org.unidal.web.mvc.annotation.OutboundActionMeta; import org.unidal.web.mvc.annotation.OutboundActionMeta;
import org.unidal.web.mvc.annotation.PayloadMeta; import org.unidal.web.mvc.annotation.PayloadMeta;
import com.dianping.cat.Cat;
import com.dianping.cat.home.dal.report.Alert;
import com.dianping.cat.home.dal.report.AlertDao;
import com.dianping.cat.home.dal.report.AlertEntity;
import com.dianping.cat.report.ReportPage; import com.dianping.cat.report.ReportPage;
import com.dianping.cat.report.task.alert.sender.AlertChannel; import com.dianping.cat.report.task.alert.sender.AlertChannel;
import com.dianping.cat.report.task.alert.sender.AlertMessageEntity; import com.dianping.cat.report.task.alert.sender.AlertMessageEntity;
...@@ -24,6 +35,9 @@ public class Handler implements PageHandler<Context> { ...@@ -24,6 +35,9 @@ public class Handler implements PageHandler<Context> {
@Inject @Inject
private SenderManager m_senderManager; private SenderManager m_senderManager;
@Inject
private AlertDao m_alertDao;
@Override @Override
@PayloadMeta(Payload.class) @PayloadMeta(Payload.class)
@InboundActionMeta(name = "alert") @InboundActionMeta(name = "alert")
...@@ -59,9 +73,25 @@ public class Handler implements PageHandler<Context> { ...@@ -59,9 +73,25 @@ public class Handler implements PageHandler<Context> {
} }
} }
break; break;
case VIEW:
Date startTime = payload.getStartTime();
Date endTime = payload.getEndTime();
String domain = payload.getDomain();
String metric = payload.getMetric();
String level = payload.getLevel();
List<Alert> alerts;
try {
alerts = m_alertDao.queryAlertsByTimeDomainMetricType(startTime, endTime, domain, metric, level,
AlertEntity.READSET_FULL);
} catch (DalException e) {
alerts = new ArrayList<Alert>();
Cat.logError(e);
}
model.setAlerts(generateAlertMap(alerts));
break;
} }
model.setAction(Action.ALERT); model.setAction(action);
model.setPage(ReportPage.ALERT); model.setPage(ReportPage.ALERT);
if (!ctx.isProcessStopped()) { if (!ctx.isProcessStopped()) {
...@@ -69,7 +99,24 @@ public class Handler implements PageHandler<Context> { ...@@ -69,7 +99,24 @@ public class Handler implements PageHandler<Context> {
} }
} }
// private Map<String, List<Alert>> generateAlertMap(List<Alert> alerts) {
DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Map<String, List<Alert>> map = new LinkedHashMap<String, List<Alert>>();
for (Alert alert : alerts) {
String time = format.format(alert.getAlertTime());
List<Alert> alertsInMinute = map.get(time);
if (alertsInMinute == null) {
alertsInMinute = new ArrayList<Alert>();
map.put(time, alertsInMinute);
}
alertsInMinute.add(alert);
}
return map;
}
private void setAlertResult(Model model, int status) { private void setAlertResult(Model model, int status) {
switch (status) { switch (status) {
case 0: case 0:
......
...@@ -3,7 +3,7 @@ package com.dianping.cat.report.page.alert; ...@@ -3,7 +3,7 @@ package com.dianping.cat.report.page.alert;
public enum JspFile { public enum JspFile {
ALERT("/jsp/report/alert/alertResult.jsp"), ALERT("/jsp/report/alert/alertResult.jsp"),
; VIEW("/jsp/report/alert/alertView.jsp");
private String m_path; private String m_path;
......
...@@ -12,6 +12,8 @@ public class JspViewer extends BaseJspViewer<ReportPage, Action, Context, Model> ...@@ -12,6 +12,8 @@ public class JspViewer extends BaseJspViewer<ReportPage, Action, Context, Model>
switch (action) { switch (action) {
case ALERT: case ALERT:
return JspFile.ALERT.getPath(); return JspFile.ALERT.getPath();
case VIEW:
return JspFile.VIEW.getPath();
} }
throw new RuntimeException("Unknown action: " + action); throw new RuntimeException("Unknown action: " + action);
......
package com.dianping.cat.report.page.alert; package com.dianping.cat.report.page.alert;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.unidal.web.mvc.ViewModel; import org.unidal.web.mvc.ViewModel;
import com.dianping.cat.Constants;
import com.dianping.cat.home.dal.report.Alert;
import com.dianping.cat.report.ReportPage; import com.dianping.cat.report.ReportPage;
public class Model extends ViewModel<ReportPage, Action, Context> { public class Model extends ViewModel<ReportPage, Action, Context> {
private String m_alertResult; private String m_alertResult;
private Map<String, List<Alert>> m_alerts;
public Model(Context ctx) { public Model(Context ctx) {
super(ctx); super(ctx);
} }
...@@ -16,12 +24,32 @@ public class Model extends ViewModel<ReportPage, Action, Context> { ...@@ -16,12 +24,32 @@ public class Model extends ViewModel<ReportPage, Action, Context> {
return m_alertResult; return m_alertResult;
} }
public Map<String, List<Alert>> getAlerts() {
return m_alerts;
}
public String getDomain() {
return Constants.CAT;
}
public String getIpAddress() {
return null;
}
public Date getDate() {
return new Date();
}
@Override @Override
public Action getDefaultAction() { public Action getDefaultAction() {
return Action.ALERT; return Action.VIEW;
} }
public void setAlertResult(String alertResult) { public void setAlertResult(String alertResult) {
m_alertResult = alertResult; m_alertResult = alertResult;
} }
public void setAlerts(Map<String, List<Alert>> alerts) {
m_alerts = alerts;
}
} }
package com.dianping.cat.report.page.alert; package com.dianping.cat.report.page.alert;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.unidal.web.mvc.ActionContext; import org.unidal.web.mvc.ActionContext;
import org.unidal.web.mvc.ActionPayload; import org.unidal.web.mvc.ActionPayload;
import org.unidal.web.mvc.payload.annotation.FieldMeta; import org.unidal.web.mvc.payload.annotation.FieldMeta;
import com.dianping.cat.helper.TimeUtil;
import com.dianping.cat.report.ReportPage; import com.dianping.cat.report.ReportPage;
import com.site.lookup.util.StringUtils; import com.site.lookup.util.StringUtils;
...@@ -22,6 +27,21 @@ public class Payload implements ActionPayload<ReportPage, Action> { ...@@ -22,6 +27,21 @@ public class Payload implements ActionPayload<ReportPage, Action> {
@FieldMeta("group") @FieldMeta("group")
private String m_group; private String m_group;
@FieldMeta("domain")
private String m_domain;
@FieldMeta("level")
private String m_level;
@FieldMeta("metric")
private String m_metric;
@FieldMeta("startTime")
private String m_startTime;
@FieldMeta("endTime")
private String m_endTime;
@FieldMeta("type") @FieldMeta("type")
private String m_type; private String m_type;
...@@ -30,6 +50,11 @@ public class Payload implements ActionPayload<ReportPage, Action> { ...@@ -30,6 +50,11 @@ public class Payload implements ActionPayload<ReportPage, Action> {
@FieldMeta("receivers") @FieldMeta("receivers")
private String m_receivers; private String m_receivers;
@FieldMeta("reportType")
private String m_reportType = "";
private DateFormat m_format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
@Override @Override
public Action getAction() { public Action getAction() {
...@@ -52,6 +77,22 @@ public class Payload implements ActionPayload<ReportPage, Action> { ...@@ -52,6 +77,22 @@ public class Payload implements ActionPayload<ReportPage, Action> {
} }
} }
public String getDomain() {
if (StringUtils.isEmpty(m_domain)) {
return null;
} else {
return m_domain;
}
}
public Date getEndTime() {
try {
return m_format.parse(m_endTime);
} catch (Exception e) {
return new Date();
}
}
public String getGroup() { public String getGroup() {
if (StringUtils.isEmpty(m_group)) { if (StringUtils.isEmpty(m_group)) {
return "default"; return "default";
...@@ -60,6 +101,22 @@ public class Payload implements ActionPayload<ReportPage, Action> { ...@@ -60,6 +101,22 @@ public class Payload implements ActionPayload<ReportPage, Action> {
} }
} }
public String getLevel() {
if (StringUtils.isEmpty(m_level)) {
return null;
} else {
return m_level;
}
}
public String getMetric() {
if (StringUtils.isEmpty(m_metric)) {
return null;
} else {
return m_metric;
}
}
@Override @Override
public ReportPage getPage() { public ReportPage getPage() {
return m_page; return m_page;
...@@ -73,6 +130,18 @@ public class Payload implements ActionPayload<ReportPage, Action> { ...@@ -73,6 +130,18 @@ public class Payload implements ActionPayload<ReportPage, Action> {
} }
} }
public String getReportType() {
return m_reportType;
}
public Date getStartTime() {
try {
return m_format.parse(m_startTime);
} catch (Exception e) {
return new Date(System.currentTimeMillis() - TimeUtil.ONE_HOUR);
}
}
public String getTitle() { public String getTitle() {
if (StringUtils.isEmpty(m_title)) { if (StringUtils.isEmpty(m_title)) {
return ""; return "";
...@@ -90,7 +159,7 @@ public class Payload implements ActionPayload<ReportPage, Action> { ...@@ -90,7 +159,7 @@ public class Payload implements ActionPayload<ReportPage, Action> {
} }
public void setAction(String action) { public void setAction(String action) {
m_action = Action.getByName(action, Action.ALERT); m_action = Action.getByName(action, Action.VIEW);
} }
public void setChannel(String channel) { public void setChannel(String channel) {
...@@ -101,10 +170,26 @@ public class Payload implements ActionPayload<ReportPage, Action> { ...@@ -101,10 +170,26 @@ public class Payload implements ActionPayload<ReportPage, Action> {
m_content = content; m_content = content;
} }
public void setDomain(String domain) {
m_domain = domain;
}
public void setEndTime(String endTime) {
m_endTime = endTime;
}
public void setGroup(String group) { public void setGroup(String group) {
m_group = group; m_group = group;
} }
public void setLevel(String level) {
m_level = level;
}
public void setMetric(String metric) {
m_metric = metric;
}
@Override @Override
public void setPage(String page) { public void setPage(String page) {
m_page = ReportPage.getByName(page, ReportPage.ALERT); m_page = ReportPage.getByName(page, ReportPage.ALERT);
...@@ -114,6 +199,14 @@ public class Payload implements ActionPayload<ReportPage, Action> { ...@@ -114,6 +199,14 @@ public class Payload implements ActionPayload<ReportPage, Action> {
m_receivers = receivers; m_receivers = receivers;
} }
public void setReportType(String reportType) {
m_reportType = "";
}
public void setStartTime(String startTime) {
m_startTime = startTime;
}
public void setTitle(String title) { public void setTitle(String title) {
m_title = title; m_title = title;
} }
......
...@@ -6,6 +6,30 @@ ...@@ -6,6 +6,30 @@
<var name="end-time" value-type="Date" /> <var name="end-time" value-type="Date" />
<param name="domain" /> <param name="domain" />
<query-defs> <query-defs>
<query name="query-alerts-by-time-domain-metric-type" type="SELECT"
multiple="true">
<param name="start-time" />
<param name="end-time" />
<param name="domain" />
<param name="metric" />
<param name="type" />
<statement><![CDATA[
SELECT <FIELDS/>
FROM <TABLE/>
WHERE <FIELD name='alert-time'/> >= ${start-time}
AND <FIELD name='alert-time'/> <= ${end-time}
<IF type='NOT_NULL' field='domain'>
AND <FIELD name='domain'/> = ${domain}
</IF>
<IF type='NOT_NULL' field='metric'>
AND <FIELD name='metric'/> = ${metric}
</IF>
<IF type='NOT_NULL' field='type'>
AND <FIELD name='type'/> = ${type}
</IF>
ORDER BY <FIELD name='alert-time'/> desc
]]></statement>
</query>
<query name="query-alerts-by-time-category-domain" type="SELECT" <query name="query-alerts-by-time-category-domain" type="SELECT"
multiple="true"> multiple="true">
<param name="start-time" /> <param name="start-time" />
......
...@@ -4096,6 +4096,9 @@ ...@@ -4096,6 +4096,9 @@
<requirement> <requirement>
<role>com.dianping.cat.report.task.alert.sender.sender.SenderManager</role> <role>com.dianping.cat.report.task.alert.sender.sender.SenderManager</role>
</requirement> </requirement>
<requirement>
<role>com.dianping.cat.home.dal.report.AlertDao</role>
</requirement>
</requirements> </requirements>
</component> </component>
<component> <component>
......
...@@ -18,6 +18,10 @@ ...@@ -18,6 +18,10 @@
<name>report</name> <name>report</name>
<path>/WEB-INF/tags/hourlyReport.tag</path> <path>/WEB-INF/tags/hourlyReport.tag</path>
</tag-file> </tag-file>
<tag-file>
<name>navbar</name>
<path>/WEB-INF/tags/navbar.tag</path>
</tag-file>
<tag-file> <tag-file>
<name>noSwitchReport</name> <name>noSwitchReport</name>
<path>/WEB-INF/tags/noSwitchReport.tag</path> <path>/WEB-INF/tags/noSwitchReport.tag</path>
......
...@@ -47,6 +47,7 @@ ...@@ -47,6 +47,7 @@
<li><a style="padding:1px 30px" href="/cat/r/network?domain=${model.domain}&ip=${model.ipAddress}&date=${model.date}&reportType=${payload.reportType}&op=${payload.action.name}">网络监控</a></li> <li><a style="padding:1px 30px" href="/cat/r/network?domain=${model.domain}&ip=${model.ipAddress}&date=${model.date}&reportType=${payload.reportType}&op=${payload.action.name}">网络监控</a></li>
<li><a style="padding:1px 30px" href="/cat/r/system?domain=${model.domain}&ip=${model.ipAddress}&date=${model.date}&reportType=${payload.reportType}&op=${payload.action.name}">PAAS系统监控</a></li> <li><a style="padding:1px 30px" href="/cat/r/system?domain=${model.domain}&ip=${model.ipAddress}&date=${model.date}&reportType=${payload.reportType}&op=${payload.action.name}">PAAS系统监控</a></li>
<li><a style="padding:1px 30px" href="/cat/r/alteration?domain=${model.domain}&ip=${model.ipAddress}&date=${model.date}&reportType=${payload.reportType}&op=${payload.action.name}">线上变更监控</a></li> <li><a style="padding:1px 30px" href="/cat/r/alteration?domain=${model.domain}&ip=${model.ipAddress}&date=${model.date}&reportType=${payload.reportType}&op=${payload.action.name}">线上变更监控</a></li>
<li><a style="padding:1px 30px" href="/cat/r/alert?domain=${model.domain}&op=${payload.action.name}">告警信息监控</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
......
<%@ tag trimDirectiveWhitespaces="true" pageEncoding="UTF-8"%>
<%@ taglib prefix="a" uri="/WEB-INF/app.tld"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="w" uri="http://www.unidal.org/web/core"%>
<%@ taglib prefix="res" uri="http://www.unidal.org/webres"%>
<%@ attribute name="title"%>
<%@ attribute name="navUrlPrefix"%>
<%@ attribute name="timestamp"%>
<%@ attribute name="subtitle" fragment="true"%>
<a:body>
<div class="report">
<jsp:doBody />
</div>
</a:body>
\ No newline at end of file
<%@ page session="false" language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="a" uri="/WEB-INF/app.tld"%>
<%@ taglib prefix="w" uri="http://www.unidal.org/web/core"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="res" uri="http://www.unidal.org/webres"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<jsp:useBean id="ctx" type="com.dianping.cat.report.page.alert.Context" scope="request" />
<jsp:useBean id="payload" type="com.dianping.cat.report.page.alert.Payload" scope="request" />
<jsp:useBean id="model" type="com.dianping.cat.report.page.alert.Model" scope="request" />
<a:navbar title="AlertReport" navUrlPrefix="">
<jsp:body>
<table class="problem table table-striped table-bordered table-condensed table-hover">
<tr class="text-success">
<th width="10%">时间</th>
<th width="5%">类型</th>
<th width="5%">级别</th>
<th width="10%">项目</th>
<th width="10%">指标</th>
<th width="60%">内容</th>
</tr>
<c:forEach var="entry" items="${model.alerts}" varStatus="status">
<c:forEach var="alert" items="${entry.value}" varStatus="status">
<tr>
<c:if test="${status.first eq 'true'}">
<td rowspan="${fn:length(entry.value)}">${entry.key}</td>
</c:if>
<td class="aleration_${alert.category}">${alert.category}</td>
<td class="aleration_${alert.category}">${alert.type}</td>
<td class="aleration_${alert.category}">${alert.domain}</td>
<td class="aleration_${alert.category}">${alert.metric}</td>
<td class="aleration_${alert.category}">${alert.content}</td>
</tr>
</c:forEach>
</c:forEach>
</table>
</jsp:body>
</a:navbar>
\ No newline at end of file
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
<jsp:useBean id="payload" type="com.dianping.cat.report.page.alteration.Payload" scope="request" /> <jsp:useBean id="payload" type="com.dianping.cat.report.page.alteration.Payload" scope="request" />
<jsp:useBean id="model" type="com.dianping.cat.report.page.alteration.Model" scope="request" /> <jsp:useBean id="model" type="com.dianping.cat.report.page.alteration.Model" scope="request" />
<a:report title="Alteration Report" navUrlPrefix=""> <a:navbar title="Alteration Report" navUrlPrefix="">
<jsp:body> <jsp:body>
<%@ include file="alter_query.jsp"%> <%@ include file="alter_query.jsp"%>
<table class="problem table table-striped table-bordered table-condensed table-hover"> <table class="problem table table-striped table-bordered table-condensed table-hover">
...@@ -41,7 +41,6 @@ ...@@ -41,7 +41,6 @@
</table> </table>
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
$(".header").hide();
$('i[tips]').popover(); $('i[tips]').popover();
$('.hreftip').tooltip({container:'body', html:true, delay:{show:0, hide:0}}); $('.hreftip').tooltip({container:'body', html:true, delay:{show:0, hide:0}});
...@@ -101,4 +100,4 @@ ...@@ -101,4 +100,4 @@
</script> </script>
</jsp:body> </jsp:body>
</a:report> </a:navbar>
\ No newline at end of file \ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册