示例#1
0
        public Task SetAsync(WsServerNodeState data)
        {
            if (data == null || string.IsNullOrEmpty(data.Address))
            {
                return(TaskEx.CompletedTask);
            }
            var db = _redis.RedisConn.GetDatabase();
            var t1 = db.HashSetAsync(_redisKeyWsServerNodeByAddress, data.Address, VirtualRoot.JsonSerializer.Serialize(data));
            // 如果WsServer节点服务器的时间和WebApiServer相差很多则该WsServer节点会被WebApiServer节点从redis中删除从而下线该节点
            var t2 = db.HashSetAsync(_redisKeyWsServerNodeAddress, data.Address, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));

            return(Task.WhenAll(t1, t2));
        }
 public ResponseBase ReportNodeState([FromBody] WsServerNodeState state)
 {
     if (state == null)
     {
         return(ResponseBase.InvalidInput("参数错误"));
     }
     try {
         WebApiRoot.WsServerNodeSet.SetNodeState(state);
         return(ResponseBase.Ok());
     }
     catch (Exception e) {
         return(ResponseBase.ServerError(e.Message));
     }
 }
 private void ReportNodeAsync(Action callback = null)
 {
     Task.Factory.StartNew(() => {
         WsServerNodeState nodeState = null;
         try {
             int minerClientWsSessionCount = 0;
             int minerStudioWsSessionCount = 0;
             minerClientWsSessionCount     = AppRoot.WsServer.MinerClientWsSessions.Count;
             minerStudioWsSessionCount     = AppRoot.WsServer.MinerStudioWsSessions.Count;
             var ram   = Windows.Ram.Instance;
             var cpu   = Windows.Cpu.Instance;
             nodeState = new WsServerNodeState {
                 Address                   = ServerRoot.HostConfig.ThisServerAddress,
                 Description               = string.Empty,
                 MinerClientSessionCount   = AppRoot.MinerClientSessionSet.Count,
                 MinerStudioSessionCount   = AppRoot.MinerStudioSessionSet.Count,
                 MinerClientWsSessionCount = minerClientWsSessionCount,
                 MinerStudioWsSessionCount = minerStudioWsSessionCount,
                 Cpu = cpu.ToData(),
                 TotalPhysicalMemory     = ram.TotalPhysicalMemory,
                 AvailablePhysicalMemory = ram.AvailablePhysicalMemory,
                 OSInfo         = Windows.OS.Instance.OsInfo,
                 CpuPerformance = cpu.GetTotalCpuUsage(),
                 // 以下三个属性的访问约耗时30毫秒所以放在Task中
                 ProcessMemoryMb        = VirtualRoot.ProcessMemoryMb,
                 ThreadCount            = VirtualRoot.ThreadCount,
                 HandleCount            = VirtualRoot.HandleCount,
                 AvailableFreeSpaceInfo = VirtualRoot.GetAvailableFreeSpaceInfo()
             };
         }
         catch (Exception e) {
             Logger.ErrorDebugLine(e);
         }
         _wsServerNodeRedis.SetAsync(nodeState).ContinueWith(t => {
             if (t.Exception != null)
             {
                 NTMinerConsole.UserFail("呼吸失败:" + t.Exception.Message);
             }
             else
             {
                 NTMinerConsole.UserOk("呼吸成功");
             }
             callback?.Invoke();
         });
     });
 }
示例#4
0
 public static WsServerNodeActiveOn Create(WsServerNodeState data)
 {
     return(new WsServerNodeActiveOn {
         Address = data.Address,
         Description = data.Description,
         MinerClientWsSessionCount = data.MinerClientWsSessionCount,
         MinerStudioWsSessionCount = data.MinerStudioWsSessionCount,
         MinerClientSessionCount = data.MinerClientSessionCount,
         MinerStudioSessionCount = data.MinerStudioSessionCount,
         AvailablePhysicalMemory = data.AvailablePhysicalMemory,
         Cpu = data.Cpu,
         CpuPerformance = data.CpuPerformance,
         OSInfo = data.OSInfo,
         TotalPhysicalMemory = data.TotalPhysicalMemory,
         ActiveOn = DateTime.Now,
     });
 }
示例#5
0
        public Task <List <WsServerNodeState> > GetAllAsync()
        {
            var db = _redis.RedisConn.GetDatabase();

            return(db.HashGetAllAsync(_redisKeyWsServerNodeByAddress).ContinueWith(t => {
                List <WsServerNodeState> list = new List <WsServerNodeState>();
                foreach (var item in t.Result)
                {
                    if (item.Value.HasValue)
                    {
                        WsServerNodeState data = VirtualRoot.JsonSerializer.Deserialize <WsServerNodeState>(item.Value);
                        if (data != null)
                        {
                            list.Add(data);
                        }
                    }
                }
                return list;
            }));
        }
        private void ReportNodeAsync(Action callback = null)
        {
            WsServerNodeState nodeState = null;

            try {
                int minerClientWsSessionCount = 0;
                int minerStudioWsSessionCount = 0;
                minerClientWsSessionCount = WsRoot.MinerClientSessionSet.WsSessionManager.Count;
                minerStudioWsSessionCount = WsRoot.MinerStudioSessionSet.WsSessionManager.Count;
                var ram = Windows.Ram.Instance;
                var cpu = Windows.Cpu.Instance;
                nodeState = new WsServerNodeState {
                    Address                   = ServerRoot.HostConfig.ThisServerAddress,
                    Description               = string.Empty,
                    MinerClientSessionCount   = WsRoot.MinerClientSessionSet.Count,
                    MinerStudioSessionCount   = WsRoot.MinerStudioSessionSet.Count,
                    MinerClientWsSessionCount = minerClientWsSessionCount,
                    MinerStudioWsSessionCount = minerStudioWsSessionCount,
                    Cpu = cpu.ToData(),
                    TotalPhysicalMemory     = ram.TotalPhysicalMemory,
                    AvailablePhysicalMemory = ram.AvailablePhysicalMemory,
                    OSInfo         = Windows.OS.Instance.OsInfo,
                    CpuPerformance = cpu.GetCurrentCpuUsage()
                };
            }
            catch (Exception e) {
                Logger.ErrorDebugLine(e);
            }
            _wsServerNodeRedis.SetAsync(nodeState).ContinueWith(t => {
                if (t.Exception != null)
                {
                    NTMinerConsole.UserFail("呼吸失败:" + t.Exception.Message);
                }
                else
                {
                    NTMinerConsole.UserOk("呼吸成功");
                }
                callback?.Invoke();
            });
        }
示例#7
0
 public void SetNodeState(WsServerNodeState data)
 {
     if (data == null || string.IsNullOrEmpty(data.Address))
     {
         return;
     }
     if (!data.IsAddressValid())
     {
         return;
     }
     if (_dicByIp.TryGetValue(data.Address, out WsServerNodeActiveOn nodeData))
     {
         nodeData.Update(data);
     }
     else
     {
         nodeData = WsServerNodeActiveOn.Create(data);
         _dicByIp.Add(data.Address, nodeData);
         ReSetConsistentHash();
         _mqSender.SendWsServerNodeAdded(data.Address);
     }
 }
示例#8
0
 public void ReportNodeStateAsync(WsServerNodeState nodeState, Action <ResponseBase, Exception> callback)
 {
     JsonRpcRoot.SignPostAsync(RpcRoot.OfficialServerHost, RpcRoot.OfficialServerPort, _controllerName, nameof(IWsServerNodeController.ReportNodeState), nodeState, callback, timeountMilliseconds: 3000);
 }
示例#9
0
 public void Update(WsServerNodeState data, DateTime activeOn)
 {
     this.Update(data);
     this.ActiveOn = activeOn;
 }