public void Client_Can_Report_Health_Async() { var sut = new Server.Hubs.RuntimeHub(_eventBus, _clientHealthService, _groupMembershipService, A.Dummy<IHubContext<Server.Hubs.IRuntimeClient>>()); sut.Context = new HubCallerContext(_request, Guid.NewGuid().ToString().ToLower()); var healthInfo = new DomainModel.EnvironmentInfo(); sut.ReportHealth(healthInfo); A.CallTo(() => _clientHealthService.RecordHealthAsync(A<ClaimsPrincipal>.Ignored, A<DomainModel.EnvironmentInfo>.That.IsSameAs(healthInfo))) .MustHaveHappened(Repeated.Exactly.Once); }
/// <summary> /// Reports to the broker the current health information of this client. /// </summary> private void Report() { while (!_stop) { MemoryStatusEx memStatus = null; try { _log.Debug("Reading extended memory status from kernel32.dll"); memStatus = MemoryStatusEx.MemoryInfo; } catch (Exception ex) { _log.ErrorException("Error retrieving extended memory information.", ex); } if (_hubConnectionManager.State != ConnectionState.Connected) { _log.Info("Connection has not been established with broker. Could not report health statistics."); return; } _log.Debug("Resolving local IP addresses on all networks."); var na = System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName()) .Where(ha => ha.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) .Select(x => x.ToString()) .ToArray(); _log.Debug("Resolving human readable OS name."); var osFriendlyName = (from x in new ManagementObjectSearcher("SELECT * FROM Win32_OperatingSystem") .Get() .OfType<ManagementObject>() select x.GetPropertyValue("Caption")).First(); _log.Debug("Building environment information to report to broker."); var ei = new DomainModel.EnvironmentInfo { Is64BitOperatingSystem = Environment.Is64BitOperatingSystem, Is64BitProcess = Environment.Is64BitProcess, MachineName = Environment.MachineName, OSFriendlyName = (osFriendlyName ?? "Unknown").ToString(), OSVersion = Environment.OSVersion.VersionString, ProcessorCount = Environment.ProcessorCount, Uptime = Environment.TickCount, IPv4Addresses = na, WorkingSet64 = Process.GetCurrentProcess().WorkingSet64, ExecutablePath = Utilities.PathUtilities.MapPath(_configurationManager.WorkingDirectory), WorkingPath = Utilities.PathUtilities.MapPath(_configurationManager.WorkingDirectory), LogsPath = Utilities.PathUtilities.MapPath(_configurationManager.LogsDirectory), PluginsPath = Utilities.PathUtilities.MapPath(_configurationManager.PluginsBaseDirectory), // Note: These may fail on Linux boxes. May need to build a "provider" model for each platform. PercentageMemoryInUse = memStatus == null ? 0 : memStatus.MemoryLoad, TotalMemoryBytes = memStatus == null ? 0 : memStatus.TotalPhysical, EnvironmentVersion = Environment.Version.ToString(), RegisteredDbFactories = _registeredDbFactories, InstalledFrameworks = _frameworkInfo }; _log.Debug("Returning environment information to broker."); _runtimeHubProxy.Invoke("ReportHealth", ei).GetAwaiter().GetResult(); Task.Delay(TimeSpan.FromSeconds(15)).GetAwaiter().GetResult(); } }