Exemplo n.º 1
0
        public IImmutableDictionary <MetricName, IMetric> GetSample(MetricType excludeTypes = MetricType.None)
        {
            if (excludeTypes.HasFlagFast(MetricType.All))
            {
                return(NoSample);
            }

            var filtered = new Dictionary <MetricName, IMetric>();

            foreach (var entry in _cache.Get <List <MetricName> >(Common.Constants.Categories.Metrics))
            {
                switch (entry.Class.Name)
                {
                case nameof(GaugeMetric) when excludeTypes.HasFlagFast(MetricType.Gauge):
                case nameof(CounterMetric) when excludeTypes.HasFlagFast(MetricType.Counter):
                case nameof(MeterMetric) when excludeTypes.HasFlagFast(MetricType.Meter):
                case nameof(HistogramMetric) when excludeTypes.HasFlagFast(MetricType.Histogram):
                case nameof(TimerMetric) when excludeTypes.HasFlagFast(MetricType.Timer):
                    continue;

                default:
                    filtered.Add(entry, _cache.Get <IMetric>(entry.CacheKey));
                    break;
                }
            }

            return(filtered.ToImmutableDictionary());
        }
Exemplo n.º 2
0
        public IImmutableDictionary <MetricName, IMetric> GetSample(MetricType typeFilter = MetricType.None)
        {
            if (typeFilter.HasFlagFast(MetricType.All))
            {
                return(NoSample);
            }

            var filtered = new Dictionary <MetricName, IMetric>();

            foreach (var entry in _metrics)
            {
                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.ToImmutableDictionary());
        }
Exemplo n.º 3
0
        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()
                };
            }));
Exemplo n.º 4
0
 public IImmutableDictionary <MetricName, GaugeMetric <bool> > GetSample(MetricType typeFilter = MetricType.None)
 {
     return(typeFilter.HasFlagFast(MetricType.All) ? NoSample : _metrics.ToImmutableDictionary());
 }