parent
7b47658ded
commit
11ac0edbbd
|
|
@ -0,0 +1,49 @@
|
|||
#!/bin/sh
|
||||
|
||||
# OS specific support. $var _must_ be set to either true or false.
|
||||
cygwin=false
|
||||
os400=false
|
||||
darwin=false
|
||||
case "`uname`" in
|
||||
CYGWIN*) cygwin=true;;
|
||||
OS400*) os400=true;;
|
||||
Darwin*) darwin=true;;
|
||||
esac
|
||||
|
||||
# resolve links - $0 may be a softlink
|
||||
SW_SERVER_BIN="$0"
|
||||
|
||||
while [ -h "$SW_SERVER_BIN" ]; do
|
||||
ls=`ls -ld "$SW_SERVER_BIN"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SW_SERVER_BIN="$link"
|
||||
else
|
||||
SW_SERVER_BIN=`dirname "$SW_SERVER_BIN"`/"$link"
|
||||
fi
|
||||
done
|
||||
|
||||
# Get standard environment variables
|
||||
SW_SERVER_BIN_DIR=`dirname "$SW_SERVER_BIN"`
|
||||
SW_PREFIX="${SW_SERVER_BIN_DIR}/.."
|
||||
SW_LOG_DIR="${SW_SERVER_BIN_DIR}/../log"
|
||||
SW_CFG_DIR="${SW_SERVER_BIN_DIR}/../config"
|
||||
|
||||
#echo $SW_SERVER_BIN_DIR
|
||||
#set java home
|
||||
if [ "$JAVA_HOME" != "" ]; then
|
||||
JAVA="$JAVA_HOME/bin/java"
|
||||
else
|
||||
JAVA=java
|
||||
fi
|
||||
|
||||
CLASSPATH="$SW_CFG_DIR:$CLASSPATH"
|
||||
|
||||
for i in "${SW_SERVER_BIN_DIR}"/../lib/*.jar
|
||||
do
|
||||
CLASSPATH="$i:$CLASSPATH"
|
||||
done
|
||||
|
||||
echo "CLASSPATH=$CLASSPATH"
|
||||
|
||||
$JAVA -classpath $CLASSPATH com.ai.cloud.skywalking.reciever.CollectionServer >> ${SW_SERVER_BIN_DIR}/../log/sw-server.log & 2>&1&
|
||||
|
|
@ -142,7 +142,7 @@ public class UserInfoCoordinator extends Thread {
|
|||
}
|
||||
|
||||
private List<String> allocationUser(List<String> registeredThreads,
|
||||
List<String> userIds) {
|
||||
List<String> userIds) throws Exception {
|
||||
List<String> realRedistributeThread = new ArrayList<String>();
|
||||
Set<String> sortThreadIds = new HashSet<String>(registeredThreads);
|
||||
int step = (int) Math.ceil(userIds.size() * 1.0 / sortThreadIds.size());
|
||||
|
|
@ -181,12 +181,12 @@ public class UserInfoCoordinator extends Thread {
|
|||
return realRedistributeThread;
|
||||
}
|
||||
|
||||
private List<String> acquireAllRegisteredThread() {
|
||||
private List<String> acquireAllRegisteredThread() throws Exception {
|
||||
return ZKUtil.getChildren(Config.ZKPath.REGISTER_SERVER_PATH);
|
||||
}
|
||||
|
||||
private boolean checkAllProcessStatus(List<String> registeredThreadIds,
|
||||
ProcessThreadStatus status) {
|
||||
ProcessThreadStatus status) throws Exception {
|
||||
String registerPathPrefix = Config.ZKPath.REGISTER_SERVER_PATH + "/";
|
||||
for (String threadId : registeredThreadIds) {
|
||||
|
||||
|
|
@ -202,7 +202,7 @@ public class UserInfoCoordinator extends Thread {
|
|||
}
|
||||
|
||||
private ProcessThreadStatus getProcessThreadStatus(
|
||||
String registerPathPrefix, String threadId) {
|
||||
String registerPathPrefix, String threadId) throws Exception {
|
||||
if (!ZKUtil.exists(Config.ZKPath.REGISTER_SERVER_PATH + "/" + threadId))
|
||||
return ProcessThreadStatus.FREE;
|
||||
String value = ZKUtil.getPathData(registerPathPrefix + threadId);
|
||||
|
|
@ -214,7 +214,7 @@ public class UserInfoCoordinator extends Thread {
|
|||
}
|
||||
|
||||
private void changeStatus(List<String> registeredThreadIds,
|
||||
ProcessThreadStatus status) {
|
||||
ProcessThreadStatus status) throws Exception {
|
||||
for (String threadId : registeredThreadIds) {
|
||||
ProcessUtil.changeProcessThreadStatus(threadId, status);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,4 +73,8 @@ public class Config {
|
|||
public static class MailSenderInfo {
|
||||
public static String configId = "1000";
|
||||
}
|
||||
|
||||
public static class TemplateInfo{
|
||||
public static String CONFIG_ID = "1001";
|
||||
}
|
||||
}
|
||||
|
|
@ -11,7 +11,7 @@ import java.sql.SQLException;
|
|||
public class SystemConfigDao {
|
||||
private static Logger logger = LogManager.getLogger(AlarmMessageDao.class);
|
||||
|
||||
public static String getMailSenderInfo(String configId) throws SQLException {
|
||||
public static String getSystemConfig(String configId) throws SQLException {
|
||||
PreparedStatement ps = DBConnectUtil.getConnection().prepareStatement(
|
||||
"SELECT system_config.conf_value FROM system_config WHERE system_config.sts = " +
|
||||
"? AND system_config.config_id = ?");
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
package com.ai.cloud.skywalking.alarm.procesor;
|
||||
|
||||
import com.ai.cloud.skywalking.alarm.dao.AlarmMessageDao;
|
||||
import com.ai.cloud.skywalking.alarm.model.AlarmRule;
|
||||
import com.ai.cloud.skywalking.alarm.model.ApplicationInfo;
|
||||
import com.ai.cloud.skywalking.alarm.model.MailInfo;
|
||||
import com.ai.cloud.skywalking.alarm.model.UserInfo;
|
||||
import com.ai.cloud.skywalking.alarm.util.MailUtil;
|
||||
import com.ai.cloud.skywalking.alarm.util.RedisUtil;
|
||||
import com.ai.cloud.skywalking.alarm.util.TemplateConfigurationUtil;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.Template;
|
||||
import freemarker.template.TemplateException;
|
||||
|
|
@ -18,6 +18,7 @@ import redis.clients.jedis.Jedis;
|
|||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
|
|
@ -38,9 +39,9 @@ public class AlarmMessageProcessor {
|
|||
for (int period = 0; period < warningTimeWindowSize; period++) {
|
||||
String alarmKey = userInfo.getUserId()
|
||||
+ "-"
|
||||
+ applicationInfo.getAppCode()
|
||||
+ applicationInfo.getAppId()
|
||||
+ "-"
|
||||
+ (currentFireMinuteTime - period);
|
||||
+ (currentFireMinuteTime - period - 1);
|
||||
|
||||
warningMessageKeys.add(alarmKey);
|
||||
warningTracingIds.addAll(getAlarmMessages(alarmKey));
|
||||
|
|
@ -50,6 +51,8 @@ public class AlarmMessageProcessor {
|
|||
// 发送告警数据
|
||||
if (warningTracingIds.size() > 0) {
|
||||
if ("0".equals(rule.getTodoType())) {
|
||||
logger.info("A total of {} alarm information needs to be sent {}", warningTracingIds.size(),
|
||||
rule.getConfigArgsDescriber().getMailInfo().getMailTo());
|
||||
// 发送邮件
|
||||
String subjects = generateSubject(warningTracingIds.size(),
|
||||
rule.getPreviousFireTimeM(), currentFireMinuteTime);
|
||||
|
|
@ -60,8 +63,6 @@ public class AlarmMessageProcessor {
|
|||
rule.getPreviousFireTimeM() * 10000 * 6)));
|
||||
parameter.put("endDate", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date(
|
||||
currentFireMinuteTime * 10000 * 6)));
|
||||
//TODO portalAddr需要初始化
|
||||
parameter.put("portalAddr", "http://127.0.0.1:8080/skywalking-webui/");
|
||||
String mailContext = generateContent(rule
|
||||
.getConfigArgsDescriber().getMailInfo()
|
||||
.getMailTemp(), parameter);
|
||||
|
|
@ -135,11 +136,9 @@ public class AlarmMessageProcessor {
|
|||
}
|
||||
|
||||
private String generateContent(String templateStr, Map parameter) {
|
||||
Configuration cfg = new Configuration(new Version("2.3.23"));
|
||||
cfg.setDefaultEncoding("UTF-8");
|
||||
Template t = null;
|
||||
try {
|
||||
t = new Template(null, new StringReader(templateStr), cfg);
|
||||
t = new Template(null, new StringReader(templateStr), TemplateConfigurationUtil.getConfiguration());
|
||||
StringWriter out = new StringWriter();
|
||||
t.process(parameter, out);
|
||||
return out.getBuffer().toString();
|
||||
|
|
@ -147,18 +146,16 @@ public class AlarmMessageProcessor {
|
|||
logger.error("Template illegal.", e);
|
||||
} catch (TemplateException e) {
|
||||
logger.error("Failed to generate content.", e);
|
||||
} catch (SQLException e) {
|
||||
logger.error("Failed to find template config");
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws InterruptedException {
|
||||
UserInfo userInfo = new UserInfo("27");
|
||||
userInfo.setUserName("123");
|
||||
List<AlarmRule> rules = AlarmMessageDao.selectAlarmRulesByUserId(userInfo.getUserId());
|
||||
while (true) {
|
||||
new AlarmMessageProcessor().process(userInfo, rules.get(0));
|
||||
Thread.sleep(60 * 1000L);
|
||||
}
|
||||
public static void main(String[] args) {
|
||||
System.out.println(System.currentTimeMillis() / (10000 * 6));
|
||||
AlarmMessageProcessor processor = new AlarmMessageProcessor();
|
||||
processor.getAlarmMessages("27-order-application-24167725");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class MailUtil {
|
|||
|
||||
static {
|
||||
try {
|
||||
String senderInfo = SystemConfigDao.getMailSenderInfo(Config.MailSenderInfo.configId);
|
||||
String senderInfo = SystemConfigDao.getSystemConfig(Config.MailSenderInfo.configId);
|
||||
Properties prop = new Gson().fromJson(senderInfo, Properties.class);
|
||||
session = Session.getInstance(prop);
|
||||
ts = session.getTransport();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
package com.ai.cloud.skywalking.alarm.util;
|
||||
|
||||
import com.ai.cloud.skywalking.alarm.conf.Config;
|
||||
import com.ai.cloud.skywalking.alarm.dao.SystemConfigDao;
|
||||
import freemarker.template.Configuration;
|
||||
import freemarker.template.TemplateModelException;
|
||||
import freemarker.template.Version;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class TemplateConfigurationUtil {
|
||||
|
||||
private static Configuration cfg;
|
||||
|
||||
public static Configuration getConfiguration() throws SQLException, TemplateModelException {
|
||||
if (cfg == null) {
|
||||
cfg = new Configuration(new Version("2.3.23"));
|
||||
cfg.setDefaultEncoding("UTF-8");
|
||||
cfg.setSharedVariable("portalAddr", SystemConfigDao.getSystemConfig(Config.TemplateInfo.CONFIG_ID));
|
||||
}
|
||||
|
||||
return cfg;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue