protected override void Run() { try { if (GlobalNodeConfig.NodeInfo.ifmonitor == 0) { return; } if (pcounts.Count <= 0) { return; } tb_nodeperformance model = new tb_nodeperformance(); string fileinstallpath = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\'); double dirsizeM = -1; if (System.IO.Directory.Exists(fileinstallpath)) { long dirsize = IOHelper.DirSize(new DirectoryInfo(fileinstallpath)); dirsizeM = (double)dirsize / 1024 / 1024; model.installdirsize = (double)dirsizeM; } foreach (var p in pcounts) { var c = p.Collect(); if (p.Name.Contains("cpu")) { model.cpu = (double)c; } else if (p.Name.Contains("内存")) { model.memory = (double)c; } else if (p.Name.Contains("网络发送")) { model.networkupload = (double)c; } else if (p.Name.Contains("网络下载")) { model.networkdownload = (double)c; } else if (p.Name.Contains("物理磁盘读")) { model.ioread = (double)c; } else if (p.Name.Contains("物理磁盘写")) { model.iowrite = (double)c; } else if (p.Name.Contains("IIS请求")) { model.iisrequest = (double)c; } } model.nodeid = GlobalNodeConfig.NodeID; model.lastupdatetime = DateTime.Now; AddNodePerformanceRequest req = new AddNodePerformanceRequest() { NodePerformance = model, Source = Source.Node, MonitorClassName = this.GetType().Name }; var r = NodeProxy.PostToServer <EmptyResponse, AddNodePerformanceRequest>(ProxyUrl.AddNodePerformance_Url, req); if (r.Status != ResponesStatus.Success) { LogProxy.AddNodeErrorLog("节点性能上报出错,请求地址:" + ProxyUrl.AddNodePerformance_Url + ",请求内容:" + JsonConvert.SerializeObject(req) + ",返回结果:" + JsonConvert.SerializeObject(r)); } } catch (Exception ex) { LogProxy.AddNodeErrorLog("节点性能监控时出错:nodeid=" + GlobalNodeConfig.NodeID + ",异常信息:" + JsonConvert.SerializeObject(ex)); } }
public void Start() { //OnInit("\r\n"); // OnInit("\r\n"); OnInit("----------------------" + DateTime.Now + ":初始化节点开始-----------------------------------------"); try { OnInit("**开始请求节点配置信息**"); if (System.Configuration.ConfigurationSettings.AppSettings.AllKeys.Contains("NodeID")) { GlobalNodeConfig.NodeID = Convert.ToInt32(System.Configuration.ConfigurationSettings.AppSettings["NodeID"]); } var r = NodeProxy.PostToServer <LoadNodeConfigResponse, LoadNodeConfigRequest>(ProxyUrl.LoadNodeConfig_Url, new LoadNodeConfigRequest() { NodeId = GlobalNodeConfig.NodeID.ToString(), Source = Source.Node }); if (r.Status != ResponesStatus.Success) { //记录日志,并抛出异常 LogProxy.AddNodeErrorLog("请求" + ProxyUrl.LoadNodeConfig_Url + "获取节点配置失败,服务端返回信息:" + JsonConvert.SerializeObject(r)); throw new Exception("请求" + ProxyUrl.LoadNodeConfig_Url + "获取节点配置失败,服务端返回信息:" + JsonConvert.SerializeObject(r)); } GlobalNodeConfig.NodeInfo = r.Data.Node; GlobalNodeConfig.Alarm = r.Data.AlarmPerson.ToString(); if (GlobalNodeConfig.NodeID <= 0) { GlobalNodeConfig.NodeID = r.Data.Node.id; } //初始化配置信息 OnInit("**请求节点配置信息完成,请求结果:" + JsonConvert.SerializeObject(r) + "**"); //初始化命令池 OnInit("**开启初始化节点命令池**"); ICommandPoolBuilder builder = new CommandPoolBuilder(); builder.OnInitEvent += builder_OnInitEvent; builder.BuildCommandPool(); OnInit("**初始化节点命令池完成:本地节点命令池数量:" + CommandPoolManager.CreateInstance().GetList().Count + "**"); OnInit("**开始初始化监控线程**"); //初始化监控信息 GlobalNodeConfig.Monitors.Add(new NodeHeartBeatMonitor()); //心跳 GlobalNodeConfig.Monitors.Add(new TaskPerformanceMonitor()); //任务性能监控 GlobalNodeConfig.Monitors.Add(new NodePerformanceMonitor()); //节点性能监控 GlobalNodeConfig.Monitors.Add(new NodeTaskSchedulingMonitor()); //节点调度中的任务监控 GlobalNodeConfig.Monitors.Add(new NodeListenComandQueueMonitor()); //节点监听命令队列监控 GlobalNodeConfig.Monitors.Add(new TimingGcCollectMonitor()); //开启定时收集GC OnInit("**监控线程已开启**"); OnInit("**开启循环监听命令队列线程**"); IOHelper.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\" + GlobalNodeConfig.TaskSharedDllsDir + @"\"); CommandQueueScanManger.StartScanCommandQueueAsync();//循环监听命令队列线程 OnInit("**循环监听命令队列线程已开启**"); //刷新节点运行状态 var r2 = NodeProxy.PostToServer <EmptyResponse, UpdateNodeStatusRequest>(ProxyUrl.UpdateNodeStatus_Url, new UpdateNodeStatusRequest() { NodeId = GlobalNodeConfig.NodeID, Source = Source.Node, NodeStatus = Model.enums.NodeStatus.Running }); if (r2.Status != ResponesStatus.Success) { string msg = "更新节点运行状态失败,请求地址:" + ProxyUrl.UpdateNodeStatus_Url + ",服务器返回参数:" + JsonConvert.SerializeObject(r2); OnInit(msg); AlarmHelper.AlarmAsync(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, "更新节点(" + GlobalNodeConfig.NodeID.ToString() + ")的运行状态失败", msg + ",节点启动日志:" + strLog.ToString()); } else { OnInit("更新节点运行状态成功"); } OnInit("节点启动成功"); } catch (Exception ex) { string exmsg = "节点启动异常:" + JsonConvert.SerializeObject(ex); OnInit(exmsg); AlarmHelper.AlarmAsync(GlobalNodeConfig.NodeInfo.isenablealarm, (AlarmType)GlobalNodeConfig.NodeInfo.alarmtype, GlobalNodeConfig.Alarm, "节点(" + GlobalNodeConfig.NodeID.ToString() + ")启动异常,请注意查看", exmsg + ",节点启动日志:" + strLog.ToString()); } finally { OnInit("----------------------" + DateTime.Now + ":初始化节点结束-----------------------------------------"); LogProxy.AddNodeLog(strLog.ToString(), LogType.NodeInitLog); //log.Info(strLog.ToString()); // EventLogHelper.Info(strLog.ToString()); strLog.Clear(); } }