示例#1
0
        /// <summary>
        /// Generating the 4D metrics.
        /// </summary>
        /// <param name="metricName">metric name</param>
        /// <param name="value">metric value</param>
        private void EmitMDMMetric(string testName, string testCategory, long value, string metricName, string dimension3Name, string dimension4Name, string dimension3Value)
        {
            try
            {
                ErrorContext mdmError = new ErrorContext();

                // MeasureMetric usage sample
                MeasureMetric4D testMeasure = MeasureMetric4D.Create(
                    MdmAccountName, // Your MDM Account Name
                    MdmNamespace,   // MDM Namespace, can be as specific as needed by separating values with '/'.
                    metricName,     // The Metric name.
                                    // The following dimensions are necessary to identify the runner and instance generating the metrics.
                                    // The values for these dimensions come from the base class RunnerAuthorBase.
                    dimensionName1, // The Worksapce name as Environment name.
                    dimensionName2, // The current category name.
                    dimension3Name, // The current computer name.
                    dimension4Name, // Type like ( KubeEvents_CL or KubeNodeInventory …)
                    ref mdmError);

                if (testMeasure == null)
                {
                    Console.WriteLine("Fail to create MeasureMetric, error code is {0:X}", mdmError.ErrorCode);
                    Console.WriteLine("    error message: {0}", mdmError.ErrorMessage);
                }
                else
                {
                    // Logs the metric as defined above.
                    var result = testMeasure.LogValue(
                        value,
                        WorkspaceName,       // The Worksapce name as Environment name.
                        testCategory,        // The current category name.
                        dimension3Value,     // The current computer name.
                        testName,            // Type like ( KubeEvents_CL or KubeNodeInventory …)
                        ref mdmError);

                    if (!result)
                    {
                        Console.WriteLine("Fail to set MeasureMetric value, error code is {0:X}", mdmError.ErrorCode);
                        Console.WriteLine("    error message: {0}", mdmError.ErrorMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Fail to set MeasureMetric value, error Source is {0}", ex.Source);
                Console.WriteLine("    error message: {0}", ex.Message);
                throw ex;
            }
        }
示例#2
0
        internal MetricsEmitter(IInternalServiceConfiguration config, TraceWriterWrapper traceWriter)
        {
            this.config = Guard.IsNotNull(config, nameof(config));
            this.trace  = Guard.IsNotNull(traceWriter, nameof(traceWriter));

            var mdmAccount   = config.MdmAccountName;
            var mdmNamespace = config.MdmNamespace;

            if (string.IsNullOrEmpty(mdmAccount) || string.IsNullOrEmpty(mdmNamespace))
            {
                this.trace.WriteError("MetricsEmitter: MdmAccount or Namespace value is empty in configuration. Disabling metrics.");
                this.isMetricsEnabled = false;
                return;
            }

            ErrorContext mdmError = new ErrorContext();

            DefaultConfiguration.SetDefaultDimensionNamesValues(
                ref mdmError,
                1,
                new[] { "DataCenter" },
                new[] { this.config.DataCenter });

            this.clusterHealthMetric                = MeasureMetric2D.Create(mdmAccount, mdmNamespace, "ClusterHealthState", ClusterNameDimension, HealthStateDimension);
            this.appHealthMetric                    = MeasureMetric3D.Create(mdmAccount, mdmNamespace, "AppHealthState", ClusterNameDimension, AppNameDimension, HealthStateDimension);
            this.nodeHealthMetric                   = MeasureMetric3D.Create(mdmAccount, mdmNamespace, "NodeHealthState", ClusterNameDimension, NodeNameDimension, HealthStateDimension);
            this.serviceHealthMetric                = MeasureMetric4D.Create(mdmAccount, mdmNamespace, "ServiceHealthState", ClusterNameDimension, AppNameDimension, ServiceNameDimension, HealthStateDimension);
            this.partitionHealthMetric              = MeasureMetric5D.Create(mdmAccount, mdmNamespace, "PartitionHealthState", ClusterNameDimension, AppNameDimension, ServiceNameDimension, PartitionIdDimension, HealthStateDimension);
            this.replicaHealthMetric                = MeasureMetric6D.Create(mdmAccount, mdmNamespace, "ReplicaHealthState", ClusterNameDimension, AppNameDimension, ServiceNameDimension, PartitionIdDimension, ReplicaIdDimension, HealthStateDimension);
            this.deployedAppHealthMetric            = MeasureMetric4D.Create(mdmAccount, mdmNamespace, "DeployedApplicationHealthState", ClusterNameDimension, AppNameDimension, NodeNameDimension, HealthStateDimension);
            this.deployedServicePackageHealthMetric = MeasureMetric5D.Create(mdmAccount, mdmNamespace, "DeployedServicePackageHealthState", ClusterNameDimension, AppNameDimension, ServiceNameDimension, NodeNameDimension, HealthStateDimension);

            this.clusterHealthEventMetric                = MeasureMetric5D.Create(mdmAccount, mdmNamespace, "ClusterHealthEvent", ClusterNameDimension, HealthStateDimension, SourceDimension, PropertyDimension, IsExpiredDimension);
            this.appHealthEventMetric                    = MeasureMetric6D.Create(mdmAccount, mdmNamespace, "AppHealthEvent", ClusterNameDimension, AppNameDimension, HealthStateDimension, SourceDimension, PropertyDimension, IsExpiredDimension);
            this.nodeHealthEventMetric                   = MeasureMetric6D.Create(mdmAccount, mdmNamespace, "NodeHealthEvent", ClusterNameDimension, NodeNameDimension, HealthStateDimension, SourceDimension, PropertyDimension, IsExpiredDimension);
            this.serviceHealthEventMetric                = MeasureMetric7D.Create(mdmAccount, mdmNamespace, "ServiceHealthEvent", ClusterNameDimension, AppNameDimension, ServiceNameDimension, HealthStateDimension, SourceDimension, PropertyDimension, IsExpiredDimension);
            this.partitionHealthEventMetric              = MeasureMetric8D.Create(mdmAccount, mdmNamespace, "PartitionHealthEvent", ClusterNameDimension, AppNameDimension, ServiceNameDimension, PartitionIdDimension, HealthStateDimension, SourceDimension, PropertyDimension, IsExpiredDimension);
            this.replicaHealthEventMetric                = MeasureMetric9D.Create(mdmAccount, mdmNamespace, "ReplicaHealthEvent", ClusterNameDimension, AppNameDimension, ServiceNameDimension, PartitionIdDimension, ReplicaIdDimension, HealthStateDimension, SourceDimension, PropertyDimension, IsExpiredDimension);
            this.deployedAppHealthEventMetric            = MeasureMetric7D.Create(mdmAccount, mdmNamespace, "DeployedApplicationHealthEvent", ClusterNameDimension, AppNameDimension, NodeNameDimension, HealthStateDimension, SourceDimension, PropertyDimension, IsExpiredDimension);
            this.deployedServicePackageHealthEventMetric = MeasureMetric8D.Create(mdmAccount, mdmNamespace, "DeployedServicePackageHealthEvent", ClusterNameDimension, AppNameDimension, ServiceNameDimension, NodeNameDimension, HealthStateDimension, SourceDimension, PropertyDimension, IsExpiredDimension);

            this.trace.WriteInfo("MetricsEmitter: Initialized Service Fabric MDM metrics. AccountName: {0}, namespace: {1}", mdmAccount, mdmNamespace);
        }
示例#3
0
 public Metric4DWrapper(
     string mdmAccountName,
     string mdmNamespace,
     string metricName,
     string dimension1Name,
     string dimension2Name,
     string dimension3Name,
     string dimension4Name)
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         this.metric = MeasureMetric4D.Create(
             mdmAccountName,
             mdmNamespace,
             metricName,
             dimension1Name,
             dimension2Name,
             dimension3Name,
             dimension4Name,
             addDefaultDimension: true);
     }
 }