/// <summary> /// Set the configuration returned from <c>MetricConfigurations.Common.Measurement()</c>. /// </summary> /// <param name="metricConfigPresets">Will be ignored.</param> /// <param name="defaultConfigurationForMeasurement">Future default config.</param> public static void SetDefaultForMeasurement( this MetricConfigurations metricConfigPresets, MetricConfigurationForMeasurement defaultConfigurationForMeasurement) { Util.ValidateNotNull( defaultConfigurationForMeasurement, nameof(defaultConfigurationForMeasurement)); Util.ValidateNotNull( defaultConfigurationForMeasurement.SeriesConfig, nameof(defaultConfigurationForMeasurement) + "." + nameof(defaultConfigurationForMeasurement.SeriesConfig)); s_defaultConfigForMeasurement = defaultConfigurationForMeasurement; }
/// <summary> /// Groups constants used my metric aggregates produced by aggregators that are configured by metric configurations represented /// through instances of <see cref="MetricConfigurationForMeasurement"/>. See also <c>MetricConfigurations.Common.Measurement()</c>./> /// </summary> /// <param name="measurementConfig">@ToDo: Complete documentation before stable release. {276}</param> /// <returns>@ToDo: Complete documentation before stable release. {564}</returns> public static MetricSeriesConfigurationForMeasurement.AggregateKindConstants Constants(this MetricConfigurationForMeasurement measurementConfig) { return(MetricSeriesConfigurationForMeasurement.AggregateKindConstants.Instance); }
/// <summary> /// Initializes the privates and activates them atomically. /// </summary> /// <param name="maxDependencyTypesToDiscoverCount">Max number of Dependency Types to discover.</param> private void ReinitializeMetrics(int maxDependencyTypesToDiscoverCount) { if (maxDependencyTypesToDiscoverCount < 0) { throw new ArgumentOutOfRangeException( nameof(maxDependencyTypesToDiscoverCount), maxDependencyTypesToDiscoverCount, Invariant($"{nameof(this.MaxDependencyTypesToDiscover)} value may not be negative.")); } lock (this.initializationLock) { if (maxDependencyTypesToDiscoverCount > Int32.MaxValue - 3) { maxDependencyTypesToDiscoverCount = Int32.MaxValue - 3; } int depTypesDimValuesLimit = (maxDependencyTypesToDiscoverCount == 0) // "Other": ? 1 // Discovered types + "Unknown" (when type not set) + "Other" (when limit reached): : maxDependencyTypesToDiscoverCount + 2; TelemetryClient thisMetricTelemetryClient = this.metricTelemetryClient; //// If there is no TelemetryClient, then this extractor has not been properly initialized yet. //// We set maxDependencyTypesToDiscover and return: if (thisMetricTelemetryClient == null) { this.dependencyCallDurationMetric = null; this.maxDependencyTypesToDiscover = maxDependencyTypesToDiscoverCount; return; } //// Remove the old metric before creating the new one: MetricManager metricManager; if (thisMetricTelemetryClient.TryGetMetricManager(out metricManager)) { Metric oldMetric = this.dependencyCallDurationMetric; metricManager.Metrics.Remove(oldMetric); } MetricConfiguration config = new MetricConfigurationForMeasurement( (1 * 2 * depTypesDimValuesLimit) + 1, new[] { 1, 2, depTypesDimValuesLimit }, new MetricSeriesConfigurationForMeasurement(restrictToUInt32Values: false)); Metric dependencyCallDuration = thisMetricTelemetryClient.GetMetric( metricId: MetricTerms.Autocollection.Metric.DependencyCallDuration.Name, dimension1Name: MetricDimensionNames.TelemetryContext.Property(MetricTerms.Autocollection.MetricId.Moniker.Key), dimension2Name: MetricTerms.Autocollection.DependencyCall.PropertyNames.Success, dimension3Name: MetricTerms.Autocollection.DependencyCall.PropertyNames.TypeName, metricConfiguration: config, aggregationScope: MetricAggregationScope.TelemetryClient); // "Pre-book" series for "special" dependenty type monikers to make sure they are not affected by dimension caps: MetricSeries prebookedSeries; dependencyCallDuration.TryGetDataSeries( out prebookedSeries, MetricTerms.Autocollection.Metric.DependencyCallDuration.Id, Boolean.TrueString, MetricTerms.Autocollection.DependencyCall.TypeNames.Other); dependencyCallDuration.TryGetDataSeries( out prebookedSeries, MetricTerms.Autocollection.Metric.DependencyCallDuration.Id, Boolean.FalseString, MetricTerms.Autocollection.DependencyCall.TypeNames.Other); if (maxDependencyTypesToDiscoverCount != 0) { dependencyCallDuration.TryGetDataSeries( out prebookedSeries, MetricTerms.Autocollection.Metric.DependencyCallDuration.Id, Boolean.TrueString, MetricTerms.Autocollection.DependencyCall.TypeNames.Unknown); dependencyCallDuration.TryGetDataSeries( out prebookedSeries, MetricTerms.Autocollection.Metric.DependencyCallDuration.Id, Boolean.FalseString, MetricTerms.Autocollection.DependencyCall.TypeNames.Unknown); } // Benign race where dependencyCallDurationMetric config and maxDependencyTypesToDiscover may not correspond briefly: this.dependencyCallDurationMetric = dependencyCallDuration; this.maxDependencyTypesToDiscover = maxDependencyTypesToDiscoverCount; } }
public void InitializeExtractor(TelemetryClient metricTelemetryClient) { if (metricTelemetryClient == null) { this.exceptionServerMetric = null; return; } if (!this.isInitialized) { lock (this.lockObject) { if (!this.isInitialized) { this.dimensionExtractors.Add(new ExceptionMetricIdDimensionExtractor()); this.dimensionExtractors.Add(new CloudRoleInstanceDimensionExtractor() { MaxValues = this.MaxCloudRoleInstanceValuesToDiscover }); this.dimensionExtractors.Add(new CloudRoleNameDimensionExtractor() { MaxValues = this.MaxCloudRoleNameValuesToDiscover }); int seriesCountLimit = 1; int[] valuesPerDimensionLimit = new int[this.dimensionExtractors.Count]; int i = 0; foreach (var dim in this.dimensionExtractors) { int dimLimit = 1; dimLimit = dim.MaxValues == 0 ? 1 : dim.MaxValues; seriesCountLimit = seriesCountLimit * (1 + dimLimit); valuesPerDimensionLimit[i++] = dimLimit; } MetricConfiguration config = new MetricConfigurationForMeasurement( seriesCountLimit, valuesPerDimensionLimit, new MetricSeriesConfigurationForMeasurement(restrictToUInt32Values: false)); config.ApplyDimensionCapping = true; config.DimensionCappedString = MetricTerms.Autocollection.Common.PropertyValues.DimensionCapFallbackValue; IList <string> dimensionNames = new List <string>(this.dimensionExtractors.Count); for (i = 0; i < this.dimensionExtractors.Count; i++) { dimensionNames.Add(this.dimensionExtractors[i].Name); } MetricIdentifier metricIdentifier = new MetricIdentifier(MetricIdentifier.DefaultMetricNamespace, MetricTerms.Autocollection.Metric.ExceptionCount.Name, dimensionNames); this.exceptionServerMetric = metricTelemetryClient.GetMetric( metricIdentifier: metricIdentifier, metricConfiguration: config, aggregationScope: MetricAggregationScope.TelemetryClient); this.isInitialized = true; } } } }