Ejemplo n.º 1
0
 public void Can_check_memory_status()
 {
     using (var monitor = new LowMemoryMonitor())
     {
         LowMemoryNotification.Instance.CheckMemoryStatus(monitor);
     }
 }
 public MachineResourcesNotificationSender(
     string resourceName,
     RavenServer server,
     ConcurrentSet <ConnectedWatcher> watchers,
     TimeSpan notificationsThrottle,
     CancellationToken shutdown)
     : base(resourceName, shutdown)
 {
     _server   = server;
     _watchers = watchers;
     _notificationsThrottle = notificationsThrottle;
     _lowMemoryMonitor      = new LowMemoryMonitor();
 }
Ejemplo n.º 3
0
        public async Task Get()
        {
            using (var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync())
            {
                using (var writer = new NotificationCenterWebSocketWriter(webSocket, ServerStore.ServerDashboardNotifications, ServerStore.ContextPool,
                                                                          ServerStore.ServerShutdown))
                {
                    var isValidFor = GetDatabaseAccessValidationFunc();
                    try
                    {
                        using (var lowMemoryMonitor = new LowMemoryMonitor())
                        {
                            var machineResources = MachineResourcesNotificationSender.GetMachineResources(Server.MetricCacher, lowMemoryMonitor, Server.CpuUsageCalculator);
                            await writer.WriteToWebSocket(machineResources.ToJson());
                        }

                        using (var cts = CancellationTokenSource.CreateLinkedTokenSource(ServerStore.ServerShutdown))
                        {
                            var databasesInfo = new List <AbstractDashboardNotification>();

                            foreach (var item in DatabasesInfoRetriever.FetchDatabasesInfo(ServerStore, isValidFor, cts.Token))
                            {
                                databasesInfo.Add(item);
                            }

                            foreach (var info in databasesInfo)
                            {
                                await writer.WriteToWebSocket(info.ToJson());
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        if (Logger.IsInfoEnabled)
                        {
                            Logger.Info("Failed to send the initial server dashboard data", e);
                        }
                    }

                    await writer.WriteNotifications(isValidFor);
                }
            }
        }
        internal static MachineResources GetMachineResources(MetricCacher metricCacher, LowMemoryMonitor lowMemoryMonitor, ICpuUsageCalculator cpuUsageCalculator)
        {
            var memInfo = metricCacher.GetValue <MemoryInfoResult>(MetricCacher.Keys.Server.MemoryInfoExtended);
            var cpuInfo = metricCacher.GetValue(MetricCacher.Keys.Server.CpuUsage, cpuUsageCalculator.Calculate);

            var machineResources = new MachineResources
            {
                TotalMemory     = memInfo.TotalPhysicalMemory.GetValue(SizeUnit.Bytes),
                AvailableMemory = memInfo.AvailableMemory.GetValue(SizeUnit.Bytes),
                AvailableWithoutTotalCleanMemory = memInfo.AvailableWithoutTotalCleanMemory.GetValue(SizeUnit.Bytes),
                SystemCommitLimit     = memInfo.TotalCommittableMemory.GetValue(SizeUnit.Bytes),
                CommittedMemory       = memInfo.CurrentCommitCharge.GetValue(SizeUnit.Bytes),
                ProcessMemoryUsage    = memInfo.WorkingSet.GetValue(SizeUnit.Bytes),
                IsWindows             = PlatformDetails.RunningOnPosix == false,
                IsLowMemory           = LowMemoryNotification.Instance.IsLowMemory(memInfo, lowMemoryMonitor, out var commitChargeThreshold),
                LowMemoryThreshold    = LowMemoryNotification.Instance.LowMemoryThreshold.GetValue(SizeUnit.Bytes),
                CommitChargeThreshold = commitChargeThreshold.GetValue(SizeUnit.Bytes),
                MachineCpuUsage       = cpuInfo.MachineCpuUsage,
                ProcessCpuUsage       = cpuInfo.ProcessCpuUsage
            };

            return(machineResources);
        }