using RestartService.Alarm; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace RestartService.Monitor { public class ServerMonitor { /// /// 发送时间 /// public static DateTime sendTime; /// /// 发送了多少次 /// public static int ServerSendCount; /// /// 网络延迟次数 /// public static int InternetDeleyCount; /// /// 监控数据转发服务 /// public static void monitorServer() { new Thread(new ThreadStart(() => { while (true) { try { var sendBytes = new byte[29]; var groupNameBytes = Encoding.Default.GetBytes("HDL"); Array.Copy(groupNameBytes, 0, sendBytes, 9, groupNameBytes.Length); sendBytes = Packet.SendBytes(sendBytes, 0x3011, 42, 0); UDPServer.AsyncBeginSend(new Packet { Bytes = sendBytes, RemoteEndPoint = new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ConfigurationManager.AppSettings["ServerIp"]), 9999) }); sendTime = DateTime.Now; ServerSendCount++; //超过6次有问题 if (ServerSendCount > 5 && ServerSendCount % 6 == 0) { AlarmHp.ServiceAlarm("Server", "服务已经6次没有响应,请尽快检查!","157.175.231.123," + ConfigurationManager.AppSettings["ServerIp"], "国外-旧服务器数据转发服务"); } } catch (Exception ex) { LogHp.WriteLog("UDP服务异常", Newtonsoft.Json.JsonConvert.SerializeObject(ex)); } Thread.Sleep(1000 * 10); } })) { IsBackground = true }.Start(); } } }