Beispiel #1
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;
            }
        }
Beispiel #2
0
        public async Task Handle(HealthCheckRequest <IndexHealthWidget> request, CancellationToken cancellationToken)
        {
            var indexHealthWidget = request.DataContext;

            var client = elasticsearchHelper.GetElasticClient(indexHealthWidget);

            var indexHealthResponse = await client.IndexHealthAsync(indexHealthWidget.IndexName, cancellationToken);

            if (indexHealthResponse.IsValid)
            {
                switch (indexHealthResponse.Status)
                {
                case ElasticsearchClient.Objects.Shared.Health.Green:
                    indexHealthWidget.State = State.Ok;
                    break;

                case ElasticsearchClient.Objects.Shared.Health.Yellow:
                    indexHealthWidget.State = State.PartiallySucceeded;
                    break;

                default:
                    indexHealthWidget.State = State.Failed;
                    break;
                }
            }
            else
            {
                indexHealthWidget.State = State.Invalid;
            }
        }
        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;
                }
            }
        }
        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;
            }
        }
Beispiel #5
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;
            }
        }
        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;
            }
        }
Beispiel #7
0
        public async Task Handle(MetricQueryRequest <DeletedDocumentCountWidget> request, CancellationToken cancellationToken)
        {
            var deleteDocumentCountWidget = request.DataContext;

            var client = elasticsearchHelper.GetElasticClient(deleteDocumentCountWidget);

            var clusterStatsResponse = await client.StatsAsync("indices.docs.deleted", cancellationToken);

            if (clusterStatsResponse.IsValid)
            {
                request.DataContext.Value = clusterStatsResponse.Indices.Documents.Deleted;
                request.DataContext.State = State.Ok;
            }
            else
            {
                deleteDocumentCountWidget.State = State.Invalid;
            }
        }
Beispiel #8
0
        public async Task Handle(MetricQueryRequest <IndexDocumentCountWidget> request, CancellationToken cancellationToken)
        {
            var documentCountWidget = request.DataContext;

            var client = elasticsearchHelper.GetElasticClient(documentCountWidget);

            var clusterStatsResponse = await client.IndexStatsAsync(documentCountWidget.IndexName, "indices.*.primaries.docs.count", cancellationToken);

            if (clusterStatsResponse.IsValid)
            {
                request.DataContext.Value = clusterStatsResponse.Indices[documentCountWidget.IndexName].Primaries.Documents.Count;
                request.DataContext.State = State.Ok;
            }
            else
            {
                documentCountWidget.State = State.Invalid;
            }
        }
        public async Task Handle(MetricQueryRequest <FileSystemUsageWidget> request, CancellationToken cancellationToken)
        {
            var fileSystemUsageWidget = request.DataContext;

            var client = elasticsearchHelper.GetElasticClient(fileSystemUsageWidget);

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

            if (clusterStatsResponse.IsValid)
            {
                if (fileSystemUsageWidget.PercentageType == FileSystemPercentageType.PercentageUsed)
                {
                    var usedInBytes = clusterStatsResponse.Nodes.FileSystem.TotalInBytes - clusterStatsResponse.Nodes.FileSystem.AvailableInBytes;
                    request.DataContext.Progress = (int)Math.Round((usedInBytes / (double)clusterStatsResponse.Nodes.FileSystem.TotalInBytes) * 100);
                    request.DataContext.Message  = $"Used {request.DataContext.Progress}%{Environment.NewLine}" +
                                                   $"{BytesFormatter.Format(usedInBytes)} used out of {BytesFormatter.Format(clusterStatsResponse.Nodes.FileSystem.TotalInBytes)}";

                    request.DataContext.State = request.DataContext.Progress >= request.DataContext.ErrorPercentage ? State.Failed : State.Ok;
                }
                else
                {
                    request.DataContext.Progress = (int)Math.Round((clusterStatsResponse.Nodes.FileSystem.AvailableInBytes / (double)clusterStatsResponse.Nodes.FileSystem.TotalInBytes) * 100);
                    request.DataContext.Message  = $"Avaliable {request.DataContext.Progress}%{Environment.NewLine}" +
                                                   $"{BytesFormatter.Format(clusterStatsResponse.Nodes.FileSystem.AvailableInBytes)} available out of {BytesFormatter.Format(clusterStatsResponse.Nodes.FileSystem.TotalInBytes)}";

                    request.DataContext.State = request.DataContext.Progress <= request.DataContext.ErrorPercentage ? State.Failed : State.Ok;
                }
            }
            else
            {
                fileSystemUsageWidget.State = State.Invalid;
            }
        }