public async Task Get()
        {
            using (var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync())
            {
                using (var writer = new NotificationCenterWebSocketWriter(webSocket, Database.NotificationCenter, ContextPool, Database.DatabaseShutdown))
                {
                    using (Database.NotificationCenter.GetStored(out IEnumerable <NotificationTableValue> storedNotifications, postponed: false))
                    {
                        foreach (var alert in storedNotifications)
                        {
                            await writer.WriteToWebSocket(alert.Json);
                        }
                    }

                    foreach (var operation in Database.Operations.GetActive().OrderBy(x => x.Description.StartTime))
                    {
                        var action = OperationChanged.Create(Database.Name, operation.Id, operation.Description, operation.State, operation.Killable);

                        await writer.WriteToWebSocket(action.ToJson());
                    }
                    writer.AfterTrackActionsRegistration = ServerStore.NotifyAboutClusterTopologyAndConnectivityChanges;
                    await writer.WriteNotifications(null);
                }
            }
        }
Example #2
0
        public async Task Get()
        {
            using (var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync())
            {
                var isValidFor = GetDatabaseAccessValidationFunc();
                using (var writer = new NotificationCenterWebSocketWriter(webSocket, ServerStore.NotificationCenter, ServerStore.ContextPool, ServerStore.ServerShutdown))
                {
                    using (ServerStore.NotificationCenter.GetStored(out IEnumerable <NotificationTableValue> storedNotifications, postponed: false))
                    {
                        foreach (var action in storedNotifications)
                        {
                            if (isValidFor != null)
                            {
                                if (action.Json.TryGet("Database", out string db) == false ||
                                    isValidFor(db) == false)
                                {
                                    continue; // not valid for this, skipping
                                }
                            }


                            await writer.WriteToWebSocket(action.Json);
                        }
                    }

                    await writer.WriteNotifications(isValidFor, () => Server.ServerStore.Engine.NotifyTopologyChange(propogateError: true));
                }
            }
        }
Example #3
0
        public async Task Get()
        {
            using (var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync())
            {
                var isValidFor = GetDatabaseAccessValidationFunc();
                using (var writer = new NotificationCenterWebSocketWriter(webSocket, ServerStore.NotificationCenter, ServerStore.ContextPool, ServerStore.ServerShutdown))
                {
                    using (ServerStore.NotificationCenter.GetStored(out IEnumerable <NotificationTableValue> storedNotifications, postponed: false))
                    {
                        foreach (var action in storedNotifications)
                        {
                            if (isValidFor != null)
                            {
                                if (action.Json.TryGet("Database", out string db) == false ||
                                    isValidFor(db) == false)
                                {
                                    continue; // not valid for this, skipping
                                }
                            }

                            await writer.WriteToWebSocket(action.Json);
                        }
                    }

                    foreach (var operation in ServerStore.Operations.GetActive().OrderBy(x => x.Description.StartTime))
                    {
                        var action = OperationChanged.Create(null, operation.Id, operation.Description, operation.State, operation.Killable);

                        await writer.WriteToWebSocket(action.ToJson());
                    }

                    await writer.WriteNotifications(isValidFor);
                }
            }
        }
        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);
                }
            }
        }
Example #5
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();
                }
            }
        }
Example #6
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);
                }
            }
        }
        public async Task Get()
        {
            using (var webSocket = await HttpContext.WebSockets.AcceptWebSocketAsync())
            {
                using (var writer = new NotificationCenterWebSocketWriter(webSocket, ServerStore.NotificationCenter, ServerStore.ContextPool, ServerStore.ServerShutdown))
                {
                    using (ServerStore.NotificationCenter.GetStored(out IEnumerable <NotificationTableValue> storedNotifications, postponed: false))
                    {
                        foreach (var action in storedNotifications)
                        {
                            await writer.WriteToWebSocket(action.Json);
                        }
                    }

                    await writer.WriteNotifications();
                }
            }
        }
Example #8
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);
                }
            }
        }