protected async override Task OnEnumChildren(bool deep) { Applications.Clear(); var applications = await _fabricClient.QueryManager.GetApplicationListAsync(); foreach (var application in applications) { var sfApplication = new SFApplication(_fabricClient, this, application); Applications.Add(sfApplication); if (deep) { await sfApplication.EnumChildren(deep); } } Nodes.Clear(); var nodes = await _fabricClient.QueryManager.GetNodeListAsync(); foreach (var node in nodes) { var sfNode = new SFNode(_fabricClient, this, node); Nodes.Add(sfNode); if (deep) { await sfNode.EnumChildren(deep); } } LoadInformation = await _fabricClient.QueryManager.GetClusterLoadInformationAsync(); }
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)); }
protected override async Task RunAsync(CancellationToken cancellationToken) { int hourlyLimit = (int)Math.Round(3600D / HourlyInterval.TotalSeconds); IReliableDictionary <DateTimeOffset, Dictionary <string, long> > dictionary = await this.StateManager.GetOrAddAsync <IReliableDictionary <DateTimeOffset, Dictionary <string, long> > >($"history:/hourly"); while (true) { cancellationToken.ThrowIfCancellationRequested(); try { ClusterLoadInformation capacities = await this.query.GetClusterLoadAsync(); DateTimeOffset utcnow = DateTimeOffset.UtcNow; DateTimeOffset timestamp = new DateTimeOffset(utcnow.Year, utcnow.Month, utcnow.Day, utcnow.Hour, utcnow.Minute, utcnow.Second, utcnow.Offset); Dictionary <string, long> values = new Dictionary <string, long>(); foreach (var capacity in capacities.LoadMetricInformationList) { values[capacity.Name] = capacity.ClusterLoad; } using (ITransaction tx = this.StateManager.CreateTransaction()) { long count = await dictionary.GetCountAsync(tx); if (count >= hourlyLimit) { var min = await(await dictionary.CreateLinqAsyncEnumerable(tx)).Min(x => x.Key); await dictionary.TryRemoveAsync(tx, min); } await dictionary.SetAsync(tx, timestamp, values); await tx.CommitAsync(); } } catch (FabricTransientException) { // retry } await Task.Delay(HourlyInterval, cancellationToken); } }
public async Task <ClusterLoadInformation> GetClusterLoadAsync() { ClusterLoadInformation loadInfo = await this.fabricClient.QueryManager.GetClusterLoadInformationAsync(); long replicaCount = await this.GetClusterReplicaCountAsync(); foreach (string systemService in systemMetrics) { LoadMetricInformation item = loadInfo.LoadMetricInformationList.FirstOrDefault(x => String.Equals(x.Name, systemService, StringComparison.OrdinalIgnoreCase)); if (item != null) { loadInfo.LoadMetricInformationList.Remove(item); } } Type t = typeof(LoadMetricInformation); LoadMetricInformation countMetric = new LoadMetricInformation(); t.GetProperty("Name").SetValue(countMetric, CountMetricName); t.GetProperty("ClusterBufferedCapacity").SetValue(countMetric, 0); t.GetProperty("ClusterCapacity").SetValue(countMetric, 0); t.GetProperty("ClusterLoad").SetValue(countMetric, replicaCount); t.GetProperty("ClusterRemainingBufferedCapacity").SetValue(countMetric, -1); t.GetProperty("ClusterRemainingCapacity").SetValue(countMetric, -1); t.GetProperty("IsClusterCapacityViolation").SetValue(countMetric, false); t.GetProperty("NodeBufferPercentage").SetValue(countMetric, 0); t.GetProperty("IsBalancedBefore").SetValue(countMetric, true); t.GetProperty("IsBalancedAfter").SetValue(countMetric, true); t.GetProperty("DeviationBefore").SetValue(countMetric, 0); t.GetProperty("DeviationAfter").SetValue(countMetric, 0); t.GetProperty("BalancingThreshold").SetValue(countMetric, 0); t.GetProperty("MaxNodeLoadNodeId").SetValue(countMetric, new NodeId(new System.Numerics.BigInteger(0), new System.Numerics.BigInteger(0))); t.GetProperty("MinNodeLoadNodeId").SetValue(countMetric, new NodeId(new System.Numerics.BigInteger(0), new System.Numerics.BigInteger(0))); loadInfo.LoadMetricInformationList.Add(countMetric); return(loadInfo); }
public async Task <IEnumerable <ClusterCapacity> > Capacity() { ClusterLoadInformation loadInfo = await this.query.GetClusterLoadAsync(); NodeList nodes = await this.query.GetNodesAsync(); return(loadInfo.LoadMetricInformationList.Select( x => new ClusterCapacity( x.Name, x.ClusterBufferedCapacity, x.ClusterCapacity, x.ClusterLoad, x.ClusterRemainingBufferedCapacity, x.ClusterRemainingCapacity, x.IsClusterCapacityViolation, x.NodeBufferPercentage, x.IsBalancedBefore, x.IsBalancedAfter, x.DeviationBefore, x.DeviationAfter, x.BalancingThreshold, nodes.FirstOrDefault(node => node.NodeId == x.MaxNodeLoadNodeId)?.NodeName, nodes.FirstOrDefault(node => node.NodeId == x.MinNodeLoadNodeId)?.NodeName))); }
private static async Task DumpClusterAsync(FabricClient fc) { var qm = fc.QueryManager; ClusterLoadInformation info = await qm.GetClusterLoadInformationAsync(); WriteLine($"LB StartTime={info.LastBalancingStartTimeUtc}, LB EndTime={info.LastBalancingEndTimeUtc}"); foreach (LoadMetricInformation lmi in info.LoadMetricInformationList) { WriteLine($"Name={lmi.Name}"); } foreach (ProvisionedFabricCodeVersion pfcv in await qm.GetProvisionedFabricCodeVersionListAsync()) { WriteLine($"SF CodeVersion={pfcv.CodeVersion}"); } foreach (ProvisionedFabricConfigVersion pfcv in await qm.GetProvisionedFabricConfigVersionListAsync()) { WriteLine($"SF Config version={pfcv.ConfigVersion}"); } foreach (ApplicationType at in await qm.GetApplicationTypeListAsync()) { WriteLine($"Name={at.ApplicationTypeName}, Ver={at.ApplicationTypeVersion}"); foreach (ServiceType st in await qm.GetServiceTypeListAsync(at.ApplicationTypeName, at.ApplicationTypeVersion)) { WriteLine($" Name={st.ServiceManifestName}, Ver={st.ServiceManifestVersion}"); } } foreach (Node n in await qm.GetNodeListAsync()) { WriteLine($"Name={n.NodeName}, Health={n.HealthState}, FD={n.FaultDomain}, UD={n.UpgradeDomain}, IP={n.IpAddressOrFQDN}"); NodeLoadInformation nli = await qm.GetNodeLoadInformationAsync(n.NodeName); foreach (NodeLoadMetricInformation nlmi in nli.NodeLoadMetricInformationList) { WriteLine($"Name={nlmi.Name}, Remaining={nlmi.NodeRemainingCapacity}"); } foreach (DeployedApplication da in await qm.GetDeployedApplicationListAsync(n.NodeName)) { WriteLine(da.ApplicationName); foreach (DeployedCodePackage dcp in await qm.GetDeployedCodePackageListAsync(n.NodeName, da.ApplicationName)) { WriteLine(dcp.EntryPoint.EntryPointLocation); } foreach (DeployedServiceType dst in await qm.GetDeployedServiceTypeListAsync(n.NodeName, da.ApplicationName)) { WriteLine(dst.ServiceTypeName); } foreach (DeployedServiceReplica dsr in await qm.GetDeployedReplicaListAsync(n.NodeName, da.ApplicationName)) { long?id = (dsr as DeployedStatefulServiceReplica)?.ReplicaId; if (id == null) { id = (dsr as DeployedStatelessServiceInstance)?.InstanceId; } WriteLine($"ServiceName={dsr.ServiceName}, PartitionId={dsr.Partitionid}, ReplicaId={id}, Status={dsr.ReplicaStatus}"); DeployedServiceReplicaDetail drd = await qm.GetDeployedReplicaDetailAsync(n.NodeName, dsr.Partitionid, id.Value); } foreach (DeployedServicePackage dsp in await qm.GetDeployedServicePackageListAsync(n.NodeName, da.ApplicationName)) { WriteLine($"ManifestName={dsp.ServiceManifestName}, Status={dsp.DeployedServicePackageStatus}"); } } } foreach (Application a in await qm.GetApplicationListAsync()) { WriteLine($"App={a.ApplicationName}, Status={a.ApplicationStatus}, Health={a.HealthState}"); foreach (Service s in await qm.GetServiceListAsync(a.ApplicationName)) { WriteLine($" Service={s.ServiceName}, Status={s.ServiceStatus}, Health={s.HealthState}"); foreach (Partition p in await qm.GetPartitionListAsync(s.ServiceName)) { WriteLine($" Partition={p.PartitionInformation.Id}, Status={p.PartitionStatus}, Health={p.HealthState}"); PartitionLoadInformation pli = await qm.GetPartitionLoadInformationAsync(p.PartitionInformation.Id); foreach (Replica r in await qm.GetReplicaListAsync(p.PartitionInformation.Id)) { WriteLine($" Replica={r.Id}, Status={r.ReplicaStatus}, Health={r.HealthState}"); ReplicaLoadInformation rli = await qm.GetReplicaLoadInformationAsync(p.PartitionInformation.Id, r.Id); } UnplacedReplicaInformation ur = await qm.GetUnplacedReplicaInformationAsync(s.ServiceName.ToString(), p.PartitionInformation.Id, false); if (ur.UnplacedReplicaReasons.Count > 0) { WriteLine("Unplaced partition replicas"); foreach (var reason in ur.UnplacedReplicaReasons) { WriteLine(reason); } } } } } }