/// <summary> /// Initializes a new instance of the <see cref="RatioCounterGauge"/> class. /// </summary> /// <param name="name"> Name of the RatioCounterGauge.</param> /// <param name="numeratorGauge">The numerator for computing the ratio.</param> /// <param name="denominatorGauge">The denominator for computing the ratio.</param> /// <param name="scale">Scale to measure the percentage or increase the scaling of the ratio.</param> public RatioCounterGauge(string name, ICounterValue numeratorGauge, ICounterValue denominatorGauge, double scale = 1) { this.name = name; this.numeratorGauge = numeratorGauge; this.denominatorGauge = denominatorGauge; this.scale = scale; }
/// <summary> /// Initializes a new instance of the <see cref="RateCounterGauge"/> class. /// This constructor is intended for Unit Tests. /// </summary> /// <param name="name"> Name of the counter variable.</param> /// <param name="jsonId">JSON identifier of the counter variable.</param> /// <param name="environmentVariable"> Identifier of the corresponding environment variable.</param> /// <param name="counter">Dependant counter.</param> /// <param name="cache"> Cache object.</param> internal RateCounterGauge(string name, string jsonId, AzureWebApEnvironmentVariables environmentVariable, ICounterValue counter, ICachedEnvironmentVariableAccess cache) { this.name = name; this.jsonId = jsonId; this.environmentVariable = environmentVariable; this.counter = counter; this.cacheHelper = cache; }
/// <summary> /// Collects a value for a single counter. /// </summary> private static double CollectCounter(string coutnerOriginalString, ICounterValue counter) { try { return counter.GetValueAndReset(); } catch (Exception e) { throw new InvalidOperationException( string.Format( CultureInfo.CurrentCulture, Resources.WebAppPerformanceCounterReadFailed, coutnerOriginalString), e); } }
/// <summary> /// Register a performance counter for collection. /// </summary> /// <param name="originalString">Original string definition of the counter.</param> /// <param name="reportAs">Alias to report the counter as.</param> /// <param name="categoryName">Category name.</param> /// <param name="counterName">Counter name.</param> /// <param name="instanceName">Instance name.</param> /// <param name="usesInstanceNamePlaceholder">Indicates whether the counter uses a placeholder in the instance name.</param> /// <param name="isCustomCounter">Indicates whether the counter is a custom counter.</param> private void RegisterPerformanceCounter(string originalString, string reportAs, string categoryName, string counterName, string instanceName, bool usesInstanceNamePlaceholder, bool isCustomCounter) { ICounterValue performanceCounter = null; try { performanceCounter = this.factory.GetCounter(originalString, categoryName, counterName, instanceName); } catch (Exception e) { // we want to have another crack at it if instance placeholder is used, // notably due to the fact that CLR process ID counter only starts returning values after the first garbage collection if (!usesInstanceNamePlaceholder) { throw new InvalidOperationException( string.Format( CultureInfo.CurrentCulture, Resources.PerformanceCounterRegistrationFailed, categoryName, counterName, instanceName), e); } } bool firstReadOk = false; try { // perform the first read. For many counters the first read will always return 0 // since a single sample is not enough to calculate a value performanceCounter.Collect(); firstReadOk = true; } catch (Exception e) { throw new InvalidOperationException( string.Format( CultureInfo.CurrentCulture, Resources.PerformanceCounterFirstReadFailed, categoryName, counterName, instanceName), e); } finally { PerformanceCounterData perfData = new PerformanceCounterData( originalString, reportAs, usesInstanceNamePlaceholder, isCustomCounter, !firstReadOk, categoryName, counterName, instanceName); this.performanceCounters.Add(new Tuple <PerformanceCounterData, ICounterValue>(perfData, performanceCounter)); } }
/// <summary> /// Registers counter for periodic extraction into telemetry configuration. /// </summary> /// <param name="configuration">Telemetry configuration to store the counter.</param> /// <param name="counter">Counter vaue interface implementation.</param> public static void RegisterCounter(this TelemetryConfiguration configuration, ICounterValue counter) { var countersCollection = counters.GetValue(configuration, CreateEmptyDictionary); countersCollection.Add(counter); }
/// <summary> /// Initializes a new instance of the <see cref="CPUPercenageGauge"/> class. /// </summary> /// <param name="name"> Name of the SumUpCountersGauge.</param> /// <param name="value"> Gauges to sum.</param> public CPUPercenageGauge(string name, ICounterValue value) { this.name = name; this.valueProvider = value; }
/// <summary> /// Initializes a new instance of the <see cref="RateCounterGauge"/> class. /// </summary> /// <param name="name"> Name of counter variable.</param> /// <param name="jsonId">JSON identifier of the counter variable.</param> /// <param name="environmentVariable"> Identifier of the corresponding environment variable.</param> /// <param name="counter">Dependant counter.</param> public RateCounterGauge(string name, string jsonId, AzureWebApEnvironmentVariables environmentVariable, ICounterValue counter = null) : this(name, jsonId, environmentVariable, counter, CacheHelper.Instance) { }