private TimerMetric(TimeUnit durationUnit, TimeUnit rateUnit, MeterMetric meter, HistogramMetric histogram, bool clear) { DurationUnit = durationUnit; RateUnit = rateUnit; _meter = meter; _histogram = histogram; if (clear) { Clear(); } }
/// <summary> /// Creates a new meter metric and registers it under the given type and name /// </summary> /// <param name="owner">The type that owns the metric</param> /// <param name="name">The metric name</param> /// <param name="eventType">The plural name of the type of events the meter is measuring (e.g., <code>"requests"</code>)</param> /// <param name="rateUnit">The rate unit of the new meter</param> /// <returns></returns> public MeterMetric Meter(Type owner, string name, string eventType, TimeUnit rateUnit) { var metricName = new MetricName(owner, name); if (_store.TryGetValue(metricName, out var existingMetric)) { return((MeterMetric)existingMetric); } var metric = MeterMetric.New(metricName, eventType, rateUnit); var added = _store.GetOrAdd(metricName, metric); return(added == null ? metric : (MeterMetric)added); }
public IImmutableDictionary <MetricName, IMetric> GetSample(MetricType typeFilter = MetricType.All) { if (typeFilter.HasFlagFast(MetricType.All)) { return(NoSample); } var filtered = new Dictionary <MetricName, IMetric>(); foreach (var entry in _inner) { switch (entry.Value) { case GaugeMetric _ when typeFilter.HasFlagFast(MetricType.Gauge): case CounterMetric _ when typeFilter.HasFlagFast(MetricType.Counter): case MeterMetric _ when typeFilter.HasFlagFast(MetricType.Meter): case HistogramMetric _ when typeFilter.HasFlagFast(MetricType.Histogram): case TimerMetric _ when typeFilter.HasFlagFast(MetricType.Timer): continue; default: filtered.Add(entry.Key, entry.Value); break; } } return(filtered.ToImmutableSortedDictionary(k => k.Key, v => { return v.Value switch { GaugeMetric gauge => gauge.Copy(), CounterMetric counter => counter.Copy(), MeterMetric meter => meter.Copy(), HistogramMetric histogram => histogram.Copy(), TimerMetric timer => timer.Copy(), _ => throw new ArgumentException() }; }));
internal TimerMetric(MetricName metricName, TimeUnit durationUnit, TimeUnit rateUnit) : this(durationUnit, rateUnit, MeterMetric.New(metricName, "updates", rateUnit), new HistogramMetric(metricName, SampleType.Biased), true) { Name = metricName; }