Beispiel #1
0
        /// <summary>
        /// Reports metrics specificed for an application
        /// </summary>
        /// <param name="metric"></param>
        /// <returns>Indicator of success.</returns>
        internal async Task <bool> ReportServiceMetricAsync(MetricCheck metric)
        {
            ServiceEventSource.Current.ServiceRequestStart(nameof(this.ReportServiceMetricAsync));

            try
            {
                Uri serviceUri          = new Uri($"fabric:/{metric.Application}/{metric.Service}");
                IList <Partition> pList = await this.GetCompletePartitionListAsync(serviceUri).ConfigureAwait(false);

                foreach (Partition p in pList)
                {
                    // Check that the partition is ready.
                    if (p.PartitionStatus == ServicePartitionStatus.Ready)
                    {
                        // Get the list of replicas within the partition.
                        IList <Replica> rList = await this.GetCompleteReplicaListAsync(p.PartitionInformation.Id);

                        foreach (Replica r in rList)
                        {
                            // Only query for load information if the replica is ready.
                            if (r.ReplicaStatus == ServiceReplicaStatus.Ready)
                            {
                                // Get the load information from the replica.
                                ReplicaLoadInformation loadInfo =
                                    await this.Client.QueryManager.GetReplicaLoadInformationAsync(p.PartitionInformation.Id, r.Id).ConfigureAwait(false);

                                foreach (LoadMetricReport item in loadInfo.LoadMetricReports)
                                {
                                    // If it contains one of the names requested, report the load.
                                    if (metric.MetricNames.Contains(item.Name))
                                    {
                                        //TODO:
                                        // await this._telemetry.ReportMetricAsync(metric.Service, r.Id, item.Name, item.Value, this._token).ConfigureAwait(false);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (FabricElementNotFoundException)
            {
                return(false);
            }
            catch (TimeoutException ex)
            {
                ServiceEventSource.Current.ServiceMessage(this._service.Context, "Timeout in ReportServiceMetric at {0}", ex.StackTrace);
            }
            catch (FabricObjectClosedException)
            {
                this._service.RefreshFabricClient();
                ServiceEventSource.Current.ServiceMessage(this._service.Context, "FabricClient closed");
            }

            ServiceEventSource.Current.ServiceRequestStop(nameof(this.ReportServiceMetricAsync));
            return(true);
        }
Beispiel #2
0
        public async Task <IEnumerable <LoadMetricReport> > GetReplicaLoad(string nodeName, Guid partitionId, long replicaOrInstanceId)
        {
            ReplicaLoadInformation detail = await
                                            this.fabricClient.QueryManager.GetReplicaLoadInformationAsync(partitionId, replicaOrInstanceId);


            Type             t           = typeof(LoadMetricReport);
            LoadMetricReport countMetric = new LoadMetricReport();

            t.GetProperty("Name").SetValue(countMetric, CountMetricName);
            t.GetProperty("Value").SetValue(countMetric, 1);


            detail.LoadMetricReports.Add(countMetric);

            return(detail.LoadMetricReports);
        }
Beispiel #3
0
        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);
                            }
                        }
                    }
                }
            }
        }