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
                    {
                        var machineResources = MachineResourcesNotificationSender.GetMachineResources();
                        await writer.WriteToWebSocket(machineResources.ToJson());

                        using (var cts = CancellationTokenSource.CreateLinkedTokenSource(ServerStore.ServerShutdown))
                        {
                            var databasesInfo = DatabasesInfoNotificationSender.FetchDatabasesInfo(ServerStore, isValidFor, cts);
                            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);
                }
            }
        }
Exemple #2
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 serverInfo = new ServerInfo
                    {
                        StartUpTime = ServerStore.Server.Statistics.StartUpTime
                    };
                    await writer.WriteToWebSocket(serverInfo.ToJson());

                    using (var cts = CancellationTokenSource.CreateLinkedTokenSource(ServerStore.ServerShutdown))
                    {
                        var databasesInfo = DatabasesInfoNotificationSender.FetchDatabasesInfo(ServerStore, cts);
                        foreach (var info in databasesInfo)
                        {
                            await writer.WriteToWebSocket(info.ToJson());
                        }
                    }

                    var machineResources = MachineResourcesNotificationSender.GetMachineResources();
                    await writer.WriteToWebSocket(machineResources.ToJson());

                    await writer.WriteNotifications();
                }
            }
        }
Exemple #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();
                    byte[][] buffers    = null;
                    try
                    {
                        SmapsReader smapsReader = null;
                        if (PlatformDetails.RunningOnLinux)
                        {
                            var buffer1 = ArrayPool <byte> .Shared.Rent(SmapsReader.BufferSize);

                            var buffer2 = ArrayPool <byte> .Shared.Rent(SmapsReader.BufferSize);

                            buffers     = new[] { buffer1, buffer2 };
                            smapsReader = new SmapsReader(new[] { buffer1, buffer2 });
                        }

                        var machineResources = MachineResourcesNotificationSender.GetMachineResources(smapsReader);
                        await writer.WriteToWebSocket(machineResources.ToJson());

                        using (var cts = CancellationTokenSource.CreateLinkedTokenSource(ServerStore.ServerShutdown))
                        {
                            var databasesInfo = DatabasesInfoNotificationSender.FetchDatabasesInfo(ServerStore, isValidFor, cts);
                            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);
                        }
                    }
                    finally
                    {
                        if (buffers != null)
                        {
                            ArrayPool <byte> .Shared.Return(buffers[0]);

                            ArrayPool <byte> .Shared.Return(buffers[1]);
                        }
                    }

                    await writer.WriteNotifications(isValidFor);
                }
            }
        }
Exemple #4
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);
                }
            }
        }