コード例 #1
0
        public async Task Handle(MetricQueryRequest <SingleNodeMemoryWidget> request, CancellationToken cancellationToken)
        {
            var ctx    = request.DataContext;
            var client = new RabbitMqClient(ctx.URL, ctx.Username, ctx.Password);

            try
            {
                var nodeInfo = await client.GetNodeInfoAsync(ctx.NodesUrlPath, ctx.NodeName)
                               .ConfigureAwait(false);

                if (!nodeInfo.IsMemoryHealthy(ctx.MaxMemoryUsagePercent, out _, out var memoryUsagePercent))
                {
                    ctx.Value = memoryUsagePercent;
                    ctx.State = State.Failed;
                }
                else
                {
                    ctx.Value = memoryUsagePercent;
                    ctx.State = State.Ok;
                }
            }
            catch (Exception e)
            {
                ctx.State   = State.Error;
                ctx.Message = e.Message;
            }
        }
コード例 #2
0
        public async Task Handle(MetricQueryRequest <RamUsageWidget> request, CancellationToken cancellationToken)
        {
            var ramUsageWidget = request.DataContext;

            var client = elasticsearchHelper.GetElasticClient(ramUsageWidget);

            ElasticsearchClient.Objects.Stats.ClusterStatsResponse clusterStatsResponse;
            if (string.IsNullOrWhiteSpace(ramUsageWidget.NodeId))
            {
                clusterStatsResponse = await client.StatsAsync("nodes.os.mem.used_percent", cancellationToken);
            }
            else
            {
                clusterStatsResponse = await client.StatsAsync("nodes.os.mem.used_percent", ramUsageWidget.NodeId, cancellationToken);
            }

            if (clusterStatsResponse.IsValid)
            {
                request.DataContext.Value = clusterStatsResponse.Nodes.OperatingSystem.Memory.UsedPercent;
                request.DataContext.State = State.Ok;
            }
            else
            {
                ramUsageWidget.State = State.Invalid;
            }
        }
コード例 #3
0
        public async Task Handle(MetricQueryRequest <NodeDiskSpaceUsageWidget> request, CancellationToken cancellationToken)
        {
            var ctx    = request.DataContext;
            var client = new RabbitMqClient(ctx.URL, ctx.Username, ctx.Password);

            try
            {
                var nodeInfo = await client.GetNodeInfoAsync(ctx.NodesUrlPath, ctx.NodeName)
                               .ConfigureAwait(false);

                if (!nodeInfo.IsHasEnoughDiskSpace(ctx.MinFreeDiskSpacePercent, out _, out var diskSpaceUsedPercent))
                {
                    ctx.Value = diskSpaceUsedPercent;
                    ctx.State = State.Failed;
                }
                else
                {
                    ctx.Value = diskSpaceUsedPercent;
                    ctx.State = State.Ok;
                }
            }
            catch (Exception e)
            {
                ctx.State   = State.Error;
                ctx.Message = e.Message;
            }
        }
コード例 #4
0
        public async Task Handle(MetricQueryRequest <StoreSizeWidget> request, CancellationToken cancellationToken)
        {
            var storeSizeWidget = request.DataContext;

            var client = elasticsearchHelper.GetElasticClient(storeSizeWidget);

            ElasticsearchClient.Objects.Stats.ClusterStatsResponse clusterStatsResponse;
            if (string.IsNullOrWhiteSpace(storeSizeWidget.NodeId))
            {
                clusterStatsResponse = await client.StatsAsync("indices.store.size_in_bytes", cancellationToken);
            }
            else
            {
                clusterStatsResponse = await client.StatsAsync("indices.store.size_in_bytes", storeSizeWidget.NodeId, cancellationToken);
            }

            if (clusterStatsResponse.IsValid)
            {
                request.DataContext.Value = clusterStatsResponse.Indices.Store.SizeInBytes;
                request.DataContext.State = State.Ok;
            }
            else
            {
                storeSizeWidget.State = State.Invalid;
            }
        }
        public async Task IndexDocumentCountShouldInvalidWhenResponseIsInvalid()
        {
            var widget = new IndexDocumentCountWidget {
                NodeUris = new List <string>()
                {
                    "http://127.0.0.1:9200"
                }, IndexName = indexName
            };

            var indexCountResponseMock        = new Mock <IndicesStatsResponse>();
            var elasticsearchHelperMock       = new Mock <ElasticsearchHelper>();
            var elasticsearchSimpleClientMock = new Mock <ElasticsearchSimpleClient>(MockBehavior.Strict, new object[] { widget });

            indexCountResponseMock.Setup(response => response.IsValid).Returns(false);

            elasticsearchHelperMock.Setup(helper => helper.GetElasticClient(It.IsAny <IElasticsearchWidget>()))
            .Returns(elasticsearchSimpleClientMock.Object);

            elasticsearchSimpleClientMock.Setup(client => client.IndexStatsAsync(indexName, "indices.*.primaries.docs.count", It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(indexCountResponseMock.Object));

            var request = MetricQueryRequest.Create(widget);

            var handler = new IndexDocumentCountMetricQuery(elasticsearchHelperMock.Object);

            await handler.Handle(request, CancellationToken.None).ConfigureAwait(false);

            Assert.AreEqual(State.Invalid, widget.State);

            elasticsearchHelperMock.Verify(client => client.GetElasticClient(It.IsAny <IElasticsearchWidget>()), Times.Once());
            elasticsearchSimpleClientMock.Verify(client => client.IndexStatsAsync(indexName, "indices.*.primaries.docs.count", It.IsAny <CancellationToken>()), Times.Once());
        }
コード例 #6
0
        public async Task ClusterRamUsageShouldInvalidWhenResponseIsInvalid()
        {
            var widget = new RamUsageWidget {
                NodeUris = new List <string>()
                {
                    "http://127.0.0.1:9200"
                }
            };

            var clusterStatsResponseMock      = new Mock <ClusterStatsResponse>();
            var elasticsearchHelperMock       = new Mock <ElasticsearchHelper>();
            var elasticsearchSimpleClientMock = new Mock <ElasticsearchSimpleClient>(MockBehavior.Strict, new object[] { widget });

            clusterStatsResponseMock.Setup(response => response.IsValid).Returns(false);

            elasticsearchHelperMock.Setup(helper => helper.GetElasticClient(It.IsAny <IElasticsearchWidget>()))
            .Returns(elasticsearchSimpleClientMock.Object);

            elasticsearchSimpleClientMock.Setup(client => client.StatsAsync("nodes.os.mem.used_percent", It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(clusterStatsResponseMock.Object));

            var request = MetricQueryRequest.Create(widget);

            var handler = new RamUsageHandler(elasticsearchHelperMock.Object);

            await handler.Handle(request, CancellationToken.None).ConfigureAwait(false);

            Assert.AreEqual(State.Invalid, widget.State);

            elasticsearchHelperMock.Verify(client => client.GetElasticClient(It.IsAny <IElasticsearchWidget>()), Times.Once());
            elasticsearchSimpleClientMock.Verify(client => client.StatsAsync("nodes.os.mem.used_percent", It.IsAny <CancellationToken>()), Times.Once());
        }
コード例 #7
0
        public async Task Handle(MetricQueryRequest <WorkItemsWidget> request, CancellationToken cancellationToken)
        {
            const string workItemsQuery = "SELECT [System.Id] FROM WorkItems " +
                                          "WHERE [System.AssignedTo] = {0} " +
                                          "AND [State] NOT IN ('Done','Closed','Inactive','Completed')";

            var query = string.Format(workItemsQuery, request.DataContext.AssignedTo);

            var api = new AzureDevOpsApi(request.DataContext.ConnectionSettings);

            var workItemQueryResult = await api.QueryWorkItemsAsync(query, cancellationToken).ConfigureAwait(false);

            var ids = workItemQueryResult.WorkItems.Select(w => w.Id).ToList();

            if (ids.Count != 0)
            {
                var workItems = await api.GetWorkItemsAsync(ids, cancellationToken).ConfigureAwait(false);

                _uiAction.Invoke(() => UpdateWidget(request.DataContext, workItemQueryResult.WorkItems, workItems));
            }
            else
            {
                request.DataContext.Value = 0;
                request.DataContext.State = State.Ok;

                _uiAction.Invoke(request.DataContext.Clear);
            }
        }
        public async Task Handle(MetricQueryRequest <IndexStoreSizeWidget> request, CancellationToken cancellationToken)
        {
            var documentCountWidget = request.DataContext;

            var client = elasticsearchHelper.GetElasticClient(documentCountWidget);

            if (documentCountWidget.SizeType == StoreSizeType.Primary)
            {
                var clusterStatsResponse = await client.IndexStatsAsync(documentCountWidget.IndexName, "indices.*.primaries.store", cancellationToken);

                if (clusterStatsResponse.IsValid)
                {
                    request.DataContext.Value = clusterStatsResponse.Indices[documentCountWidget.IndexName].Primaries.Store.SizeInBytes;
                    request.DataContext.State = State.Ok;
                }
                else
                {
                    documentCountWidget.State = State.Invalid;
                }
            }
            else
            {
                var clusterStatsResponse = await client.IndexStatsAsync(documentCountWidget.IndexName, "indices.*.total.store", cancellationToken);

                if (clusterStatsResponse.IsValid)
                {
                    request.DataContext.Value = clusterStatsResponse.Indices[documentCountWidget.IndexName].Total.Store.SizeInBytes;
                    request.DataContext.State = State.Ok;
                }
                else
                {
                    documentCountWidget.State = State.Invalid;
                }
            }
        }
コード例 #9
0
        public async Task NamespaceCountShouldInvalidWhenResponseIsInvalid()
        {
            var widget = new NamespaceCountWidget {
                Host = "https://127.0.0.1:6443"
            };

            var namespacesResponseMock     = new Mock <NamespacesResponse>();
            var kubernetesHelperMock       = new Mock <KubernetesHelper>();
            var kubernetesSimpleClientMock = new Mock <KubernetesSimpleClient>(MockBehavior.Strict, new object[] { widget });

            namespacesResponseMock.Setup(response => response.IsValid).Returns(false);

            kubernetesHelperMock.Setup(helper => helper.GetKubernetesClient(It.IsAny <IKubernetesWidget>()))
            .Returns(kubernetesSimpleClientMock.Object);

            kubernetesSimpleClientMock.Setup(client => client.GetNamespacesAsync(It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(namespacesResponseMock.Object));

            var request = MetricQueryRequest.Create(widget);

            var handler = new NamespaceCountHandler(kubernetesHelperMock.Object);

            await handler.Handle(request, CancellationToken.None).ConfigureAwait(false);

            Assert.AreEqual(State.Invalid, widget.State);

            kubernetesHelperMock.Verify(client => client.GetKubernetesClient(It.IsAny <IKubernetesWidget>()), Times.Once());
            kubernetesSimpleClientMock.Verify(client => client.GetNamespacesAsync(It.IsAny <CancellationToken>()), Times.Once());
        }
コード例 #10
0
        public async Task PodCountShouldValid()
        {
            var widget = new PodCountWidget {
                Host = "https://127.0.0.1:6443", Namespace = "default"
            };

            var podsResponseMock           = new Mock <PodsResponse>();
            var kubernetesHelperMock       = new Mock <KubernetesHelper>();
            var kubernetesSimpleClientMock = new Mock <KubernetesSimpleClient>(MockBehavior.Strict, new object[] { widget });

            podsResponseMock.Setup(response => response.Items).Returns(new ItemEntry[50]);
            podsResponseMock.Setup(response => response.IsValid).Returns(true);

            kubernetesHelperMock.Setup(helper => helper.GetKubernetesClient(It.IsAny <IKubernetesWidget>()))
            .Returns(kubernetesSimpleClientMock.Object);

            kubernetesSimpleClientMock.Setup(client => client.GetPodsAsync("default", It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(podsResponseMock.Object));

            var request = MetricQueryRequest.Create(widget);

            var handler = new PodCountHandler(kubernetesHelperMock.Object);

            await handler.Handle(request, CancellationToken.None).ConfigureAwait(false);

            Assert.AreEqual(State.Ok, widget.State);
            Assert.AreEqual((long)50, widget.Value);

            kubernetesHelperMock.Verify(client => client.GetKubernetesClient(It.IsAny <IKubernetesWidget>()), Times.Once());
            kubernetesSimpleClientMock.Verify(client => client.GetPodsAsync("default", It.IsAny <CancellationToken>()), Times.Once());
        }
コード例 #11
0
        public async Task Handle(MetricQueryRequest <CPUUsageWidget> request, CancellationToken cancellationToken)
        {
            var clusterHealthWidget = request.DataContext;

            var client = elasticsearchHelper.GetElasticClient(clusterHealthWidget);

            ElasticsearchClient.Objects.Stats.ClusterStatsResponse clusterStatsResponse;
            if (string.IsNullOrWhiteSpace(clusterHealthWidget.NodeId))
            {
                clusterStatsResponse = await client.StatsAsync("nodes.process.cpu.percent", cancellationToken);
            }
            else
            {
                clusterStatsResponse = await client.StatsAsync("nodes.process.cpu.percent", clusterHealthWidget.NodeId, cancellationToken);
            }


            if (clusterStatsResponse.IsValid)
            {
                request.DataContext.Value = clusterStatsResponse.Nodes.Process.Cpu.Percent;
                request.DataContext.State = State.Ok;
            }
            else
            {
                clusterHealthWidget.State = State.Invalid;
            }
        }
コード例 #12
0
        public async Task Handle(MetricQueryRequest <WorkItemQueryWidget> request, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(request.DataContext.QueryId))
            {
                return;
            }

            var api = new AzureDevOpsApi(request.DataContext.ConnectionSettings);

            var workItemQueryResult = await api.QueryWorkItemsByIdAsync(request.DataContext.QueryId, cancellationToken).ConfigureAwait(false);

            var ids = workItemQueryResult.WorkItems.Select(w => w.Id).ToList();

            if (ids.Any())
            {
                var workItems = await api.GetWorkItemsAsync(ids, cancellationToken).ConfigureAwait(false);

                _uiAction.Invoke(() => UpdateWidget(request.DataContext, workItemQueryResult.WorkItems, workItems));
            }
            else
            {
                request.DataContext.Value = 0;
                request.DataContext.State = State.Ok;

                _uiAction.Invoke(request.DataContext.Clear);
            }
        }
        public async Task ClusterDeletedDocumentCountShouldValid()
        {
            var widget = new DeletedDocumentCountWidget {
                NodeUris = new List <string>()
                {
                    "http://127.0.0.1:9200"
                }
            };

            var clusterStatsResponseMock      = new Mock <ClusterStatsResponse>();
            var elasticsearchHelperMock       = new Mock <ElasticsearchHelper>();
            var elasticsearchSimpleClientMock = new Mock <ElasticsearchSimpleClient>(MockBehavior.Strict, new object[] { widget });

            clusterStatsResponseMock.Setup(response => response.Indices.Documents.Deleted).Returns(50);
            clusterStatsResponseMock.Setup(response => response.IsValid).Returns(true);

            elasticsearchHelperMock.Setup(helper => helper.GetElasticClient(It.IsAny <IElasticsearchWidget>()))
            .Returns(elasticsearchSimpleClientMock.Object);

            elasticsearchSimpleClientMock.Setup(client => client.StatsAsync("indices.docs.deleted", It.IsAny <CancellationToken>()))
            .Returns(Task.FromResult(clusterStatsResponseMock.Object));

            var request = MetricQueryRequest.Create(widget);

            var handler = new DeletedDocumentCountMetricQuery(elasticsearchHelperMock.Object);

            await handler.Handle(request, CancellationToken.None).ConfigureAwait(false);

            Assert.AreEqual(State.Ok, widget.State);
            Assert.AreEqual((long)50, widget.Value);

            elasticsearchHelperMock.Verify(client => client.GetElasticClient(It.IsAny <IElasticsearchWidget>()), Times.Once());
            elasticsearchSimpleClientMock.Verify(client => client.StatsAsync("indices.docs.deleted", It.IsAny <CancellationToken>()), Times.Once());
        }
コード例 #14
0
        public async Task Handle(MetricQueryRequest <KeyspaceExpiresCountWidget> request, CancellationToken cancellationToken)
        {
            var keyspaceKeysCountWidget = request.DataContext;

            var multiplexer = RedisHelper.GetConnectionMultiplexer(keyspaceKeysCountWidget);
            var redisServer = multiplexer.GetServer(keyspaceKeysCountWidget.EndPoint);
            var databaseKey = "db" + keyspaceKeysCountWidget.Database;

            var info = await redisServer.InfoAsync("keyspace");

            var keyspaceInfo = info[0].FirstOrDefault(x => x.Key == databaseKey).Value;

            if (keyspaceInfo == null)
            {
                request.DataContext.State = State.Invalid;
            }

            var keyspaceInfoDictionary = keyspaceInfo.Split(',')
                                         .Select(value => value.Split('='))
                                         .ToDictionary(pair => pair[0], pair => pair[1]);


            request.DataContext.Value = double.Parse(keyspaceInfoDictionary["expires"]);

            request.DataContext.State = State.Ok;
        }
コード例 #15
0
        public async Task Handle(MetricQueryRequest <CpuUsage> request, CancellationToken cancellationToken)
        {
            var usage = await GetCpuUsageAsync(request.DataContext.MachineName).ConfigureAwait(false);

            request.DataContext.Value = usage + "%";

            request.DataContext.State = State.Ok;
        }
コード例 #16
0
        protected override void HandleCore(MetricQueryRequest <LogicalDriveUsage> request)
        {
            var driveInformation = DriveInformation.ReadDrive(request.DataContext.Drive);

            request.DataContext.Progress = GetDrivePercentage(driveInformation, request.DataContext.PercentageType);
            request.DataContext.Message  = GetDriveMessage(driveInformation, request.DataContext.PercentageType);
            request.DataContext.State    = GetDriveState(driveInformation, request.DataContext.PercentageType, request.DataContext.ErrorPercentage);
        }
コード例 #17
0
        protected override void HandleCore(MetricQueryRequest <Battery> request)
        {
            var power = SystemInformation.PowerStatus;

            request.DataContext.Value    = power.BatteryLifePercent.ToString("P0");
            request.DataContext.Progress = (int)(power.BatteryLifePercent * 100);
            request.DataContext.Message  = $"{power.BatteryLifeRemaining / 3600} hr {power.BatteryLifeRemaining % 3600 / 60} min remaining";
            request.DataContext.State    = power.BatteryLifePercent * 100 >= request.DataContext.BatteryLifePercentThreshold ? State.Ok : State.Failed;
        }
コード例 #18
0
        public Task Handle(MetricQueryRequest <NuGetPackageVersion> request, CancellationToken cancellationToken)
        {
            //https://api.nuget.org/v3/registration3/anystatus.api/index.json

            request.DataContext.Value = "1.0.0.0";

            request.DataContext.State = State.Ok;

            return(Task.CompletedTask);
        }
コード例 #19
0
        public async Task API_MetricQueryTest()
        {
            var widget  = new TestWidget();
            var handler = new MetricQuery();
            var request = MetricQueryRequest.Create(widget);

            await handler.Handle(request, CancellationToken.None);

            Assert.AreEqual(1, widget.Value);
        }
 private static CollectionSynchronizer <IndexEntry, Item> GetNoneSynchronizer(MetricQueryRequest <IndexCountWidget> request)
 {
     return(new CollectionSynchronizer <IndexEntry, Item>
     {
         Compare = (indexEntry, item) => false,
         Remove = item => request.DataContext.Remove(item),
         Update = (indexEntry, item) => item.Name = indexEntry.Index,
         Add = indexEntry => { }
     });
 }
コード例 #21
0
ファイル: ProcessCountQuery.cs プロジェクト: trashpat/Plugins
 protected override void HandleCore(MetricQueryRequest <ProcessCount> request)
 {
     using (var counter = string.IsNullOrWhiteSpace(request.DataContext.MachineName)
         ? new System.Diagnostics.PerformanceCounter(CategoryName, CounterName)
         : new System.Diagnostics.PerformanceCounter(CategoryName, CounterName, InstanceName, request.DataContext.MachineName))
     {
         request.DataContext.Value = (int)counter.NextValue();
         request.DataContext.State = State.Ok;
     }
 }
コード例 #22
0
        public Task Handle(MetricQueryRequest <Battery> request, CancellationToken cancellationToken)
        {
            var power = SystemInformation.PowerStatus;

            request.DataContext.Value    = power.BatteryLifePercent.ToString("P0");
            request.DataContext.Progress = (int)(power.BatteryLifePercent * 100);
            request.DataContext.Message  = $"{power.BatteryLifeRemaining / 3600} hr {power.BatteryLifeRemaining % 3600 / 60} min remaining";
            request.DataContext.State    = power.BatteryLifePercent * 100 > request.DataContext.BatteryLifePercentThreshold ? State.Ok : State.Failed;

            return(Task.CompletedTask);
        }
コード例 #23
0
        protected override void HandleCore(MetricQueryRequest <PerformanceCounter> request)
        {
            if (string.IsNullOrWhiteSpace(request.DataContext.MachineName))
            {
                request.DataContext.MachineName = "localhost";
            }

            request.DataContext.Value = (int)GetValue(request.DataContext);

            request.DataContext.State = State.Ok;
        }
コード例 #24
0
        public async Task CpuUsageTest()
        {
            var widget = new CpuUsage();

            var request = MetricQueryRequest.Create(widget);

            var handler = new CpuUsageQuery();

            await handler.Handle(request, CancellationToken.None).ConfigureAwait(false);

            Assert.AreEqual(State.Ok, widget.State);
        }
コード例 #25
0
        public async Task Handle(MetricQueryRequest <DatabaseSizeWidget> request, CancellationToken cancellationToken)
        {
            var databaseSizeWidget = request.DataContext;

            var multiplexer = RedisHelper.GetConnectionMultiplexer(databaseSizeWidget);
            var redisServer = multiplexer.GetServer(databaseSizeWidget.EndPoint);

            var databaseSize = await redisServer.DatabaseSizeAsync(database : databaseSizeWidget.Database);

            request.DataContext.Value = databaseSize;
            request.DataContext.State = State.Ok;
        }
        public async Task Handle(MetricQueryRequest <IndexCountWidget> request, CancellationToken cancellationToken)
        {
            var indexCountWidget = request.DataContext;

            var client = elasticsearchHelper.GetElasticClient(indexCountWidget);

            var indexCountResponse = await client.IndexListAsync(cancellationToken);

            if (indexCountResponse.IsValid)
            {
                request.DataContext.Value = indexCountResponse.Indices.Length;

                if (uiAction != null) //uiAction is null on unit tests...
                {
                    CollectionSynchronizer <IndexEntry, Item> synchronizer = null;
                    switch (indexCountWidget.IndexDetails)
                    {
                    case IndexDetail.None:
                        synchronizer = GetNoneSynchronizer(request);
                        break;

                    case IndexDetail.Health:
                        synchronizer = GetHealthSynchronizer(request);
                        break;

                    case IndexDetail.DocumentsCount:
                        synchronizer = GetDocumentsCountSynchronizer(request);
                        break;

                    case IndexDetail.DeletedDocumentsCount:
                        synchronizer = GetDeletedDocumentsCountSynchronizer(request);
                        break;

                    case IndexDetail.TotalStoreSize:
                        synchronizer = GetTotalStoreSizeSynchronizer(request);
                        break;

                    case IndexDetail.PrimaryStoreSize:
                        synchronizer = GetPrimaryStoreSizeSynchronizer(request);
                        break;
                    }

                    uiAction.Invoke(() => synchronizer.Synchronize(indexCountResponse.Indices, request.DataContext.Items));
                }

                request.DataContext.State = State.Ok;
            }
            else
            {
                indexCountWidget.State = State.Invalid;
            }
        }
コード例 #27
0
        public async Task ProcessCpuUsage_ProcessNotFound_Test()
        {
            var widget = new ProcessCpuUsage
            {
                ProcessName = "DoesNotExist"
            };

            var request = MetricQueryRequest.Create(widget);

            var handler = new ProcessCpuUsageQuery();

            await handler.Handle(request, CancellationToken.None).ConfigureAwait(false);
        }
コード例 #28
0
        public async Task Handle(MetricQueryRequest <BlockedClientsWidget> request, CancellationToken cancellationToken)
        {
            var BlockedClientWidget = request.DataContext;

            var multiplexer = RedisHelper.GetConnectionMultiplexer(BlockedClientWidget);
            var redisServer = multiplexer.GetServer(BlockedClientWidget.EndPoint);

            var info = await redisServer.InfoAsync("clients");

            request.DataContext.Value = double.Parse(info[0].First(stat => stat.Key == "blocked_clients").Value);

            request.DataContext.State = State.Ok;
        }
コード例 #29
0
        public async Task Handle(MetricQueryRequest <ClientCountWidget> request, CancellationToken cancellationToken)
        {
            var clientListWidget = request.DataContext;

            var multiplexer = RedisHelper.GetConnectionMultiplexer(clientListWidget);
            var redisServer = multiplexer.GetServer(clientListWidget.EndPoint);

            var clientList = await redisServer.ClientListAsync();

            request.DataContext.Value = clientList.Length;

            request.DataContext.State = State.Ok;
        }
        public async Task Handle(MetricQueryRequest <TotalCommandsProcessedWidget> request, CancellationToken cancellationToken)
        {
            var totalCommandsProcessedWidget = request.DataContext;

            var multiplexer = RedisHelper.GetConnectionMultiplexer(totalCommandsProcessedWidget);
            var redisServer = multiplexer.GetServer(totalCommandsProcessedWidget.EndPoint);

            var info = await redisServer.InfoAsync("stats");

            request.DataContext.Value = double.Parse(info[0].First(stat => stat.Key == "total_commands_processed").Value);

            request.DataContext.State = State.Ok;
        }