parent
b388f111e0
commit
eca97eb14d
|
|
@ -11,25 +11,25 @@ Darwin*) darwin=true;;
|
|||
esac
|
||||
|
||||
# resolve links - $0 may be a softlink
|
||||
SW_SERVER_BIN="$0"
|
||||
SW_ALARM_ALARM_SERVER_BIN="$0"
|
||||
|
||||
while [ -h "$SW_SERVER_BIN" ]; do
|
||||
ls=`ls -ld "$SW_SERVER_BIN"`
|
||||
while [ -h "$SW_ALARM_ALARM_SERVER_BIN" ]; do
|
||||
ls=`ls -ld "$SW_ALARM_ALARM_SERVER_BIN"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
SW_SERVER_BIN="$link"
|
||||
SW_ALARM_ALARM_SERVER_BIN="$link"
|
||||
else
|
||||
SW_SERVER_BIN=`dirname "$SW_SERVER_BIN"`/"$link"
|
||||
SW_ALARM_ALARM_SERVER_BIN=`dirname "$SW_ALARM_ALARM_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"
|
||||
SW_ALARM_ALARM_SERVER_BIN_DIR=`dirname "$SW_ALARM_ALARM_SERVER_BIN"`
|
||||
SW_ALARM_ALARM_PREFIX="${SW_ALARM_ALARM_SERVER_BIN_DIR}/.."
|
||||
SW_ALARM_ALARM_LOG_DIR="${SW_ALARM_ALARM_SERVER_BIN_DIR}/../log"
|
||||
SW_ALARM_ALARM_CFG_DIR="${SW_ALARM_ALARM_SERVER_BIN_DIR}/../config"
|
||||
|
||||
#echo $SW_SERVER_BIN_DIR
|
||||
#echo $SW_ALARM_ALARM_SERVER_BIN_DIR
|
||||
#set java home
|
||||
if [ "$JAVA_HOME" != "" ]; then
|
||||
JAVA="$JAVA_HOME/bin/java"
|
||||
|
|
@ -37,13 +37,13 @@ else
|
|||
JAVA=java
|
||||
fi
|
||||
|
||||
CLASSPATH="$SW_CFG_DIR:$CLASSPATH"
|
||||
CLASSPATH="$SW_ALARM_ALARM_CFG_DIR:$CLASSPATH"
|
||||
|
||||
for i in "${SW_SERVER_BIN_DIR}"/../lib/*.jar
|
||||
for i in "${SW_ALARM_ALARM_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&
|
||||
$JAVA -classpath $CLASSPATH com.ai.cloud.skywalking.alarm.AlarmProcessServer >> ${SW_ALARM_ALARM_SERVER_BIN_DIR}/../log/sw-alarm-server.log & 2>&1&
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@
|
|||
<executions>
|
||||
<execution>
|
||||
<id>copy-resources</id>
|
||||
<phase>install</phase>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
|
|
@ -103,7 +103,7 @@
|
|||
</execution>
|
||||
<execution>
|
||||
<id>copy-start-script</id>
|
||||
<phase>install</phase>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-resources</goal>
|
||||
</goals>
|
||||
|
|
@ -124,7 +124,7 @@
|
|||
<executions>
|
||||
<execution>
|
||||
<id>copy-dependencies</id>
|
||||
<phase>pre-integration-test</phase>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>copy-dependencies</goal>
|
||||
</goals>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ import org.apache.zookeeper.CreateMode;
|
|||
import org.apache.zookeeper.WatchedEvent;
|
||||
import org.apache.zookeeper.Watcher;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
|
@ -94,8 +95,7 @@ public class AlarmMessageProcessThread extends Thread {
|
|||
cacheRules.clear();
|
||||
}
|
||||
|
||||
private void cacheProcessUser(List<String> processUserIds) {
|
||||
// TODO 需要重新获取
|
||||
private void cacheProcessUser(List<String> processUserIds) throws SQLException {
|
||||
UserInfo tmpUserInfo;
|
||||
List<AlarmRule> alarmRules;
|
||||
for (String userId : processUserIds) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
package com.ai.cloud.skywalking.alarm;
|
||||
|
||||
import com.ai.cloud.skywalking.alarm.conf.Config;
|
||||
import com.ai.cloud.skywalking.alarm.conf.ConfigInitializer;
|
||||
import com.ai.cloud.skywalking.alarm.util.ZKUtil;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
public class AlarmProcessServer {
|
||||
|
||||
|
|
@ -15,8 +18,13 @@ public class AlarmProcessServer {
|
|||
private static List<AlarmMessageProcessThread> processThreads =
|
||||
new ArrayList<AlarmMessageProcessThread>();
|
||||
|
||||
public static void main(String[] main) {
|
||||
public static void main(String[] main) throws IOException, IllegalAccessException {
|
||||
logger.info("Begin to start alarm process server....");
|
||||
|
||||
logger.info("Begin to initialize configuration");
|
||||
initializeParam();
|
||||
logger.info("Finished to initialize configuration");
|
||||
|
||||
if (!ZKUtil.exists(Config.ZKPath.REGISTER_SERVER_PATH)) {
|
||||
ZKUtil.createPath(Config.ZKPath.REGISTER_SERVER_PATH);
|
||||
}
|
||||
|
|
@ -30,6 +38,8 @@ public class AlarmProcessServer {
|
|||
processThreads.add(tmpThread);
|
||||
}
|
||||
logger.info("Successfully launched {} processing threads.", Config.Server.PROCESS_THREAD_SIZE);
|
||||
new UserInfoInspectThread().start();
|
||||
logger.info("Successfully launched the thread that inspect the number of user");
|
||||
logger.info("Alarm process server successfully started.");
|
||||
while (true) {
|
||||
try {
|
||||
|
|
@ -40,8 +50,17 @@ public class AlarmProcessServer {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
public static List<AlarmMessageProcessThread> getProcessThreads() {
|
||||
return processThreads;
|
||||
private static void initializeParam() throws IllegalAccessException, IOException {
|
||||
Properties properties = new Properties();
|
||||
try {
|
||||
properties.load(AlarmProcessServer.class.getResourceAsStream("/config.properties"));
|
||||
ConfigInitializer.initialize(properties, Config.class);
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.error("Initialize the collect server configuration failed", e);
|
||||
throw e;
|
||||
} catch (IOException e) {
|
||||
logger.error("Initialize the collect server configuration failed", e);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class UserInfoCoordinator extends Thread {
|
|||
|
||||
private Logger logger = LogManager.getLogger(UserInfoCoordinator.class);
|
||||
|
||||
private boolean redistributing;
|
||||
private static boolean redistributing;
|
||||
private RegisterServerWatcher watcher = new RegisterServerWatcher();
|
||||
private InterProcessMutex lock = new InterProcessMutex(
|
||||
ZKUtil.getZkClient(), Config.ZKPath.COORDINATOR_PATH);
|
||||
|
|
@ -157,7 +157,7 @@ public class UserInfoCoordinator extends Thread {
|
|||
for (String thread : sortThreadIds) {
|
||||
if (!ZKUtil.exists(Config.ZKPath.REGISTER_SERVER_PATH + "/"
|
||||
+ thread))
|
||||
continue;
|
||||
throw new RuntimeException("Process thread[" + thread + "] is not exists");
|
||||
String value = ZKUtil
|
||||
.getPathData(Config.ZKPath.REGISTER_SERVER_PATH + "/"
|
||||
+ thread);
|
||||
|
|
@ -193,7 +193,7 @@ public class UserInfoCoordinator extends Thread {
|
|||
|
||||
if (!ZKUtil.exists(Config.ZKPath.REGISTER_SERVER_PATH + "/"
|
||||
+ threadId))
|
||||
continue;
|
||||
throw new RuntimeException("Process thread[" + threadId + "] is not exists");
|
||||
|
||||
if (getProcessThreadStatus(registerPathPrefix, threadId) != status) {
|
||||
return false;
|
||||
|
|
@ -241,4 +241,8 @@ public class UserInfoCoordinator extends Thread {
|
|||
logger.error("Failed to set watcher for get children", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void activateRedistribute() {
|
||||
redistributing = true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,56 @@
|
|||
package com.ai.cloud.skywalking.alarm;
|
||||
|
||||
import com.ai.cloud.skywalking.alarm.conf.Config;
|
||||
import com.ai.cloud.skywalking.alarm.dao.AlarmMessageDao;
|
||||
import com.ai.cloud.skywalking.alarm.util.ZKUtil;
|
||||
import org.apache.curator.framework.recipes.locks.InterProcessMutex;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class UserInfoInspectThread extends Thread {
|
||||
|
||||
private boolean isInspector = false;
|
||||
private InterProcessMutex inspectorLock = new InterProcessMutex(ZKUtil.getZkClient(),
|
||||
Config.ZKPath.INSPECTOR_LOCK_PATH);
|
||||
private int userHashCode;
|
||||
private Logger logger = LogManager.getLogger(UserInfoInspectThread.class);
|
||||
|
||||
public void run() {
|
||||
while (true) {
|
||||
try {
|
||||
// 探寻是否成为探测者
|
||||
if (!isInspector) {
|
||||
while (!inspectorLock.acquire(5, TimeUnit.SECONDS)) {
|
||||
Thread.sleep(Config.InspectThread.RETRY_GET_INSPECT_LOCK_INTERVAL);
|
||||
}
|
||||
|
||||
isInspector = true;
|
||||
userHashCode = AlarmMessageDao.selectAllUserIds().toString().hashCode();
|
||||
}
|
||||
|
||||
// 判断上次用户数量是否发生变化
|
||||
if (!checkUserNumber()) {
|
||||
Thread.sleep(Config.InspectThread.CHECK_USER_LIST_INTERVAL);
|
||||
continue;
|
||||
}
|
||||
logger.info("The number of users has changed, activated redistribution task");
|
||||
// 激活重分配
|
||||
UserInfoCoordinator.activateRedistribute();
|
||||
} catch (Exception e) {
|
||||
logger.error("Failed to inspect number of user.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean checkUserNumber() throws SQLException {
|
||||
int currentUserHashCode = AlarmMessageDao.selectAllUserIds().toString().hashCode();
|
||||
if (userHashCode == currentUserHashCode) {
|
||||
return false;
|
||||
}
|
||||
userHashCode = currentUserHashCode;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -11,12 +11,13 @@ public class Config {
|
|||
}
|
||||
|
||||
public static class ProcessThread {
|
||||
// public static long THREAD_WAIT_INTERVAL = 60 * 1000L;
|
||||
public static long THREAD_WAIT_INTERVAL = 5 * 1000L;
|
||||
public static long THREAD_WAIT_INTERVAL = 60 * 1000L;
|
||||
// public static long THREAD_WAIT_INTERVAL = 5 * 1000L;
|
||||
}
|
||||
|
||||
public static class ZKPath {
|
||||
|
||||
|
||||
public static String CONNECT_STR = "127.0.0.1:2181";
|
||||
|
||||
public static int CONNECT_TIMEOUT = 1000;
|
||||
|
|
@ -25,12 +26,11 @@ public class Config {
|
|||
|
||||
public static int RETRY_TIMES = 3;
|
||||
|
||||
public static String NODE_PREFIX = "/skywalking";
|
||||
public static String REGISTER_SERVER_PATH = "/skywalking/alarm-server/register-servers";
|
||||
|
||||
public static String REGISTER_SERVER_PATH = NODE_PREFIX + "/alarm-server/register-servers";
|
||||
|
||||
public static String COORDINATOR_PATH = NODE_PREFIX + "/alarm-server/coordinator/lock";
|
||||
public static String COORDINATOR_PATH = "/skywalking/alarm-server/coordinator/lock";
|
||||
|
||||
public static String INSPECTOR_LOCK_PATH = "/skywalking/alarm-server/user-inspector/lock";
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -59,8 +59,17 @@ public class Config {
|
|||
|
||||
public static int MAX_POOL_SIZE = 20;
|
||||
|
||||
public static long CONNECT_TIMEOUT = 10000;
|
||||
|
||||
}
|
||||
|
||||
public static class InspectThread {
|
||||
public static long RETRY_GET_INSPECT_LOCK_INTERVAL = 10000;
|
||||
|
||||
public static long CHECK_USER_LIST_INTERVAL = 5 * 60 * 1000;
|
||||
}
|
||||
|
||||
|
||||
public static class Alarm {
|
||||
|
||||
public static String REDIS_SERVER = "127.0.0.1:6379";
|
||||
|
|
@ -78,7 +87,7 @@ public class Config {
|
|||
public static String configId = "1000";
|
||||
}
|
||||
|
||||
public static class TemplateInfo{
|
||||
public static class TemplateInfo {
|
||||
public static String CONFIG_ID = "1001";
|
||||
}
|
||||
}
|
||||
|
|
@ -1,32 +1,16 @@
|
|||
package com.ai.cloud.skywalking.alarm.conf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class ConfigInitializer {
|
||||
private static Logger logger = Logger.getLogger(ConfigInitializer.class.getName());
|
||||
|
||||
public static void initialize() {
|
||||
InputStream inputStream = ConfigInitializer.class.getResourceAsStream("/sky-walking.auth");
|
||||
if (inputStream == null) {
|
||||
logger.log(Level.ALL, "No provider sky-walking certification documents, buried point won't work");
|
||||
} else {
|
||||
try {
|
||||
Properties properties = new Properties();
|
||||
properties.load(inputStream);
|
||||
initNextLevel(properties, Config.class, new ConfigDesc());
|
||||
} catch (IllegalAccessException e) {
|
||||
logger.log(Level.ALL, "Parsing certification file failed, buried won't work");
|
||||
} catch (IOException e) {
|
||||
logger.log(Level.ALL, "Failed to read the certification file, buried won't work");
|
||||
}
|
||||
}
|
||||
public static void initialize(Properties properties, Class<?> rootConfigType) throws IllegalAccessException {
|
||||
initNextLevel(properties, rootConfigType, new ConfigDesc());
|
||||
}
|
||||
|
||||
private static void initNextLevel(Properties properties, Class<?> recentConfigType, ConfigDesc parentDesc) throws NumberFormatException, IllegalArgumentException, IllegalAccessException {
|
||||
|
|
|
|||
|
|
@ -7,21 +7,25 @@ import com.ai.cloud.skywalking.alarm.util.DBConnectUtil;
|
|||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class AlarmMessageDao {
|
||||
|
||||
private static Logger logger = LogManager.getLogger(AlarmMessageDao.class);
|
||||
|
||||
|
||||
public static List<String> selectAllUserIds() {
|
||||
public static List<String> selectAllUserIds() throws SQLException {
|
||||
List<String> result = new ArrayList<String>();
|
||||
Connection connection = DBConnectUtil.getConnection();
|
||||
try {
|
||||
PreparedStatement ps = DBConnectUtil.getConnection().prepareStatement("SELECT user_info.uid FROM user_info WHERE sts = ?");
|
||||
PreparedStatement ps = connection.prepareStatement("SELECT user_info.uid FROM user_info WHERE sts = ?");
|
||||
ps.setString(1, "A");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
while (rs.next()) {
|
||||
|
|
@ -29,29 +33,21 @@ public class AlarmMessageDao {
|
|||
}
|
||||
} catch (SQLException e) {
|
||||
logger.error("Failed to select all user info", e);
|
||||
throw e;
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static int selectUserCount() {
|
||||
try {
|
||||
PreparedStatement ps = DBConnectUtil.getConnection().prepareStatement("SELECT count(user_info.uid) as totalNumber FROM user_info WHERE sts = ?");
|
||||
ps.setString(1, "A");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
rs.next();
|
||||
return rs.getInt("totalNumber");
|
||||
} catch (SQLException e) {
|
||||
logger.error("Failed to select all user info", e);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static UserInfo selectUser(String userId) {
|
||||
public static UserInfo selectUser(String userId) throws SQLException {
|
||||
UserInfo userInfo = null;
|
||||
Connection connection = DBConnectUtil.getConnection();
|
||||
try {
|
||||
PreparedStatement ps = DBConnectUtil.getConnection().prepareStatement("SELECT user_info.uid,user_info.user_name FROM user_info WHERE sts = ? AND uid = ?");
|
||||
PreparedStatement ps = connection.prepareStatement("SELECT user_info.uid,user_info.user_name FROM user_info WHERE sts = ? AND uid = ?");
|
||||
ps.setString(1, "A");
|
||||
ps.setString(2, userId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
|
|
@ -60,52 +56,47 @@ public class AlarmMessageDao {
|
|||
userInfo.setUserName(rs.getString("user_name"));
|
||||
} catch (SQLException e) {
|
||||
logger.error("Failed to select all user info", e);
|
||||
throw e;
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
|
||||
return userInfo;
|
||||
}
|
||||
|
||||
public static List<AlarmRule> selectAlarmRulesByUserId(String userId) {
|
||||
public static List<AlarmRule> selectAlarmRulesByUserId(String userId) throws SQLException {
|
||||
List<AlarmRule> rules = new ArrayList<AlarmRule>();
|
||||
List<ApplicationInfo> selfDefineApplications = new ArrayList<ApplicationInfo>();
|
||||
Connection connection = DBConnectUtil.getConnection();
|
||||
try {
|
||||
PreparedStatement ps = DBConnectUtil.getConnection().prepareStatement("SELECT alarm_rule.app_id,alarm_rule.rule_id, alarm_rule.uid,alarm_rule.is_global, alarm_rule.todo_type," +
|
||||
" alarm_rule.config_args FROM alarm_rule WHERE uid = ? AND sts = ?");
|
||||
PreparedStatement ps = connection.
|
||||
prepareStatement("SELECT alarm_rule.app_id,alarm_rule.rule_id, alarm_rule.uid,alarm_rule.is_global, alarm_rule.todo_type," +
|
||||
" alarm_rule.config_args FROM alarm_rule WHERE uid = ? AND sts = ?");
|
||||
ps.setString(1, userId);
|
||||
ps.setString(2, "A");
|
||||
ResultSet rs = ps.executeQuery();
|
||||
AlarmRule globalRules = null;
|
||||
AlarmRule tmpAlarmRule = null;
|
||||
ApplicationInfo tmpApplication;
|
||||
Map<String, AlarmRule> rulesMap = new HashMap<String, AlarmRule>();
|
||||
while (rs.next()) {
|
||||
tmpAlarmRule = new AlarmRule(rs.getString("uid"), rs.getString("rule_id"));
|
||||
tmpAlarmRule.setConfigArgs(rs.getString("config_args"));
|
||||
tmpAlarmRule.setTodoType(rs.getString("todo_type"));
|
||||
if ("1".equals(rs.getString("is_global"))) {
|
||||
globalRules = new AlarmRule(rs.getString("uid"), rs.getString("rule_id"));
|
||||
globalRules.setConfigArgs(rs.getString("config_args"));
|
||||
globalRules.setTodoType(rs.getString("todo_type"));
|
||||
globalRules.setGlobal(true);
|
||||
rulesMap.put("*", tmpAlarmRule);
|
||||
continue;
|
||||
} else {
|
||||
tmpAlarmRule = new AlarmRule(rs.getString("uid"), rs.getString("rule_id"));
|
||||
tmpAlarmRule.setConfigArgs(rs.getString("config_args"));
|
||||
tmpAlarmRule.setTodoType(rs.getString("todo_type"));
|
||||
// 自定义规则的Application
|
||||
tmpApplication = new ApplicationInfo();
|
||||
tmpApplication.setAppId(rs.getString("app_id"));
|
||||
tmpApplication.setUId(rs.getString("uid"));
|
||||
selfDefineApplications.add(tmpApplication);
|
||||
|
||||
tmpAlarmRule.getApplicationInfos().add(tmpApplication);
|
||||
rules.add(tmpAlarmRule);
|
||||
}
|
||||
}
|
||||
|
||||
if (globalRules == null) {
|
||||
//
|
||||
throw new IllegalArgumentException("Can not found the global config");
|
||||
tmpApplication = new ApplicationInfo();
|
||||
tmpApplication.setAppId(rs.getString("app_id"));
|
||||
tmpApplication.setUId(rs.getString("uid"));
|
||||
tmpAlarmRule.getApplicationInfos().add(tmpApplication);
|
||||
rulesMap.put(rs.getString("app_id"), tmpAlarmRule);
|
||||
}
|
||||
|
||||
List<ApplicationInfo> allApplication = new ArrayList<ApplicationInfo>();
|
||||
ps = DBConnectUtil.getConnection()
|
||||
ps = connection
|
||||
.prepareStatement("SELECT application_info.app_id, application_info.uid, app_code FROM application_info WHERE uid = ? AND sts = ?");
|
||||
ps.setString(1, userId);
|
||||
ps.setString(2, "A");
|
||||
|
|
@ -119,12 +110,44 @@ public class AlarmMessageDao {
|
|||
allApplication.add(applicationInfo);
|
||||
}
|
||||
|
||||
allApplication.removeAll(selfDefineApplications);
|
||||
globalRules.getApplicationInfos().addAll(allApplication);
|
||||
rules.add(globalRules);
|
||||
|
||||
for (ApplicationInfo app : allApplication) {
|
||||
tmpAlarmRule = rulesMap.get(app.getAppId());
|
||||
if (tmpAlarmRule != null) {
|
||||
tmpAlarmRule.getApplicationInfos().get(0).setAppCode(app.getAppCode());
|
||||
} else {
|
||||
rulesMap.get("*").getApplicationInfos().add(app);
|
||||
}
|
||||
}
|
||||
|
||||
rules.addAll(rulesMap.values());
|
||||
} catch (SQLException e) {
|
||||
logger.error("Failed to query applications.", e);
|
||||
throw e;
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
return rules;
|
||||
}
|
||||
|
||||
public static String selectAppCodeByAppId(String appId) throws SQLException {
|
||||
Connection connection = DBConnectUtil.getConnection();
|
||||
try {
|
||||
PreparedStatement ps =
|
||||
connection.prepareStatement("SELECT app_code FROM application_info WHERE sts = ? AND application_info.app_id = ?");
|
||||
ps.setString(1, "A");
|
||||
ps.setString(2, appId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
rs.next();
|
||||
return rs.getString("app_code");
|
||||
} catch (SQLException e) {
|
||||
throw e;
|
||||
} finally {
|
||||
if (connection != null) {
|
||||
connection.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
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;
|
||||
|
|
@ -7,10 +8,8 @@ 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;
|
||||
import freemarker.template.Version;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import redis.clients.jedis.Jedis;
|
||||
|
|
@ -21,13 +20,14 @@ import java.io.StringWriter;
|
|||
import java.sql.SQLException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class AlarmMessageProcessor {
|
||||
|
||||
private static Logger logger = LogManager
|
||||
.getLogger(AlarmMessageProcessor.class);
|
||||
|
||||
public void process(UserInfo userInfo, AlarmRule rule) {
|
||||
public void process(UserInfo userInfo, AlarmRule rule) throws TemplateException, IOException, SQLException {
|
||||
Set<String> warningTracingIds = new HashSet<String>();
|
||||
Set<String> warningMessageKeys = new HashSet<String>();
|
||||
long currentFireMinuteTime = System.currentTimeMillis() / (10000 * 6);
|
||||
|
|
@ -39,7 +39,7 @@ public class AlarmMessageProcessor {
|
|||
for (int period = 0; period < warningTimeWindowSize; period++) {
|
||||
String alarmKey = userInfo.getUserId()
|
||||
+ "-"
|
||||
+ applicationInfo.getAppId()
|
||||
+ applicationInfo.getAppCode()
|
||||
+ "-"
|
||||
+ (currentFireMinuteTime - period - 1);
|
||||
|
||||
|
|
@ -135,27 +135,24 @@ public class AlarmMessageProcessor {
|
|||
return result.keySet();
|
||||
}
|
||||
|
||||
private String generateContent(String templateStr, Map parameter) {
|
||||
private String generateContent(String templateStr, Map parameter) throws IOException, TemplateException, SQLException {
|
||||
Template t = null;
|
||||
try {
|
||||
t = new Template(null, new StringReader(templateStr), TemplateConfigurationUtil.getConfiguration());
|
||||
StringWriter out = new StringWriter();
|
||||
t.process(parameter, out);
|
||||
return out.getBuffer().toString();
|
||||
} catch (IOException e) {
|
||||
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");
|
||||
t = new Template(null, new StringReader(templateStr), TemplateConfigurationUtil.getConfiguration());
|
||||
StringWriter out = new StringWriter();
|
||||
t.process(parameter, out);
|
||||
return out.getBuffer().toString();
|
||||
}
|
||||
|
||||
private static Map<String, String> idCodeMapper = new ConcurrentHashMap<String, String>();
|
||||
|
||||
public static String convertAppId2AppCode(String appId) throws SQLException {
|
||||
String resultCode = idCodeMapper.get(appId);
|
||||
if (resultCode == null) {
|
||||
resultCode = AlarmMessageDao.selectAppCodeByAppId(appId);
|
||||
|
||||
idCodeMapper.put(appId, resultCode);
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(System.currentTimeMillis() / (10000 * 6));
|
||||
AlarmMessageProcessor processor = new AlarmMessageProcessor();
|
||||
processor.getAlarmMessages("27-order-application-24167725");
|
||||
return idCodeMapper.get(appId);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ public class DBConnectUtil {
|
|||
config.addDataSourceProperty("prepStmtCacheSize", "250");
|
||||
config.setMinimumIdle(Config.DB.MAX_IDLE);
|
||||
config.setMaximumPoolSize(Config.DB.MAX_POOL_SIZE);
|
||||
config.setConnectionTimeout(Config.DB.CONNECT_TIMEOUT);
|
||||
config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048");
|
||||
hikariDataSource = new HikariDataSource(config);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ public class MailUtil {
|
|||
message.addRecipients(Message.RecipientType.TO, recipientAccountArray);
|
||||
|
||||
InternetAddress[] ccAccountArray = new InternetAddress[ccList.length];
|
||||
for (int i = 0; i < recipientAccounts.length; i++) {
|
||||
for (int i = 0; i < ccList.length; i++) {
|
||||
ccAccountArray[i] = new InternetAddress(ccList[i]);
|
||||
}
|
||||
message.addRecipients(Message.RecipientType.CC, ccAccountArray);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
#告警处理线程数
|
||||
server.process_thread_size=1
|
||||
server.process_thread_size=2
|
||||
#守护线程等待周期
|
||||
server.daemon_thread_wait_interval=50000
|
||||
|
||||
#处理线程等待周期
|
||||
processthread.thread_wait_interval=60000
|
||||
processthread.thread_wait_interval=5000
|
||||
|
||||
#zookeeper连接地址
|
||||
zkpath.connect_str=127.0.0.1:2181
|
||||
zkpath.connect_str=10.1.235.197:29181,10.1.235.198:29181,10.1.235.199:29181
|
||||
#zookeeper连接超时时间(单位:毫秒)
|
||||
zkpath.connect_timeout=1000
|
||||
#zookeeper重试次数
|
||||
|
|
@ -31,30 +31,37 @@ coordinator.check_redistribute_interval=5000
|
|||
coordinator.check_all_process_thread_interval=500
|
||||
|
||||
#数据库驱动类
|
||||
db.driver_class=com.mysql.jdbc.driver
|
||||
db.driver_class=com.mysql.jdbc.Driver
|
||||
#数据库连接地址
|
||||
db.url=jdbc:mysql://10.1.228.200:31306/test
|
||||
db.url=jdbc:mysql://10.1.228.202:31316/test
|
||||
#数据库用户名
|
||||
db.user_name=devrdbusr13
|
||||
db.user_name=devrdbusr21
|
||||
#数据库密码
|
||||
db.password=devrdbusr13
|
||||
db.password=devrdbusr21
|
||||
#数据库连接最大空闲数
|
||||
db.max_idle=1
|
||||
#数据库最大连接数
|
||||
db.max_pool_size=20
|
||||
#数据连接超时时间
|
||||
db.connect_timeout=10000
|
||||
|
||||
#告警信息存在的redis服务器地址
|
||||
alarm.redis_server=
|
||||
alarm.redis_server=10.1.235.197:46379
|
||||
#redis的最大空闲连接数
|
||||
alarm.redis_max_idle=
|
||||
alarm.redis_max_idle=5
|
||||
#redis的最小空闲连接数
|
||||
alarm.redis_min_idle=
|
||||
alarm.redis_min_idle=1
|
||||
#redis最大连接数
|
||||
alarm.redis_max_total=
|
||||
alarm.redis_max_total=20
|
||||
#是否关闭告警发送
|
||||
alarm.alarm_off_flag=false
|
||||
|
||||
#邮件发送配置id
|
||||
mailsenderinfo.configid=1000
|
||||
#邮件模板配置id
|
||||
templateinfo.config_id=1001
|
||||
templateinfo.config_id=1001
|
||||
|
||||
#尝试获取轮询锁的周期(单位:毫秒)
|
||||
inspectthread.retry_get_inspect_lock_interval=10000
|
||||
#尝试检查用户列表的周期(单位:毫秒)
|
||||
inspectthread.check_user_list_interval=300000
|
||||
Loading…
Reference in New Issue