コード例 #1
0
ファイル: IfxMetricsFactory.cs プロジェクト: Azure/RingMaster
 public Metric0DWrapper(string mdmAccountName, string mdmNamespace, string metricName)
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         this.metric = MeasureMetric0D.Create(mdmAccountName, mdmNamespace, metricName, addDefaultDimension: true);
     }
 }
コード例 #2
0
        public static MetricLogger Create(
            Context context,
            string?monitoringAccount,
            string logicalNameSpace,
            string metricName,
            bool addDefaultDimensions,
            IEnumerable <Dimension> dimensions)
        {
            if (string.IsNullOrEmpty(monitoringAccount))
            {
                return(NoOpMetricLogger.Instance);
            }

            // For some reason the generic MeasureMetric class does not work with 0 dimensions.  There is a special
            // class (MeasureMetric0D) that does metrics without any dimensions.
            var dimensionNames = dimensions.Select(d => d.Name).ToArray();

            Tracer.Debug(context, $"Initializing Mdm logger {logicalNameSpace}:{metricName}");
            var error = new ErrorContext();

            MeasureMetric?  measureMetric   = null;
            MeasureMetric0D?measureMetric0D = null;

            // Very important not to forget to pass true for addDefaultDimension argument since the default is false.
            if (dimensionNames.Length > 0)
            {
                measureMetric = MeasureMetric.Create(monitoringAccount, logicalNameSpace, metricName, ref error, addDefaultDimension: addDefaultDimensions, dimensionNames);
            }
            else
            {
                measureMetric0D = MeasureMetric0D.Create(monitoringAccount, logicalNameSpace, metricName, ref error, addDefaultDimension: addDefaultDimensions);
            }

            if (error.ErrorCode != 0)
            {
                Tracer.Error(context, $"Fail to create MeasureMetric. {logicalNameSpace}:{metricName} ErrorCode: {error.ErrorCode} ErrorMessage: {error.ErrorMessage}. Metrics would be disabled!");
                return(NoOpMetricLogger.Instance);
            }

            return(new WindowsMetricLogger(context, logicalNameSpace, metricName, measureMetric, measureMetric0D));
        }