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

finish alert monitor page backend job

上级 eba7012a
package com.dianping.cat.report.page.alert;
public enum Action implements org.unidal.web.mvc.Action {
ALERT("alert");
ALERT("alert"),
VIEW("view");
private String m_name;
......
package com.dianping.cat.report.page.alert;
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.Map;
import javax.servlet.ServletException;
import org.unidal.dal.jdbc.DalException;
import org.unidal.lookup.annotation.Inject;
import org.unidal.web.mvc.PageHandler;
import org.unidal.web.mvc.annotation.InboundActionMeta;
import org.unidal.web.mvc.annotation.OutboundActionMeta;
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.task.alert.sender.AlertChannel;
import com.dianping.cat.report.task.alert.sender.AlertMessageEntity;
......@@ -24,6 +35,9 @@ public class Handler implements PageHandler<Context> {
@Inject
private SenderManager m_senderManager;
@Inject
private AlertDao m_alertDao;
@Override
@PayloadMeta(Payload.class)
@InboundActionMeta(name = "alert")
......@@ -59,9 +73,25 @@ public class Handler implements PageHandler<Context> {
}
}
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);
if (!ctx.isProcessStopped()) {
......@@ -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) {
switch (status) {
case 0:
......
......@@ -3,7 +3,7 @@ package com.dianping.cat.report.page.alert;
public enum JspFile {
ALERT("/jsp/report/alert/alertResult.jsp"),
;
VIEW("/jsp/report/alert/alertView.jsp");
private String m_path;
......
......@@ -12,6 +12,8 @@ public class JspViewer extends BaseJspViewer<ReportPage, Action, Context, Model>
switch (action) {
case ALERT:
return JspFile.ALERT.getPath();
case VIEW:
return JspFile.VIEW.getPath();
}
throw new RuntimeException("Unknown action: " + action);
......
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 com.dianping.cat.Constants;
import com.dianping.cat.home.dal.report.Alert;
import com.dianping.cat.report.ReportPage;
public class Model extends ViewModel<ReportPage, Action, Context> {
private String m_alertResult;
private Map<String, List<Alert>> m_alerts;
public Model(Context ctx) {
super(ctx);
}
......@@ -16,12 +24,32 @@ public class Model extends ViewModel<ReportPage, Action, Context> {
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
public Action getDefaultAction() {
return Action.ALERT;
return Action.VIEW;
}
public void setAlertResult(String alertResult) {
m_alertResult = alertResult;
}
public void setAlerts(Map<String, List<Alert>> alerts) {
m_alerts = alerts;
}
}
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.ActionPayload;
import org.unidal.web.mvc.payload.annotation.FieldMeta;
import com.dianping.cat.helper.TimeUtil;
import com.dianping.cat.report.ReportPage;
import com.site.lookup.util.StringUtils;
......@@ -22,6 +27,21 @@ public class Payload implements ActionPayload<ReportPage, Action> {
@FieldMeta("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")
private String m_type;
......@@ -30,6 +50,11 @@ public class Payload implements ActionPayload<ReportPage, Action> {
@FieldMeta("receivers")
private String m_receivers;
@FieldMeta("reportType")
private String m_reportType = "";
private DateFormat m_format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
@Override
public Action getAction() {
......@@ -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() {
if (StringUtils.isEmpty(m_group)) {
return "default";
......@@ -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
public ReportPage getPage() {
return m_page;
......@@ -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() {
if (StringUtils.isEmpty(m_title)) {
return "";
......@@ -90,7 +159,7 @@ public class Payload implements ActionPayload<ReportPage, 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) {
......@@ -101,10 +170,26 @@ public class Payload implements ActionPayload<ReportPage, Action> {
m_content = content;
}
public void setDomain(String domain) {
m_domain = domain;
}
public void setEndTime(String endTime) {
m_endTime = endTime;
}
public void setGroup(String group) {
m_group = group;
}
public void setLevel(String level) {
m_level = level;
}
public void setMetric(String metric) {
m_metric = metric;
}
@Override
public void setPage(String page) {
m_page = ReportPage.getByName(page, ReportPage.ALERT);
......@@ -114,6 +199,14 @@ public class Payload implements ActionPayload<ReportPage, Action> {
m_receivers = receivers;
}
public void setReportType(String reportType) {
m_reportType = "";
}
public void setStartTime(String startTime) {
m_startTime = startTime;
}
public void setTitle(String title) {
m_title = title;
}
......
......@@ -6,6 +6,30 @@
<var name="end-time" value-type="Date" />
<param name="domain" />
<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"
multiple="true">
<param name="start-time" />
......
......@@ -4096,6 +4096,9 @@
<requirement>
<role>com.dianping.cat.report.task.alert.sender.sender.SenderManager</role>
</requirement>
<requirement>
<role>com.dianping.cat.home.dal.report.AlertDao</role>
</requirement>
</requirements>
</component>
<component>
......
......@@ -18,6 +18,10 @@
<name>report</name>
<path>/WEB-INF/tags/hourlyReport.tag</path>
</tag-file>
<tag-file>
<name>navbar</name>
<path>/WEB-INF/tags/navbar.tag</path>
</tag-file>
<tag-file>
<name>noSwitchReport</name>
<path>/WEB-INF/tags/noSwitchReport.tag</path>
......
......@@ -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/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/alert?domain=${model.domain}&op=${payload.action.name}">告警信息监控</a></li>
</ul>
</li>
</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 @@
<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" />
<a:report title="Alteration Report" navUrlPrefix="">
<a:navbar title="Alteration Report" navUrlPrefix="">
<jsp:body>
<%@ include file="alter_query.jsp"%>
<table class="problem table table-striped table-bordered table-condensed table-hover">
......@@ -41,7 +41,6 @@
</table>
<script type="text/javascript">
$(document).ready(function() {
$(".header").hide();
$('i[tips]').popover();
$('.hreftip').tooltip({container:'body', html:true, delay:{show:0, hide:0}});
......@@ -101,4 +100,4 @@
</script>
</jsp:body>
</a:report>
\ No newline at end of file
</a:navbar>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册