private GaugeAggregatorStrategy GetAggregatorStategy() { var type = GetType(); if (_aggregatorsByTypeCache.ContainsKey(type)) { return(_aggregatorsByTypeCache[type]); } lock (_aggregatorsByTypeCache) { if (_aggregatorsByTypeCache.ContainsKey(type)) { return(_aggregatorsByTypeCache[type]); } var aggregators = GetType().GetCustomAttributes <GaugeAggregatorAttribute>(false).ToList().AsReadOnly(); if (aggregators.Count == 0) { throw new Exception(GetType().FullName + " has no GaugeAggregator attributes. All gauges must have at least one."); } var hash = new HashSet <string>(); foreach (var r in aggregators) { if (hash.Contains(r.Suffix)) { throw new Exception($"{type.FullName} has more than one gauge aggregator with the name \"{r.Suffix}\"."); } } return(_aggregatorsByTypeCache[type] = new GaugeAggregatorStrategy(aggregators)); } }
GaugeAggregatorStrategy GetAggregatorStategy() { var type = GetType(); if (s_aggregatorsByTypeCache.ContainsKey(type)) { return(s_aggregatorsByTypeCache[type]); } lock (s_aggregatorsByTypeCache) { if (s_aggregatorsByTypeCache.ContainsKey(type)) { return(s_aggregatorsByTypeCache[type]); } var attributes = GetGaugeAggregatorAttributes(type); var hash = new HashSet <string>(); foreach (var attr in attributes) { if (hash.Contains(attr.Suffix)) { throw new Exception($"{type.FullName} has more than one gauge aggregator with the name \"{attr.Suffix}\"."); } hash.Add(attr.Suffix); } return(s_aggregatorsByTypeCache[type] = new GaugeAggregatorStrategy(attributes)); } }
public AggregateGauge() { _aggregatorStrategy = GetAggregatorStategy(); // denormalize these for one less level of indirection _trackMean = _aggregatorStrategy.TrackMean; _specialCaseMin = _aggregatorStrategy.SpecialCaseMin; _specialCaseMax = _aggregatorStrategy.SpecialCaseMax; _specialCaseLast = _aggregatorStrategy.SpecialCaseLast; _reportCount = _aggregatorStrategy.ReportCount; // setup heap, if required. if (_aggregatorStrategy.UseList) _list = new List<double>(); }
public AggregateGauge() { _aggregatorStrategy = GetAggregatorStategy(); // denormalize these for one less level of indirection _trackMean = _aggregatorStrategy.TrackMean; _specialCaseMin = _aggregatorStrategy.SpecialCaseMin; _specialCaseMax = _aggregatorStrategy.SpecialCaseMax; _specialCaseLast = _aggregatorStrategy.SpecialCaseLast; _reportCount = _aggregatorStrategy.ReportCount; // setup heap, if required. if (_aggregatorStrategy.UseList) { _list = new List <double>(); } }
/// <summary> /// Instantiates a new <see cref="AggregateGauge"/>. /// </summary> public AggregateGauge(IEnumerable <GaugeAggregator> aggregators, string name, string unit, string description, MetricSourceOptions options, ImmutableDictionary <string, string> tags = null) : base(name, unit, description, options, tags) { var strategy = new GaugeAggregatorStrategy(aggregators.ToImmutableArray()); // denormalize these for one less level of indirection _percentiles = strategy.Percentiles; _suffixes = strategy.Suffixes; _trackMean = strategy.TrackMean; _specialCaseMin = strategy.SpecialCaseMin; _specialCaseMax = strategy.SpecialCaseMax; _specialCaseLast = strategy.SpecialCaseLast; _reportCount = strategy.ReportCount; // setup heap, if required. if (strategy.UseList) { _list = new List <double>(); } _snapshot = new double[_suffixes.Length]; _snapshotReportingMode = SnapshotReportingMode.None; }
private GaugeAggregatorStrategy GetAggregatorStategy() { var type = GetType(); if (_aggregatorsByTypeCache.ContainsKey(type)) return _aggregatorsByTypeCache[type]; lock (_aggregatorsByTypeCache) { if (_aggregatorsByTypeCache.ContainsKey(type)) return _aggregatorsByTypeCache[type]; var aggregators = GetType().GetCustomAttributes<GaugeAggregatorAttribute>(false).ToList().AsReadOnly(); if (aggregators.Count == 0) throw new Exception(GetType().FullName + " has no GaugeAggregator attributes. All gauges must have at least one."); var hash = new HashSet<string>(); foreach (var r in aggregators) { if (hash.Contains(r.Suffix)) throw new Exception($"{type.FullName} has more than one gauge aggregator with the name \"{r.Suffix}\"."); } return _aggregatorsByTypeCache[type] = new GaugeAggregatorStrategy(aggregators); } }