提交 73a67925 编写于 作者: J jialinsun

js monitor alert

上级 1ad42d49
......@@ -7,7 +7,7 @@
<entity name="aggregation-rule">
<attribute name="pattern" value-type="String" key="true"/>
<attribute name="type" value-type="int" primitive="true"/>
<attribute name="warn" value-type="int" primitive="true"/>
<attribute name="warn" value-type="int" primitive="true" default-value="200"/>
<attribute name="mails" value-type="String" />
<attribute name="domain" value-type="String" />
<attribute name="sample" value-type="String" />
......
......@@ -71,6 +71,7 @@ import com.dianping.cat.report.task.alert.sender.decorator.BusinessDecorator;
import com.dianping.cat.report.task.alert.sender.decorator.Decorator;
import com.dianping.cat.report.task.alert.sender.decorator.DecoratorManager;
import com.dianping.cat.report.task.alert.sender.decorator.ExceptionDecorator;
import com.dianping.cat.report.task.alert.sender.decorator.FrontEndExceptionDecorator;
import com.dianping.cat.report.task.alert.sender.decorator.NetworkDecorator;
import com.dianping.cat.report.task.alert.sender.decorator.SystemDecorator;
import com.dianping.cat.report.task.alert.sender.decorator.ThirdpartyDecorator;
......@@ -78,6 +79,7 @@ import com.dianping.cat.report.task.alert.sender.receiver.BusinessContactor;
import com.dianping.cat.report.task.alert.sender.receiver.Contactor;
import com.dianping.cat.report.task.alert.sender.receiver.ContactorManager;
import com.dianping.cat.report.task.alert.sender.receiver.ExceptionContactor;
import com.dianping.cat.report.task.alert.sender.receiver.FrontEndExceptionContactor;
import com.dianping.cat.report.task.alert.sender.receiver.NetworkContactor;
import com.dianping.cat.report.task.alert.sender.receiver.SystemContactor;
import com.dianping.cat.report.task.alert.sender.receiver.ThirdpartyContactor;
......@@ -148,11 +150,15 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all.add(C(Contactor.class, ThirdpartyContactor.ID, ThirdpartyContactor.class).req(ProjectDao.class,
AlertConfigManager.class));
all.add(C(Contactor.class, FrontEndExceptionContactor.ID, FrontEndExceptionContactor.class).req(
AggregationConfigManager.class));
all.add(C(ContactorManager.class).req(Contactor.class, BusinessContactor.ID, "businessContactor")
.req(Contactor.class, NetworkContactor.ID, "networkContactor")
.req(Contactor.class, SystemContactor.ID, "exceptionContactor")
.req(Contactor.class, ExceptionContactor.ID, "systemContactor")
.req(Contactor.class, ThirdpartyContactor.ID, "thirdpartyContactor"));
.req(Contactor.class, ThirdpartyContactor.ID, "thirdpartyContactor")
.req(Contactor.class, FrontEndExceptionContactor.ID, "frontEndExceptionContactor"));
all.add(C(Decorator.class, BusinessDecorator.ID, BusinessDecorator.class).req(ProjectDao.class));
......@@ -164,11 +170,14 @@ public class ComponentsConfigurator extends AbstractResourceConfigurator {
all.add(C(Decorator.class, ThirdpartyDecorator.ID, ThirdpartyDecorator.class).req(ProjectDao.class));
all.add(C(Decorator.class, FrontEndExceptionDecorator.ID, FrontEndExceptionDecorator.class));
all.add(C(DecoratorManager.class).req(Decorator.class, BusinessDecorator.ID, "businessDecorator")
.req(Decorator.class, NetworkDecorator.ID, "networkDecorator")
.req(Decorator.class, ExceptionDecorator.ID, "exceptionDecorator")
.req(Decorator.class, SystemDecorator.ID, "systemDecorator")
.req(Decorator.class, ThirdpartyDecorator.ID, "thirdpartyDecorator"));
.req(Decorator.class, ThirdpartyDecorator.ID, "thirdpartyDecorator")
.req(Decorator.class, FrontEndExceptionDecorator.ID, "frontEndExceptionDecorator"));
all.add(C(AlertPolicyManager.class).req(ConfigDao.class));
......
......@@ -36,15 +36,14 @@ public class SystemGraphCreator extends AbstractGraphCreator {
"eth0-outFlow:sum", "eth0-dropped:sum", "eth0-errors:sum", "eth0-collisions:sum", "lo-inFlow:sum",
"lo-outFlow:sum", "swapUsage:avg", "loadAvg1:avg", "loadAvg5:avg", "totalMem:avg", "usedMem:avg",
"freeMem:avg", "sharedMem:avg", "buffersMem:avg", "cachedMem:avg", "totalProcess:avg", "runningProcess:avg",
"swapUsage:avg", "establishedTcp:avg", "loginUsers:avg", "uptime:avg", "md5Change:avg", "hostNameChange:avg",
"hostIpChange:avg");
"swapUsage:avg", "establishedTcp:avg", "loginUsers:avg");
private static final List<String> PAAS_SYSTEM_KEY_LIST = Arrays.asList("sysCpu:avg", "userCpu:avg", "cpuUsage:avg",
"/-usage:avg", "/-freeInodes:avg", "/-read:sum", "/-write:sum", "eth0-inFlow:sum", "eth0-outFlow:sum",
"eth0-dropped:sum", "eth0-errors:sum", "eth0-collisions:sum", "lo-inFlow:sum", "lo-outFlow:sum",
"swapUsage:avg", "totalMem:avg", "usedMem:avg", "freeMem:avg", "sharedMem:avg", "buffersMem:avg",
"cachedMem:avg", "totalProcess:avg", "runningProcess:avg", "swapUsage:avg", "establishedTcp:avg",
"loginUsers:avg", "uptime:avg", "md5Change:avg");
"loginUsers:avg");
private static final List<String> JVM_KEY_LIST = new ArrayList<String>(Arrays.asList("edenUsage:avg",
"oldUsage:avg", "permUsage:avg", "catalinaLogSize:sum"));
......
......@@ -6,6 +6,8 @@ public class AlertConstants {
public static final String EXCEPTION = "exception";
public static final String FRONT_END_EXCEPTION = "frontEndException";
public static final String NETWORK = "network";
public static final String SYSTEM = "system";
......@@ -18,4 +20,8 @@ public class AlertConstants {
public static final String WEIXIN = "weixin";
public static final String WARNING_EXCEPTION = "warning";
public static final String ERROR_EXCEPTION = "error";
}
package com.dianping.cat.report.task.alert.exception;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
......@@ -11,11 +9,12 @@ import java.util.Map.Entry;
import org.unidal.lookup.annotation.Inject;
import org.unidal.tuple.Pair;
import com.dianping.cat.Constants;
import com.dianping.cat.config.aggregation.AggregationConfigManager;
import com.dianping.cat.configuration.aggreation.model.entity.AggregationRule;
import com.dianping.cat.home.dependency.exception.entity.ExceptionExclude;
import com.dianping.cat.home.dependency.exception.entity.ExceptionLimit;
import com.dianping.cat.report.page.top.TopMetric.Item;
import com.dianping.cat.report.task.alert.AlertConstants;
import com.dianping.cat.system.config.ExceptionConfigManager;
public class AlertExceptionBuilder {
......@@ -30,29 +29,32 @@ public class AlertExceptionBuilder {
Map<String, List<AlertException>> alertExceptions = new LinkedHashMap<String, List<AlertException>>();
for (Item item : items) {
String domain = item.getDomain();
List<AlertException> domainAlertExceptions = buildDomainAlertExceptions(item);
if (Constants.FRONT_END.equalsIgnoreCase(domain)) {
List<AlertException> frontEndAlertExceptions = buildFrontEndAlertExceptions(item);
if (!frontEndAlertExceptions.isEmpty()) {
alertExceptions.put(domain, frontEndAlertExceptions);
}
} else {
List<AlertException> domainAlertExceptions = buildDomainAlertExceptions(item);
if (!domainAlertExceptions.isEmpty()) {
alertExceptions.put(domain, domainAlertExceptions);
}
if (!domainAlertExceptions.isEmpty()) {
alertExceptions.put(item.getDomain(), domainAlertExceptions);
}
}
return alertExceptions;
}
private List<AlertException> buildFrontEndAlertExceptions(Item item) {
String domain = item.getDomain();
public List<AlertException> buildFrontEndAlertExceptions(Item frontEndItem) {
List<AlertException> alertExceptions = new ArrayList<AlertException>();
return null;
for (Entry<String, Double> entry : frontEndItem.getException().entrySet()) {
String exception = entry.getKey();
AggregationRule rule = m_aggregationConfigManager.queryAggration(exception);
if (rule != null) {
int warn = rule.getWarn();
double value = entry.getValue().doubleValue();
if (value >= warn) {
alertExceptions.add(new AlertException(exception, AlertConstants.WARNING_EXCEPTION, value));
}
}
}
return alertExceptions;
}
private List<AlertException> buildDomainAlertExceptions(Item item) {
......@@ -75,19 +77,19 @@ public class AlertExceptionBuilder {
totalException += value;
if (errorLimit > 0 && value >= errorLimit) {
alertExceptions.add(new AlertException(exceptionName, AlertException.ERROR_EXCEPTION, value,
alertExceptions.add(new AlertException(exceptionName, AlertConstants.ERROR_EXCEPTION, value,
needSendSms(domain, exceptionName)));
} else if (warnLimit > 0 && value >= warnLimit) {
alertExceptions.add(new AlertException(exceptionName, AlertException.WARN_EXCEPTION, value));
alertExceptions.add(new AlertException(exceptionName, AlertConstants.WARNING_EXCEPTION, value));
}
}
}
if (totalErrorLimit > 0 && totalException >= totalErrorLimit) {
alertExceptions.add(new AlertException(ExceptionConfigManager.TOTAL_STRING, AlertException.ERROR_EXCEPTION,
alertExceptions.add(new AlertException(ExceptionConfigManager.TOTAL_STRING, AlertConstants.ERROR_EXCEPTION,
totalException, needSendSms(domain, ExceptionConfigManager.TOTAL_STRING)));
} else if (totalWarnLimit > 0 && totalException >= totalWarnLimit) {
alertExceptions.add(new AlertException(ExceptionConfigManager.TOTAL_STRING, AlertException.WARN_EXCEPTION,
alertExceptions.add(new AlertException(ExceptionConfigManager.TOTAL_STRING, AlertConstants.WARNING_EXCEPTION,
totalException));
}
......@@ -146,72 +148,8 @@ public class AlertExceptionBuilder {
return limits;
}
public String buildMailContent(String exceptions, String domain, String contactInfo) {
String content = buildContent(exceptions, domain, contactInfo);
String date = new SimpleDateFormat("yyyyMMddHH").format(new Date());
String url = "http://cat.dianpingoa.com/cat/r/p?domain=" + domain + "&date=" + date;
String mailContent = content + "<br/>" + " <a href='" + url + "'>点击此处查看详情</a>";
return mailContent;
}
public String buildDBContent(String exceptions, String domain) {
String content = buildContent(exceptions, domain);
String url = "http://cat.dianpingoa.com/cat/r/p?domain=" + domain;
String mailContent = content + "<br/>" + " <a href='" + url + "'>点击此处查看详情</a>";
return mailContent;
}
public String buildContent(String exceptions, String domain) {
StringBuilder sb = new StringBuilder();
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
sb.append("[CAT异常告警] [项目: ").append(domain).append("] : ");
sb.append(exceptions).append("[时间: ").append(time).append("]");
return sb.toString();
}
public String buildContent(String exceptions, String domain, String contactInfo) {
StringBuilder sb = new StringBuilder();
String time = new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date());
sb.append("[CAT异常告警] [项目: ").append(domain).append("] : ");
sb.append(exceptions).append("[时间: ").append(time).append("]").append("\n");
sb.append(contactInfo);
return sb.toString();
}
public List<AlertException> buildErrorException(List<AlertException> exceptions) {
List<AlertException> errorExceptions = new ArrayList<AlertException>();
for (AlertException alertException : exceptions) {
if (AlertException.ERROR_EXCEPTION.equals(alertException.getType())) {
errorExceptions.add(alertException);
}
}
return errorExceptions;
}
public List<AlertException> buildErrorAndTriggeredException(List<AlertException> exceptions) {
List<AlertException> errorExceptions = new ArrayList<AlertException>();
for (AlertException alertException : exceptions) {
if (AlertException.ERROR_EXCEPTION.equals(alertException.getType()) && alertException.isTriggered()) {
errorExceptions.add(alertException);
}
}
return errorExceptions;
}
public class AlertException {
private static final String WARN_EXCEPTION = "warn";
private static final String ERROR_EXCEPTION = "error";
private String m_name;
private String m_type;
......
......@@ -94,31 +94,27 @@ public class ExceptionAlert implements Task {
try {
TopMetric topMetric = buildTopMetric(new Date(current - TimeUtil.ONE_MINUTE * 2));
Collection<List<Item>> items = topMetric.getError().getResult().values();
List<Item> item = new ArrayList<Item>();
Collection<List<Item>> itemLists = topMetric.getError().getResult().values();
List<Item> itemList = new ArrayList<Item>();
if (!items.isEmpty()) {
item = items.iterator().next();
if (!itemLists.isEmpty()) {
itemList = itemLists.iterator().next();
}
Map<String, List<AlertException>> alertExceptions = m_alertBuilder.buildAlertExceptions(item);
for (Entry<String, List<AlertException>> entry : alertExceptions.entrySet()) {
try {
String domain = entry.getKey();
List<AlertException> exceptions = entry.getValue();
for (AlertException exception : exceptions) {
String metricName = exception.getName();
AlertEntity entity = new AlertEntity();
entity.setDate(new Date()).setContent(exception.toString()).setLevel(exception.getType());
entity.setMetric(metricName).setType(getName()).setGroup(domain);
m_sendManager.addAlert(entity);
}
} catch (Exception e) {
Cat.logError(e);
Item frontEndItem = null;
List<Item> otherItemList = new ArrayList<Item>();
for (Item item : itemList) {
if (Constants.FRONT_END.equals(item.getDomain())) {
frontEndItem = item;
} else {
otherItemList.add(item);
}
}
if (frontEndItem != null) {
handleFrontEndException(frontEndItem);
}
handleGeneralExceptions(itemList);
t.setStatus(Transaction.SUCCESS);
} catch (Exception e) {
t.setStatus(e);
......@@ -137,6 +133,45 @@ public class ExceptionAlert implements Task {
}
}
private void handleGeneralExceptions(List<Item> itemList) {
Map<String, List<AlertException>> alertExceptions = m_alertBuilder.buildAlertExceptions(itemList);
for (Entry<String, List<AlertException>> entry : alertExceptions.entrySet()) {
try {
String domain = entry.getKey();
List<AlertException> exceptions = entry.getValue();
for (AlertException exception : exceptions) {
String metricName = exception.getName();
AlertEntity entity = new AlertEntity();
entity.setDate(new Date()).setContent(exception.toString()).setLevel(exception.getType());
entity.setMetric(metricName).setType(getName()).setGroup(domain);
m_sendManager.addAlert(entity);
}
} catch (Exception e) {
Cat.logError(e);
}
}
}
private void handleFrontEndException(Item frontEndItem) {
List<AlertException> alertExceptions = m_alertBuilder.buildFrontEndAlertExceptions(frontEndItem);
for (AlertException exception : alertExceptions) {
try {
String metricName = exception.getName();
AlertEntity entity = new AlertEntity();
entity.setDate(new Date()).setContent(exception.toString()).setLevel(exception.getType());
entity.setMetric(metricName).setType(AlertConstants.FRONT_END_EXCEPTION).setGroup(metricName);
m_sendManager.addAlert(entity);
} catch (Exception e) {
Cat.logError(e);
}
}
}
@Override
public void shutdown() {
}
......
......@@ -27,6 +27,9 @@ public class DecoratorManager implements Initializable {
@Inject(type = Decorator.class, value = ThirdpartyDecorator.ID)
private Decorator m_thirdpartyDecorator;
@Inject(type = Decorator.class, value = FrontEndExceptionDecorator.ID)
private Decorator m_frontEndExceptionDecorator;
private Map<String, Decorator> m_decorators = new HashMap<String, Decorator>();
public Pair<String, String> generateTitleAndContent(AlertEntity alert) {
......@@ -50,6 +53,7 @@ public class DecoratorManager implements Initializable {
m_decorators.put(m_exceptionDecorator.getId(), m_exceptionDecorator);
m_decorators.put(m_systemDecorator.getId(), m_systemDecorator);
m_decorators.put(m_thirdpartyDecorator.getId(), m_thirdpartyDecorator);
m_decorators.put(m_frontEndExceptionDecorator.getId(), m_frontEndExceptionDecorator);
}
public void setBusinessDecorator(Decorator decorator) {
......@@ -72,4 +76,8 @@ public class DecoratorManager implements Initializable {
m_thirdpartyDecorator = decorator;
}
public void setFrontEndExceptionDecorator(Decorator decorator) {
m_frontEndExceptionDecorator = decorator;
}
}
......@@ -23,7 +23,7 @@ public class ExceptionDecorator extends DefaultDecorator implements Initializabl
public static final String ID = AlertConstants.EXCEPTION;
private DateFormat m_dateFormat = new SimpleDateFormat("yyyyMMddHH");
protected DateFormat m_dateFormat = new SimpleDateFormat("yyyyMMddHH");
@Override
public String getId() {
......@@ -51,7 +51,7 @@ public class ExceptionDecorator extends DefaultDecorator implements Initializabl
return sw.toString();
}
private Map<Object, Object> generateExceptionMap(AlertEntity alert) {
protected Map<Object, Object> generateExceptionMap(AlertEntity alert) {
String domain = alert.getGroup();
String contactInfo = buildContactInfo(domain);
Map<Object, Object> map = new HashMap<Object, Object>();
......
package com.dianping.cat.report.task.alert.sender.decorator;
import com.dianping.cat.report.task.alert.AlertConstants;
public class FrontEndExceptionDecorator extends ExceptionDecorator {
public static final String ID = AlertConstants.FRONT_END_EXCEPTION;
@Override
public String getId() {
return ID;
}
@Override
protected String buildContactInfo(String domainName) {
return "";
}
}
......@@ -28,6 +28,9 @@ public class ContactorManager implements Initializable {
@Inject(type = Contactor.class, value = ThirdpartyContactor.ID)
private Contactor m_thirdpartyContactor;
@Inject(type = Contactor.class, value = FrontEndExceptionContactor.ID)
private Contactor m_frontEndExceptionContactor;
private Map<String, Contactor> m_contactors = new HashMap<String, Contactor>();
public List<String> queryReceivers(String group, String channel, String type) {
......@@ -51,6 +54,7 @@ public class ContactorManager implements Initializable {
m_contactors.put(m_exceptionContactor.getId(), m_exceptionContactor);
m_contactors.put(m_systemContactor.getId(), m_systemContactor);
m_contactors.put(m_thirdpartyContactor.getId(), m_thirdpartyContactor);
m_contactors.put(m_frontEndExceptionContactor.getId(), m_frontEndExceptionContactor);
}
public void setBusinessContactor(Contactor contactor) {
......@@ -73,4 +77,8 @@ public class ContactorManager implements Initializable {
m_thirdpartyContactor = thirdpartyContactor;
}
public void setFrontEndExceptionContactor(Contactor frontEndExceptionContactor) {
m_frontEndExceptionContactor = frontEndExceptionContactor;
}
}
package com.dianping.cat.report.task.alert.sender.receiver;
import java.util.ArrayList;
import java.util.List;
import org.unidal.helper.Splitters;
import org.unidal.lookup.annotation.Inject;
import com.dianping.cat.config.aggregation.AggregationConfigManager;
import com.dianping.cat.configuration.aggreation.model.entity.AggregationRule;
import com.dianping.cat.report.task.alert.AlertConstants;
public class FrontEndExceptionContactor implements Contactor {
@Inject
private AggregationConfigManager m_configManager;
public static final String ID = AlertConstants.FRONT_END_EXCEPTION;
@Override
public String getId() {
return ID;
}
@Override
public List<String> queryEmailContactors(String id) {
AggregationRule rule = m_configManager.queryAggration(id);
if (rule != null) {
String mails = rule.getMails();
List<String> receiver = Splitters.by(",").noEmptyItem().split(mails);
return receiver;
} else {
return new ArrayList<String>();
}
}
@Override
public List<String> queryWeiXinContactors(String id) {
return null;
}
@Override
public List<String> querySmsContactors(String id) {
return null;
}
}
<config mode="client" xmlns:xsi="http://www.w3.org/2001/XMLSchema" xsi:noNamespaceSchemaLocation="config.xsd">
<domain id="FrontEnd"/>
<domain id="Cat"/>
</config>
......@@ -479,15 +479,6 @@
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.report.task.alert.exception.AlertExceptionBuilder</role>
<implementation>com.dianping.cat.report.task.alert.exception.AlertExceptionBuilder</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.system.config.ExceptionConfigManager</role>
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.report.task.alert.summary.AlertSummaryExecutor</role>
<implementation>com.dianping.cat.report.task.alert.summary.AlertSummaryExecutor</implementation>
......@@ -628,6 +619,16 @@
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.report.task.alert.sender.receiver.Contactor</role>
<role-hint>frontEndException</role-hint>
<implementation>com.dianping.cat.report.task.alert.sender.receiver.FrontEndExceptionContactor</implementation>
<requirements>
<requirement>
<role>com.dianping.cat.config.aggregation.AggregationConfigManager</role>
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.report.task.alert.sender.receiver.ContactorManager</role>
<implementation>com.dianping.cat.report.task.alert.sender.receiver.ContactorManager</implementation>
......@@ -657,6 +658,11 @@
<role-hint>thirdParty</role-hint>
<field-name>thirdpartyContactor</field-name>
</requirement>
<requirement>
<role>com.dianping.cat.report.task.alert.sender.receiver.Contactor</role>
<role-hint>frontEndException</role-hint>
<field-name>frontEndExceptionContactor</field-name>
</requirement>
</requirements>
</component>
<component>
......@@ -709,6 +715,11 @@
</requirement>
</requirements>
</component>
<component>
<role>com.dianping.cat.report.task.alert.sender.decorator.Decorator</role>
<role-hint>frontEndException</role-hint>
<implementation>com.dianping.cat.report.task.alert.sender.decorator.FrontEndExceptionDecorator</implementation>
</component>
<component>
<role>com.dianping.cat.report.task.alert.sender.decorator.DecoratorManager</role>
<implementation>com.dianping.cat.report.task.alert.sender.decorator.DecoratorManager</implementation>
......@@ -738,6 +749,11 @@
<role-hint>thirdParty</role-hint>
<field-name>thirdpartyDecorator</field-name>
</requirement>
<requirement>
<role>com.dianping.cat.report.task.alert.sender.decorator.Decorator</role>
<role-hint>frontEndException</role-hint>
<field-name>frontEndExceptionDecorator</field-name>
</requirement>
</requirements>
</component>
<component>
......@@ -941,6 +957,9 @@
<requirement>
<role>com.dianping.cat.system.config.ExceptionConfigManager</role>
</requirement>
<requirement>
<role>com.dianping.cat.config.aggregation.AggregationConfigManager</role>
</requirement>
</requirements>
</component>
<component>
......@@ -3591,6 +3610,9 @@
<requirement>
<role>com.dianping.cat.system.config.ExceptionConfigManager</role>
</requirement>
<requirement>
<role>com.dianping.cat.ServerConfigManager</role>
</requirement>
</requirements>
</component>
<component>
......
package com.dianping.cat.report.task.alert;
import com.dianping.cat.Cat;
public class ExceptionBuilder {
public static void main(String args[]) {
while (true) {
Cat.logError(new RuntimeException("just test for FrontEnd"));
System.out.println("log error");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册