From 31d69e78cff2ca1ffe08b281a44eda265b465481 Mon Sep 17 00:00:00 2001 From: heavyrain2012 Date: Sat, 12 Dec 2020 16:15:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=82=E5=B8=B8=E6=8A=A5=E8=AD=A6=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- broker/config/wildfirechat.conf | 5 + .../java/cn/wildfirechat/push/PushServer.java | 5 +- .../action/admin/CreateRobotAction.java | 3 +- .../action/admin/CreateUserAction.java | 4 +- .../action/channel/ChannelAction.java | 4 +- .../loServer/action/robot/RobotAction.java | 6 +- .../loServer/handler/ActionHandler.java | 8 +- .../java/io/moquette/BrokerConstants.java | 3 + .../moquette/persistence/DatabaseStore.java | 158 +++++++++--------- .../persistence/MemoryMessagesStore.java | 65 ++++++- .../main/java/io/moquette/server/Server.java | 3 + .../moquette/spi/impl/MessagesPublisher.java | 37 +++- .../moquette/spi/impl/ProtocolProcessor.java | 11 +- .../src/main/java/win/liyufan/im/Utility.java | 81 ++++++++- .../wildfirechat/common/IMExceptionEvent.java | 21 +++ .../src/main/resources/wildfirechat.conf | 5 + 16 files changed, 310 insertions(+), 109 deletions(-) create mode 100644 common/src/main/java/cn/wildfirechat/common/IMExceptionEvent.java diff --git a/broker/config/wildfirechat.conf b/broker/config/wildfirechat.conf index 7cab562e..97dbb0b7 100755 --- a/broker/config/wildfirechat.conf +++ b/broker/config/wildfirechat.conf @@ -185,6 +185,11 @@ push.android.server.address http://localhost:8085/android/push ##注意回调是单线程回调,接收服务必须在同一内网,且异步处理快速返回,否则会有延迟问题!! push.ios.server.address http://localhost:8085/ios/push +#********************************************************************* +# 监控配置 +#********************************************************************* +#monitor.exception_event_address http://localhost:8888/im_exception_event/ + #********************************************************************* # 各种事件回调 #********************************************************************* diff --git a/broker/src/main/java/cn/wildfirechat/push/PushServer.java b/broker/src/main/java/cn/wildfirechat/push/PushServer.java index 9e9880f6..5beaf361 100644 --- a/broker/src/main/java/cn/wildfirechat/push/PushServer.java +++ b/broker/src/main/java/cn/wildfirechat/push/PushServer.java @@ -8,12 +8,11 @@ package cn.wildfirechat.push; +import cn.wildfirechat.common.IMExceptionEvent; import cn.wildfirechat.proto.ProtoConstants; -import cn.wildfirechat.proto.WFCMessage; import com.google.gson.Gson; import io.moquette.persistence.MemorySessionStore; import io.moquette.server.config.IConfig; -import io.moquette.spi.ClientSession; import io.moquette.spi.ISessionsStore; import io.netty.util.internal.StringUtil; import org.slf4j.Logger; @@ -64,7 +63,7 @@ public class PushServer { pushMessageInternel(pushMessage, deviceId, pushContent); } catch (Exception e) { e.printStackTrace(); - Utility.printExecption(LOG, e); + Utility.printExecption(LOG, e, IMExceptionEvent.EventType.PUSH_SERVER_Exception); } }); } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateRobotAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateRobotAction.java index 827185b7..910affda 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateRobotAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateRobotAction.java @@ -9,6 +9,7 @@ package com.xiaoleilu.loServer.action.admin; import cn.wildfirechat.common.APIPath; +import cn.wildfirechat.common.IMExceptionEvent; import cn.wildfirechat.proto.WFCMessage; import com.google.gson.Gson; import com.xiaoleilu.loServer.RestResult; @@ -63,7 +64,7 @@ public class CreateRobotAction extends AdminAction { messagesStore.addUserInfo(newUser, inputCreateRobot.getPassword()); } catch (Exception e) { e.printStackTrace(); - Utility.printExecption(LOG, e); + Utility.printExecption(LOG, e, IMExceptionEvent.EventType.ADMIN_API_Exception); response.setStatus(HttpResponseStatus.OK); RestResult result = RestResult.resultOf(ErrorCode.ERROR_CODE_SERVER_ERROR, e.getMessage()); response.setContent(new Gson().toJson(result)); diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateUserAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateUserAction.java index 8e15e17f..163d71f1 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateUserAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/admin/CreateUserAction.java @@ -9,6 +9,7 @@ package com.xiaoleilu.loServer.action.admin; import cn.wildfirechat.common.APIPath; +import cn.wildfirechat.common.IMExceptionEvent; import cn.wildfirechat.proto.ProtoConstants; import cn.wildfirechat.proto.WFCMessage; import com.google.gson.Gson; @@ -25,7 +26,6 @@ import io.netty.util.internal.StringUtil; import cn.wildfirechat.common.ErrorCode; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import win.liyufan.im.DBUtil; import win.liyufan.im.UUIDGenerator; import win.liyufan.im.Utility; @@ -88,7 +88,7 @@ public class CreateUserAction extends AdminAction { messagesStore.addUserInfo(newUserBuilder.build(), inputCreateUser.getPassword()); } catch (Exception e) { e.printStackTrace(); - Utility.printExecption(LOG, e); + Utility.printExecption(LOG, e, IMExceptionEvent.EventType.ADMIN_API_Exception); response.setStatus(HttpResponseStatus.OK); RestResult result = RestResult.resultOf(ErrorCode.ERROR_CODE_SERVER_ERROR, e.getMessage()); response.setContent(new Gson().toJson(result)); diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/ChannelAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/ChannelAction.java index 767d3d4a..61b92b68 100644 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/channel/ChannelAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/channel/ChannelAction.java @@ -8,11 +8,11 @@ package com.xiaoleilu.loServer.action.channel; +import cn.wildfirechat.common.IMExceptionEvent; import cn.wildfirechat.proto.WFCMessage; import com.google.gson.Gson; import com.xiaoleilu.loServer.RestResult; import com.xiaoleilu.loServer.action.Action; -import com.xiaoleilu.loServer.action.admin.AdminAction; import com.xiaoleilu.loServer.handler.Request; import com.xiaoleilu.loServer.handler.Response; import io.moquette.spi.impl.Utils; @@ -63,7 +63,7 @@ abstract public class ChannelAction extends Action { ts = Long.parseLong(timestamp); } catch (Exception e) { e.printStackTrace(); - Utility.printExecption(LOG, e); + Utility.printExecption(LOG, e, IMExceptionEvent.EventType.CHANNEL_API_Exception); return ErrorCode.INVALID_PARAMETER; } diff --git a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/RobotAction.java b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/RobotAction.java index 76d11c2c..3dbf5ca6 100644 --- a/broker/src/main/java/com/xiaoleilu/loServer/action/robot/RobotAction.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/action/robot/RobotAction.java @@ -8,13 +8,13 @@ package com.xiaoleilu.loServer.action.robot; +import cn.wildfirechat.common.IMExceptionEvent; import cn.wildfirechat.proto.WFCMessage; import com.google.gson.Gson; import com.xiaoleilu.loServer.RestResult; import com.xiaoleilu.loServer.action.Action; import com.xiaoleilu.loServer.handler.Request; import com.xiaoleilu.loServer.handler.Response; -import io.moquette.imhandler.IMHandler; import io.moquette.spi.impl.Utils; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpRequest; @@ -67,7 +67,7 @@ abstract public class RobotAction extends Action { ts = Long.parseLong(timestamp); } catch (Exception e) { e.printStackTrace(); - Utility.printExecption(LOG, e); + Utility.printExecption(LOG, e, IMExceptionEvent.EventType.ROBOT_API_Exception); return ErrorCode.INVALID_PARAMETER; } @@ -112,7 +112,7 @@ abstract public class RobotAction extends Action { return t; } catch (UnsupportedEncodingException e) { e.printStackTrace(); - Utility.printExecption(LOG, e); + Utility.printExecption(LOG, e, IMExceptionEvent.EventType.ROBOT_API_Exception); } } return null; diff --git a/broker/src/main/java/com/xiaoleilu/loServer/handler/ActionHandler.java b/broker/src/main/java/com/xiaoleilu/loServer/handler/ActionHandler.java index 5cdb8287..eca67cf2 100755 --- a/broker/src/main/java/com/xiaoleilu/loServer/handler/ActionHandler.java +++ b/broker/src/main/java/com/xiaoleilu/loServer/handler/ActionHandler.java @@ -1,11 +1,7 @@ package com.xiaoleilu.loServer.handler; -import java.io.IOException; - -import com.hazelcast.core.HazelcastInstance; +import cn.wildfirechat.common.IMExceptionEvent; import com.xiaoleilu.hutool.lang.Singleton; -import com.xiaoleilu.hutool.log.Log; -import com.xiaoleilu.hutool.log.StaticLog; import com.xiaoleilu.loServer.ServerSetting; import com.xiaoleilu.loServer.action.Action; import com.xiaoleilu.loServer.action.UnknownErrorAction; @@ -53,7 +49,7 @@ abstract public class ActionHandler extends SimpleChannelInboundHandler HttpUtils.httpJsonPost(mGroupInfoUpdateCallback, new Gson().toJson(event))); + m_Server.getCallbackScheduler().execute(() -> { + try { + HttpUtils.httpJsonPost(mGroupInfoUpdateCallback, new Gson().toJson(event)); + } catch (Exception e) { + e.printStackTrace(); + Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception); + } + }); } } @@ -930,7 +939,14 @@ public class MemoryMessagesStore implements IMessagesStore { event.memberIds = memberIds; event.type = type; event.value = value; - m_Server.getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(mGroupMemberUpdateCallback, new Gson().toJson(event))); + m_Server.getCallbackScheduler().execute(() -> { + try { + HttpUtils.httpJsonPost(mGroupMemberUpdateCallback, new Gson().toJson(event)); + } catch (Exception e) { + e.printStackTrace(); + Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception); + } + }); } } @@ -941,13 +957,27 @@ public class MemoryMessagesStore implements IMessagesStore { event.targetId = targetId; event.type = type; event.value = value; - m_Server.getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(mRelationUpdateCallback, new Gson().toJson(event))); + m_Server.getCallbackScheduler().execute(() -> { + try { + HttpUtils.httpJsonPost(mRelationUpdateCallback, new Gson().toJson(event)); + } catch (Exception e) { + e.printStackTrace(); + Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception); + } + }); } } private void callbackUserInfoEvent(WFCMessage.User user) { if (!StringUtil.isNullOrEmpty(mUserInfoUpdateCallback)) { - m_Server.getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(mUserInfoUpdateCallback, new Gson().toJson(InputOutputUserInfo.fromPbUser(user)))); + m_Server.getCallbackScheduler().execute(() -> { + try { + HttpUtils.httpJsonPost(mUserInfoUpdateCallback, new Gson().toJson(InputOutputUserInfo.fromPbUser(user))); + } catch (Exception e) { + e.printStackTrace(); + Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception); + } + }); } } @@ -957,7 +987,14 @@ public class MemoryMessagesStore implements IMessagesStore { event.operatorId = operatorId; event.channelId = channelId; event.type = type; - m_Server.getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(mChannelInfoUpdateCallback, new Gson().toJson(event))); + m_Server.getCallbackScheduler().execute(() -> { + try { + HttpUtils.httpJsonPost(mChannelInfoUpdateCallback, new Gson().toJson(event)); + } catch (Exception e) { + e.printStackTrace(); + Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception); + } + }); } } @@ -966,7 +1003,14 @@ public class MemoryMessagesStore implements IMessagesStore { ChatroomUpdateEvent event = new ChatroomUpdateEvent(); event.chatroomId = chatroomId; event.type = type; - m_Server.getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(mChatroomInfoUpdateCallback, new Gson().toJson(event))); + m_Server.getCallbackScheduler().execute(() -> { + try { + HttpUtils.httpJsonPost(mChatroomInfoUpdateCallback, new Gson().toJson(event)); + } catch (Exception e) { + e.printStackTrace(); + Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception); + } + }); } } @@ -977,7 +1021,14 @@ public class MemoryMessagesStore implements IMessagesStore { event.chatroomId = chatroomId; event.memberIds = memberIds; event.type = type; - m_Server.getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(mChatroomMemberUpdateCallback, new Gson().toJson(event))); + m_Server.getCallbackScheduler().execute(() -> { + try { + HttpUtils.httpJsonPost(mChatroomMemberUpdateCallback, new Gson().toJson(event)); + } catch (Exception e) { + e.printStackTrace(); + Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception); + } + }); } } diff --git a/broker/src/main/java/io/moquette/server/Server.java b/broker/src/main/java/io/moquette/server/Server.java index db3593d2..3ebaf282 100755 --- a/broker/src/main/java/io/moquette/server/Server.java +++ b/broker/src/main/java/io/moquette/server/Server.java @@ -253,6 +253,9 @@ public class Server { initMediaServerConfig(config); + String monitorEventAddress = config.getProperty(MONITOR_Exception_Event_Address); + Utility.setMonitorEventAddress(monitorEventAddress); + final String persistencePath = config.getProperty(BrokerConstants.PERSISTENT_STORE_PROPERTY_NAME); LOG.info("Configuring Using persistent store file, path={}", persistencePath); m_store = initStore(config, this); diff --git a/broker/src/main/java/io/moquette/spi/impl/MessagesPublisher.java b/broker/src/main/java/io/moquette/spi/impl/MessagesPublisher.java index 7b373f33..ae3faf80 100755 --- a/broker/src/main/java/io/moquette/spi/impl/MessagesPublisher.java +++ b/broker/src/main/java/io/moquette/spi/impl/MessagesPublisher.java @@ -49,6 +49,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.function.BiFunction; +import static cn.wildfirechat.common.IMExceptionEvent.EventType.EVENT_CALLBACK_Exception; import static cn.wildfirechat.proto.ProtoConstants.PersistFlag.Transparent; public class MessagesPublisher { @@ -176,7 +177,14 @@ public class MessagesPublisher { message = m_messagesStore.getMessage(messageHead); } final WFCMessage.Message finalMsg = message; - Server.getServer().getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(robot.getCallback(), new Gson().toJson(SendMessageData.fromProtoMessage(finalMsg), SendMessageData.class))); + Server.getServer().getCallbackScheduler().execute(() -> { + try { + HttpUtils.httpJsonPost(robot.getCallback(), new Gson().toJson(SendMessageData.fromProtoMessage(finalMsg), SendMessageData.class)); + } catch (Exception e) { + e.printStackTrace(); + Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception); + } + }); continue; } } @@ -540,7 +548,14 @@ public class MessagesPublisher { if (message.getConversation().getType() == ProtoConstants.ConversationType.ConversationType_Channel) { WFCMessage.ChannelInfo channelInfo = m_messagesStore.getChannelInfo(message.getConversation().getTarget()); if (channelInfo != null && !StringUtil.isNullOrEmpty(channelInfo.getCallback())) { - Server.getServer().getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(channelInfo.getCallback() + "/message", new Gson().toJson(SendMessageData.fromProtoMessage(message), SendMessageData.class))); + Server.getServer().getCallbackScheduler().execute(() -> { + try { + HttpUtils.httpJsonPost(channelInfo.getCallback() + "/message", new Gson().toJson(SendMessageData.fromProtoMessage(message), SendMessageData.class)); + } catch (Exception e) { + e.printStackTrace(); + Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception); + } + }); } } long messageId = message.getMessageId(); @@ -580,7 +595,14 @@ public class MessagesPublisher { } public void forwardMessage(final WFCMessage.Message message, String forwardUrl) { - Server.getServer().getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(forwardUrl, new Gson().toJson(OutputMessageData.fromProtoMessage(message), OutputMessageData.class))); + Server.getServer().getCallbackScheduler().execute(() -> { + try { + HttpUtils.httpJsonPost(forwardUrl, new Gson().toJson(OutputMessageData.fromProtoMessage(message), OutputMessageData.class)); + } catch (Exception e) { + e.printStackTrace(); + Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception); + } + }); } public void notifyChannelListenStatusChanged(WFCMessage.ChannelInfo channelInfo, String user, boolean listen) { @@ -588,6 +610,13 @@ public class MessagesPublisher { return; } - Server.getServer().getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(channelInfo.getCallback() + "/subscribe", new Gson().toJson(new OutputNotifyChannelSubscribeStatus(user, channelInfo.getTargetId(), listen), OutputNotifyChannelSubscribeStatus.class))); + Server.getServer().getCallbackScheduler().execute(() -> { + try { + HttpUtils.httpJsonPost(channelInfo.getCallback() + "/subscribe", new Gson().toJson(new OutputNotifyChannelSubscribeStatus(user, channelInfo.getTargetId(), listen), OutputNotifyChannelSubscribeStatus.class)); + } catch (Exception e) { + e.printStackTrace(); + Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception); + } + }); } } diff --git a/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java b/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java index 77309555..c6295682 100755 --- a/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java +++ b/broker/src/main/java/io/moquette/spi/impl/ProtocolProcessor.java @@ -17,7 +17,6 @@ package io.moquette.spi.impl; import cn.wildfirechat.common.ErrorCode; -import cn.wildfirechat.pojos.SendMessageData; import cn.wildfirechat.pojos.UserOnlineStatus; import cn.wildfirechat.proto.ProtoConstants; import cn.wildfirechat.proto.WFCMessage; @@ -54,6 +53,7 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import static io.moquette.spi.impl.InternalRepublisher.createPublishForQos; +import static cn.wildfirechat.common.IMExceptionEvent.EventType.EVENT_CALLBACK_Exception; import static io.moquette.spi.impl.Utils.readBytesAndRewind; import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.*; import static io.netty.handler.codec.mqtt.MqttMessageIdVariableHeader.from; @@ -252,7 +252,14 @@ public class ProtocolProcessor { public void forwardOnlineStatusEvent(String userId, String clientId, int platform, int status, String packageName) { if (!StringUtil.isNullOrEmpty(mUserOnlineStatusCallback)) { - mServer.getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(mUserOnlineStatusCallback, new Gson().toJson(new UserOnlineStatus(userId, clientId, platform, status, packageName)))); + mServer.getCallbackScheduler().execute(() -> { + try { + HttpUtils.httpJsonPost(mUserOnlineStatusCallback, new Gson().toJson(new UserOnlineStatus(userId, clientId, platform, status, packageName))); + } catch (Exception e) { + e.printStackTrace(); + Utility.printExecption(LOG, e, EVENT_CALLBACK_Exception); + } + }); } } diff --git a/broker/src/main/java/win/liyufan/im/Utility.java b/broker/src/main/java/win/liyufan/im/Utility.java index a0cedf1b..6a63afda 100644 --- a/broker/src/main/java/win/liyufan/im/Utility.java +++ b/broker/src/main/java/win/liyufan/im/Utility.java @@ -8,12 +8,35 @@ package win.liyufan.im; +import cn.wildfirechat.common.IMExceptionEvent; +import com.google.gson.Gson; +import com.hazelcast.util.StringUtil; +import io.moquette.server.Server; import org.slf4j.Logger; import java.net.*; -import java.util.Enumeration; +import java.util.*; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; public class Utility { + private static Map exceptionEventHashMap = new ConcurrentHashMap<>(); + static AtomicLong SendExceptionExpireTime = new AtomicLong(0); + static int SendExceptionDuration = 60000; + static long lastSendTime = System.currentTimeMillis(); + static { + new Thread(()->{ + while (true) { + try { + Thread.sleep(10 * 1000); + sendExceptionEvent(); + } catch (Exception e) { + e.printStackTrace(); + } + + } + }).start(); + } public static InetAddress getLocalAddress(){ try { Enumeration b = NetworkInterface.getNetworkInterfaces(); @@ -29,6 +52,10 @@ public class Utility { } public static void printExecption(Logger LOG, Exception e) { + printExecption(LOG, e, 0); + } + + public static void printExecption(Logger LOG, Exception e, int eventType) { String message = ""; for(StackTraceElement stackTraceElement : e.getStackTrace()) { @@ -36,6 +63,58 @@ public class Utility { } LOG.error("Exception: {}", e.getMessage()); LOG.error(message); + if(eventType > 0) { + String key = eventType+(e.getMessage() != null ? e.getMessage().split("\n")[0] : "null"); + IMExceptionEvent event = exceptionEventHashMap.get(key); + if(event == null) { + event = new IMExceptionEvent(); + event.event_type = eventType; + event.msg = e.getMessage(); + event.call_stack = message; + event.count = 0; + + exceptionEventHashMap.put(key, event); + } + event.count++; + + sendExceptionEvent(); + } + } + + private static String gMonitorEventAddress; + + public static void setMonitorEventAddress(String gMonitorEventAddress) { + Utility.gMonitorEventAddress = gMonitorEventAddress; + } + + private static void sendExceptionEvent() { + if(StringUtil.isNullOrEmpty(gMonitorEventAddress)) { + return; + } + + long now = System.currentTimeMillis(); + long t = SendExceptionExpireTime.getAndUpdate((long l) -> now - l >= SendExceptionDuration ? now : l); + + if(now - t >= SendExceptionDuration) { + for (Map.Entry entry : exceptionEventHashMap.entrySet()) { + if(entry.getValue().count > 0) { + String jsonStr = new Gson().toJson(entry.getValue()); + Server.getServer().getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(gMonitorEventAddress, jsonStr)); + entry.getValue().count = 0; + lastSendTime = now; + } + } + if(now - lastSendTime > 24 * 3600 * 1000) { + lastSendTime = now; + IMExceptionEvent event = new IMExceptionEvent(); + event.event_type = 0; + event.msg = "监控心跳通知"; + event.call_stack = "别担心!这个是心跳消息,已经有24小时没有出现异常消息了!"; + event.count = IMExceptionEvent.EventType.HEART_BEAT; + String jsonStr = new Gson().toJson(event); + Server.getServer().getCallbackScheduler().execute(() -> HttpUtils.httpJsonPost(gMonitorEventAddress, jsonStr)); + } + } } public static String getMacAddress() throws UnknownHostException, diff --git a/common/src/main/java/cn/wildfirechat/common/IMExceptionEvent.java b/common/src/main/java/cn/wildfirechat/common/IMExceptionEvent.java new file mode 100644 index 00000000..607838d7 --- /dev/null +++ b/common/src/main/java/cn/wildfirechat/common/IMExceptionEvent.java @@ -0,0 +1,21 @@ +package cn.wildfirechat.common; + +public class IMExceptionEvent { + public interface EventType { + int RDBS_Exception = 1; + int MONGO_Exception = 2; + int RPC_Exception = 3; + int PUSH_SERVER_Exception = 4; + int ADMIN_API_Exception = 5; + int CHANNEL_API_Exception = 6; + int ROBOT_API_Exception = 7; + int SHORT_LINK_Exception = 8; + int EVENT_CALLBACK_Exception = 9; + int HEART_BEAT = 100; + } + + public int event_type; + public String msg; + public String call_stack; + public int count; +} diff --git a/distribution/src/main/resources/wildfirechat.conf b/distribution/src/main/resources/wildfirechat.conf index 1fc4388d..d61e94d5 100755 --- a/distribution/src/main/resources/wildfirechat.conf +++ b/distribution/src/main/resources/wildfirechat.conf @@ -180,6 +180,11 @@ push.android.server.address http://localhost:8085/android/push ##注意回调是单线程回调,接收服务必须在同一内网,且异步处理快速返回,否则会有延迟问题!! push.ios.server.address http://localhost:8085/ios/push +#********************************************************************* +# 监控配置 +#********************************************************************* +#monitor.exception_event_address http://localhost:8888/im_exception_event/ + #********************************************************************* # 各种事件回调 #*********************************************************************