Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
9a1bed87fd
|
|
@ -0,0 +1,21 @@
|
|||
package com.ai.cloud.skywalking.alarm.model;
|
||||
|
||||
public class AlarmMessage {
|
||||
private String traceid;
|
||||
|
||||
private String exceptionMsg;
|
||||
|
||||
public AlarmMessage(String traceid, String exceptionMsg) {
|
||||
super();
|
||||
this.traceid = traceid;
|
||||
this.exceptionMsg = exceptionMsg;
|
||||
}
|
||||
|
||||
public String getTraceid() {
|
||||
return traceid;
|
||||
}
|
||||
|
||||
public String getExceptionMsg() {
|
||||
return exceptionMsg;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,6 @@ import java.io.StringReader;
|
|||
import java.io.StringWriter;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
|
@ -19,6 +18,7 @@ import org.apache.logging.log4j.Logger;
|
|||
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
||||
import com.ai.cloud.skywalking.alarm.model.AlarmMessage;
|
||||
import com.ai.cloud.skywalking.alarm.model.AlarmRule;
|
||||
import com.ai.cloud.skywalking.alarm.model.ApplicationInfo;
|
||||
import com.ai.cloud.skywalking.alarm.model.MailInfo;
|
||||
|
|
@ -50,7 +50,7 @@ public class AlarmMessageProcessor {
|
|||
|
||||
|
||||
public void process(UserInfo userInfo, AlarmRule rule) throws TemplateException, IOException, SQLException {
|
||||
Set<String> warningTracingIds = new HashSet<String>();
|
||||
Set<AlarmMessage> warningObjects = new HashSet<AlarmMessage>();
|
||||
Set<String> warningMessageKeys = new HashSet<String>();
|
||||
long currentFireMinuteTime = System.currentTimeMillis() / (10000 * 6);
|
||||
long warningTimeWindowSize = currentFireMinuteTime
|
||||
|
|
@ -66,28 +66,26 @@ public class AlarmMessageProcessor {
|
|||
+ (currentFireMinuteTime - period - 1);
|
||||
|
||||
warningMessageKeys.add(alarmKey);
|
||||
warningTracingIds.addAll(getAlarmMessages(alarmKey));
|
||||
setAlarmMessages(alarmKey, warningObjects);
|
||||
}
|
||||
}
|
||||
|
||||
// 发送告警数据
|
||||
if (warningTracingIds.size() > 0) {
|
||||
if (warningObjects.size() > 0) {
|
||||
if ("0".equals(rule.getTodoType())) {
|
||||
logger.info("A total of {} alarm information needs to be sent {}", warningTracingIds.size(),
|
||||
logger.info("A total of {} alarm information needs to be sent {}", warningObjects.size(),
|
||||
rule.getConfigArgsDescriber().getMailInfo().getMailTo());
|
||||
// 发送邮件
|
||||
String subjects = generateSubject(warningTracingIds.size(),
|
||||
String subjects = generateSubject(warningObjects.size(),
|
||||
rule.getPreviousFireTimeM(), currentFireMinuteTime);
|
||||
Map parameter = new HashMap();
|
||||
parameter.put("warningTracingIds", warningTracingIds);
|
||||
Map<String, Object> parameter = new HashMap<String, Object>();
|
||||
parameter.put("warningObjects", warningObjects);
|
||||
parameter.put("name", userInfo.getUserName());
|
||||
parameter.put("startDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(
|
||||
rule.getPreviousFireTimeM() * 10000 * 6)));
|
||||
parameter.put("endDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(
|
||||
currentFireMinuteTime * 10000 * 6)));
|
||||
String mailContext = generateContent(/*rule
|
||||
.getConfigArgsDescriber().getMailInfo()
|
||||
.getMailTemp()*/mailTemplate, parameter);
|
||||
String mailContext = generateContent(mailTemplate, parameter);
|
||||
if (mailContext.length() > 0) {
|
||||
MailInfo mailInfo = rule.getConfigArgsDescriber()
|
||||
.getMailInfo();
|
||||
|
|
@ -147,15 +145,17 @@ public class AlarmMessageProcessor {
|
|||
});
|
||||
}
|
||||
|
||||
private Collection<String> getAlarmMessages(final String key) {
|
||||
return RedisUtil.execute(new Executable<Collection<String>>() {
|
||||
private void setAlarmMessages(final String key, final Collection<AlarmMessage> warningTracingIds) {
|
||||
RedisUtil.execute(new Executable<Object>() {
|
||||
@Override
|
||||
public Collection<String> exe(Jedis client) {
|
||||
Map<String, String> result = client.hgetAll(key);
|
||||
if (result == null) {
|
||||
return new ArrayList<String>();
|
||||
if (result != null) {
|
||||
for(String traceid : result.keySet()){
|
||||
warningTracingIds.add(new AlarmMessage(traceid, result.get(traceid)));
|
||||
}
|
||||
}
|
||||
return result.keySet();
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
template.default=<!DOCTYPE html PUBLIC\"-//W3C//DTD XHTML 1.0 Transitional//EN\"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\"content=\"text/html; charset=utf-8\"><style type=\"text/css\">li{text-indent:2em}</style><title>templete1_welcome</title></head><body style=\"background:#eee;\"><table width=\"80%\"cellpadding=\"0\"cellspacing=\"0\"border=\"0\"style=\"text-align:left;font:12px/15px simsun; line-height:20px; color:#000;background:#fff; padding:30px 20px; border:20px solid #fff; margin:0 auto;\"><tbody><tr><td style=\"margin:0; padding:0;\"><div style=\"background:#f9f9f9; padding:25px; font-family: \u5fae\u8f6f\u96c5\u9ed1, \u9ed1\u4f53, Arial; font-size:14px; line-height:25px; margin:5px 0; overflow:hidden;\"><p>\u5c0a\u656c\u7684SkyWalking\u7528\u6237\u60a8\u597d:</p><p>\u81ea<b>${startDate!}</b>\u8d77\uff0c\u5230<b>${endDate!}</b>\u6b62\uff0c\u5e73\u53f0\u63a5\u6536\u5230\u76d1\u63a7\u544a\u8b66\u4fe1\u606f\u5982\u4e0b\uff1a</p><p><#if warningTracingIds??><#list warningTracingIds as traceId><li><a href=\"${(portalAddr + traceId)!}\">${traceId!}</a></li></#list></#if></p></div></td></tr></tbody></table></body></html>
|
||||
template.default=<!DOCTYPE html PUBLIC\"-//W3C//DTD XHTML 1.0 Transitional//EN\"\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html xmlns=\"http://www.w3.org/1999/xhtml\"><head><meta http-equiv=\"Content-Type\"content=\"text/html; charset=utf-8\"><style type=\"text/css\">li{text-indent:2em}</style><title>templete1_welcome</title></head><body style=\"background:#eee;\"><table width=\"80%\"cellpadding=\"0\"cellspacing=\"0\"border=\"0\"style=\"text-align:left;font:12px/15px simsun; line-height:20px; color:#000;background:#fff; padding:30px 20px; border:20px solid #fff; margin:0 auto;\"><tbody><tr><td style=\"margin:0; padding:0;\"><div style=\"background:#f9f9f9; padding:25px; font-family: \u5fae\u8f6f\u96c5\u9ed1, \u9ed1\u4f53, Arial; font-size:14px; line-height:25px; margin:5px 0; overflow:hidden;\"><p>\u5c0a\u656c\u7684SkyWalking\u7528\u6237\u60a8\u597d:</p><p>\u81ea<b>${startDate!}</b>\u8d77\uff0c\u5230<b>${endDate!}</b>\u6b62\uff0c\u5e73\u53f0\u63a5\u6536\u5230\u76d1\u63a7\u544a\u8b66\u4fe1\u606f\u5982\u4e0b\uff1a</p><p><#if warningTracingIds??><#list warningObjects as warningObject><li><a href=\"${(portalAddr + warningObject.traceId)!}\">${warningObject.traceId!}</a><br/>Stack: ${warningObject.exceptionMsg!}</li></#list></#if></p></div></td></tr></tbody></table></body></html>
|
||||
|
|
|
|||
|
|
@ -91,6 +91,8 @@ public class Config {
|
|||
public static class Alarm {
|
||||
|
||||
public static int ALARM_EXPIRE_SECONDS = 1000 * 60 * 90;
|
||||
|
||||
public static int ALARM_EXCEPTION_STACK_LENGTH = 300;
|
||||
|
||||
public static String REDIS_SERVER = "127.0.0.1:6379";
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ import redis.clients.jedis.exceptions.JedisConnectionException;
|
|||
import java.util.List;
|
||||
|
||||
import static com.ai.cloud.skywalking.reciever.conf.Config.Alarm.ALARM_EXPIRE_SECONDS;
|
||||
import static com.ai.cloud.skywalking.reciever.conf.Config.Alarm.ALARM_EXCEPTION_STACK_LENGTH;
|
||||
|
||||
public class AlarmChain implements IStorageChain {
|
||||
private static Logger logger = LogManager.getLogger(AlarmChain.class);
|
||||
|
|
@ -58,7 +59,13 @@ public class AlarmChain implements IStorageChain {
|
|||
for (Span span : spans) {
|
||||
if (span.getStatusCode() != 1)
|
||||
continue;
|
||||
saveAlarmMessage(generateAlarmKey(span), span.getTraceId());
|
||||
String exceptionStack = span.getExceptionStack();
|
||||
if(exceptionStack == null){
|
||||
exceptionStack = "";
|
||||
}else if(exceptionStack.length() > ALARM_EXCEPTION_STACK_LENGTH){
|
||||
exceptionStack = exceptionStack.substring(0, ALARM_EXCEPTION_STACK_LENGTH);
|
||||
}
|
||||
saveAlarmMessage(generateAlarmKey(span), span.getTraceId(), exceptionStack);
|
||||
}
|
||||
chain.doChain(spans);
|
||||
}
|
||||
|
|
@ -68,7 +75,7 @@ public class AlarmChain implements IStorageChain {
|
|||
+ (System.currentTimeMillis() / (10000 * 6));
|
||||
}
|
||||
|
||||
private void saveAlarmMessage(String key, String traceId) {
|
||||
private void saveAlarmMessage(String key, String traceId, String exceptionMsgOutline) {
|
||||
if (Config.Alarm.ALARM_OFF_FLAG) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -76,7 +83,7 @@ public class AlarmChain implements IStorageChain {
|
|||
Jedis jedis = null;
|
||||
try {
|
||||
jedis = jedisPool.getResource();
|
||||
jedis.hset(key, traceId, "");
|
||||
jedis.hsetnx(key, traceId, exceptionMsgOutline);
|
||||
jedis.expire(key, ALARM_EXPIRE_SECONDS);
|
||||
} catch (Exception e) {
|
||||
handleFailedToConnectRedisServerException(e);
|
||||
|
|
|
|||
Loading…
Reference in New Issue