// all the exceptions are sent, because they are important Even if many happens in a 30 minutes period public static void SendException(string p_locationMsg, Exception e, HealthMonitorMessageID p_healthMonId) { //Utils.Logger.Warn($"HealthMonitorMessage.SendException(). Crash in { p_locationMsg}. Exception Message: '{ e.Message}', StackTrace: { e.StackTrace}"); Utils.Logger.Warn($"HealthMonitorMessage.SendException(): Exception occured in {p_locationMsg}. Exception: '{ e.ToString()}'"); if (!(new HealthMonitorMessage() { ID = p_healthMonId, ParamStr = $"Exception in {p_locationMsg}. Exception: '{ e.ToStringWithShortenedStackTrace(400)}'", ResponseFormat = HealthMonitorMessageResponseFormat.None }.SendMessage().Result)) { Utils.Logger.Error("Error in sending HealthMonitorMessage to Server."); } }
static DateTime gLastMessageTime = DateTime.MinValue; // be warned, this is global for the whole App; better to not use it, because messages can be swallowed silently. HealthMonitor itself should decide if it swallows it or not, and not the SenderApp. // A syntactic sugar so callers don't have to give parameters all the time as: ServerIp.HealthMonitorPublicIp, ServerIp.DefaultHealthMonitorServerPort, TcpMessageResponseFormat.None public static async Task SendAsync(string p_fullMsg, HealthMonitorMessageID p_healthMonId, TimeSpan?p_globalMinTimeBetweenMessages = null) { // p_globalMinTimeBetweenMessages: In general try to send All the exceptions and messages to HealthMonitor, even though it is CPU busy. It will be network busy anyway. It is the responsibility of HealthMonitor to decide their fate. // VBroker or SQLab website don't use p_globalMinTimeBetweenMessages, but maybe other crawler Apps will use it in the future. So keep the functionality, but without strong reason don't use it. Utils.Logger.Warn($"HealthMonitorMessage.SendAsync(): Message: '{ p_fullMsg}'"); TimeSpan globalMinTimeBetweenMessages = p_globalMinTimeBetweenMessages ?? TimeSpan.MinValue; if ((DateTime.UtcNow - gLastMessageTime) > globalMinTimeBetweenMessages) // don't send it in every minute, just after e.g. 30 minutes { Task <string?> tcpMsgTask = TcpMessage.Send(p_fullMsg, (int)p_healthMonId, ServerIp.HealthMonitorPublicIp, ServerIp.DefaultHealthMonitorServerPort, TcpMessageResponseFormat.None); string? tcpMsgResponse = await tcpMsgTask; if (tcpMsgTask.Exception != null || String.IsNullOrEmpty(tcpMsgResponse)) { Utils.Logger.Error($"Error. HealthMonitorMessage.SendAsync() to {ServerIp.HealthMonitorPublicIp}:{ServerIp.DefaultHealthMonitorServerPort}"); } } gLastMessageTime = DateTime.UtcNow; }
public static async void Send(string p_locationMsg, string p_msg, HealthMonitorMessageID p_healthMonId) { //Utils.Logger.Warn($"HealthMonitorMessage.SendException(). Crash in { p_locationMsg}. Exception Message: '{ e.Message}', StackTrace: { e.StackTrace}"); Utils.Logger.Warn($"HealthMonitorMessage.Send(): Msg from {p_locationMsg}. Message: '{ p_msg}'"); if ((DateTime.UtcNow - gLastMessageTime).TotalMinutes > 30) // don't send it in every minute, just after 30 minutes { var t = (new HealthMonitorMessage() { ID = p_healthMonId, ParamStr = $"Msg from {p_locationMsg}. {p_msg}", ResponseFormat = HealthMonitorMessageResponseFormat.None }.SendMessage()); if (!(await t)) { Utils.Logger.Error("Error in sending HealthMonitorMessage to Server."); } gLastMessageTime = DateTime.UtcNow; } }
public static void SendStrongAssert(string p_locationMsg, StrongAssertMessage p_msg, HealthMonitorMessageID p_healthMonId) { Send(p_locationMsg, $"StrongAssert. Severity: {p_msg.Severity}, Message { p_msg.Message}, StackTrace: { p_msg.StackTrace}", p_healthMonId); }