Ejemplo n.º 1
0
        public async Task <ClusterInfo> Info()
        {
            NodeList nodes = await this.query.GetNodesAsync();

            ApplicationTypeList appTypes = await this.query.GetApplicationTypesAsync();

            ApplicationList applications = await this.query.GetApplicationsAsync();

            ClusterLoadInformation clusterLoadInfo = await this.query.GetClusterLoadAsync();

            ClusterHealth clusterHealth = await this.query.GetClusterHealthAsync();

            ProvisionedFabricCodeVersion version = await this.query.GetFabricVersion();

            long serviceCount   = 0;
            long partitionCount = 0;
            long replicaCount   = 0;

            foreach (Node node in nodes)
            {
                DeployedApplicationList deployedApplicationList = await this.query.GetDeployedApplicationsAsync(node.NodeName);

                foreach (DeployedApplication deployedApplication in deployedApplicationList)
                {
                    DeployedServiceReplicaList deployedReplicas =
                        await this.query.GetDeployedReplicasAsync(node.NodeName, deployedApplication.ApplicationName);

                    replicaCount += deployedReplicas.Count;
                }
            }

            foreach (Application application in applications)
            {
                ServiceList services = await this.query.GetServicesAsync(application.ApplicationName);

                serviceCount += services.Count;
            }

            return(new ClusterInfo(
                       clusterHealth.AggregatedHealthState.ToString(),
                       version != null ? version.CodeVersion : "not based",
                       nodes.Select(x => x.NodeType).Distinct().Count(),
                       appTypes.Count(),
                       nodes.Select(x => x.FaultDomain.ToString()).Distinct().Count(),
                       nodes.Select(x => x.UpgradeDomain).Distinct().Count(),
                       nodes.Count,
                       applications.Count,
                       serviceCount,
                       partitionCount, // TODO: partition count
                       replicaCount,
                       clusterLoadInfo.LastBalancingStartTimeUtc,
                       clusterLoadInfo.LastBalancingEndTimeUtc));
        }
Ejemplo n.º 2
0
        private async Task <long> GetNodeReplicaCountAsync(string nodeName)
        {
            long count = 0;
            DeployedApplicationList deployedApplications = await this.fabricClient.QueryManager.GetDeployedApplicationListAsync(nodeName);

            foreach (DeployedApplication application in deployedApplications)
            {
                DeployedServiceReplicaList replicas = await this.fabricClient.QueryManager.GetDeployedReplicaListAsync(nodeName, application.ApplicationName);

                count += replicas.Count;
            }

            return(count);
        }
Ejemplo n.º 3
0
        private void SetInstanceOrReplicaMonitoringList(
            Uri appName,
            List <string> serviceFilterList,
            ServiceFilterType filterType,
            string appTypeName,
            DeployedServiceReplicaList deployedReplicaList,
            ref List <ReplicaOrInstanceMonitoringInfo> replicaMonitoringList)
        {
            foreach (var deployedReplica in deployedReplicaList)
            {
                ReplicaOrInstanceMonitoringInfo replicaInfo = null;

                if (deployedReplica is DeployedStatefulServiceReplica statefulReplica &&
                    statefulReplica.ReplicaRole == ReplicaRole.Primary)
                {
                    replicaInfo = new ReplicaOrInstanceMonitoringInfo()
                    {
                        ApplicationName     = appName,
                        ApplicationTypeName = appTypeName,
                        HostProcessId       = statefulReplica.HostProcessId,
                        ReplicaOrInstanceId = statefulReplica.ReplicaId,
                        PartitionId         = statefulReplica.Partitionid,
                    };

                    if (serviceFilterList != null &&
                        filterType != ServiceFilterType.None)
                    {
                        bool isInFilterList = serviceFilterList.Any(s => statefulReplica.ServiceName.OriginalString.ToLower().Contains(s.ToLower()));

                        // Include
                        if (filterType == ServiceFilterType.Include &&
                            !isInFilterList)
                        {
                            continue;
                        }

                        // Exclude
                        else if (filterType == ServiceFilterType.Exclude &&
                                 isInFilterList)
                        {
                            continue;
                        }
                    }
                }
Ejemplo n.º 4
0
        public async Task <IEnumerable <DeployedApplicationModel> > Get(string nodeName, string appTypeFilter = null)
        {
            IEnumerable <DeployedApplication> deployedApplications = await this.query.GetDeployedApplicationsAsync(nodeName);

            if (appTypeFilter != null)
            {
                deployedApplications = deployedApplications.Where(x => !appTypeFilter.Contains(x.ApplicationTypeName));
            }

            List <DeployedApplicationModel> applicationModels = new List <DeployedApplicationModel>(deployedApplications.Count());

            foreach (DeployedApplication deployedApplication in deployedApplications)
            {
                DeployedServiceReplicaList deployedReplicas =
                    await this.query.GetDeployedReplicasAsync(nodeName, deployedApplication.ApplicationName);

                IEnumerable <IGrouping <Uri, DeployedServiceReplica> > groups = deployedReplicas.GroupBy(x => x.ServiceName);
                List <DeployedServiceModel> serviceModels = new List <DeployedServiceModel>(groups.Count());

                foreach (IGrouping <Uri, DeployedServiceReplica> group in groups)
                {
                    List <ReplicaModel> replicaModels = new List <ReplicaModel>(group.Count());
                    foreach (DeployedServiceReplica item in group)
                    {
                        try
                        {
                            DeployedStatefulServiceReplica statefulDeployedReplica = item as DeployedStatefulServiceReplica;

                            if (statefulDeployedReplica != null)
                            {
                                IEnumerable <LoadMetricReport> loadMetrics =
                                    await this.query.GetReplicaLoad(nodeName, statefulDeployedReplica.Partitionid, statefulDeployedReplica.ReplicaId);

                                string health =
                                    await this.query.GetReplicaHealthAsync(statefulDeployedReplica.Partitionid, statefulDeployedReplica.ReplicaId);

                                replicaModels.Add(
                                    new ReplicaModel(
                                        statefulDeployedReplica.ReplicaId,
                                        statefulDeployedReplica.Partitionid,
                                        statefulDeployedReplica.ReplicaRole.ToString(),
                                        statefulDeployedReplica.ReplicaStatus.ToString(),
                                        health,
                                        loadMetrics.Select(x => new LoadMetric(x.Name, x.Value))));
                            }
                            else
                            {
                                DeployedStatelessServiceInstance statelessDeployedInstance = item as DeployedStatelessServiceInstance;

                                if (statelessDeployedInstance != null)
                                {
                                    IEnumerable <LoadMetricReport> loadMetrics =
                                        await this.query.GetReplicaLoad(nodeName, statelessDeployedInstance.Partitionid, statelessDeployedInstance.InstanceId);

                                    string health =
                                        await this.query.GetReplicaHealthAsync(statelessDeployedInstance.Partitionid, statelessDeployedInstance.InstanceId);

                                    replicaModels.Add(
                                        new ReplicaModel(
                                            statelessDeployedInstance.InstanceId,
                                            statelessDeployedInstance.Partitionid,
                                            null,
                                            statelessDeployedInstance.ReplicaStatus.ToString(),
                                            health,
                                            loadMetrics.Select(x => new LoadMetric(x.Name, x.Value))));
                                }
                            }
                        }
                        catch (FabricException)
                        {
                            // information may not be available yet. Skip and move on.
                        }
                    }

                    Service service = await this.query.GetServiceAsync(deployedApplication.ApplicationName, group.Key);

                    serviceModels.Add(
                        new DeployedServiceModel(
                            new ServiceModel(
                                group.Key.ToString(),
                                service?.ServiceTypeName,
                                service?.ServiceManifestVersion,
                                service?.ServiceStatus.ToString(),
                                service?.HealthState.ToString(),
                                replicaModels
                                .SelectMany(r => r.Metrics)
                                .GroupBy(k => k.Name, v => v.Value)
                                .Select(g => new LoadMetric(g.Key, g.Sum()))),
                            replicaModels));
                }

                Application application = await this.query.GetApplicationAsync(deployedApplication.ApplicationName);

                applicationModels.Add(
                    new DeployedApplicationModel(
                        new ApplicationModel(
                            deployedApplication.ApplicationName.ToString(),
                            application?.ApplicationTypeName,
                            application?.ApplicationTypeVersion,
                            application?.ApplicationStatus.ToString(),
                            application?.HealthState.ToString(),
                            serviceModels
                            .SelectMany(s => s.Service.Metrics)
                            .GroupBy(k => k.Name, v => v.Value)
                            .Select(g => new LoadMetric(g.Key, g.Sum()))),
                        serviceModels));
            }

            return(applicationModels);
        }