예제 #1
0
        protected override double Combine(List <Sample> samples, MetricConfig config, long now)
        {
            double total = 0.0;

            foreach (var sample in samples)
            {
                total += sample.Value;
            }
            return(total);
        }
예제 #2
0
        public void Record(MetricConfig config, double value, long timeMs)
        {
            Sample sample = Current(timeMs);

            if (sample.IsComplete(timeMs, config))
            {
                sample = Advance(config, timeMs);
            }
            Update(sample, config, value, timeMs);
            sample.EventCount += 1;
        }
예제 #3
0
        internal void PurgeObsoleteSamples(MetricConfig config, long now)
        {
            long expireAge = config.Samples * config.TimeWindowMs;

            foreach (Sample sample in samples)
            {
                if (now - sample.LastWindowMs >= expireAge)
                {
                    sample.Reset(now);
                }
            }
        }
예제 #4
0
        protected override double Combine(List <Sample> samples, MetricConfig config, long now)
        {
            double total = 0.0;
            long   count = 0;

            foreach (var s in samples)
            {
                total += s.Value;
                count += s.EventCount;
            }

            return(count == 0 ? Double.NaN : total / count);
        }
예제 #5
0
        protected override double Combine(List <Sample> samples, MetricConfig config, long now)
        {
            double min   = Double.MaxValue;
            long   count = 0;

            foreach (var s in samples)
            {
                min    = Math.Min(min, s.Value);
                count += s.EventCount;
            }

            return(count == 0 ? Double.NaN : min);
        }
예제 #6
0
        protected override double Combine(List <Sample> samples, MetricConfig config, long now)
        {
            double max   = Double.NegativeInfinity;
            long   count = 0;

            foreach (var s in samples)
            {
                max    = Math.Max(max, s.Value);
                count += s.EventCount;
            }

            return(count == 0 ? Double.NaN : max);
        }
예제 #7
0
 private Sample Advance(MetricConfig config, long timeMs)
 {
     current = (current + 1) % config.Samples;
     if (current >= samples.Count)
     {
         Sample sample = NewSample(timeMs);
         samples.Add(sample);
         return(sample);
     }
     else
     {
         Sample sample = Current(timeMs);
         sample.Reset(timeMs);
         return(sample);
     }
 }
예제 #8
0
 public bool IsComplete(long timeMs, MetricConfig config)
 {
     return(timeMs - LastWindowMs >= config.TimeWindowMs || EventCount >= config.EventWindow);
 }
예제 #9
0
 protected override void Update(Sample sample, MetricConfig config, double value, long timeMs)
 {
     sample.Value += value;
 }
예제 #10
0
        public double Measure(MetricConfig config, long now)
        {
            double value = internalStat.Measure(config, now);

            return(value / timeUnit.Convert(WindowSize(config, now)));
        }
예제 #11
0
 public void Record(MetricConfig config, double value, long timeMs)
 => internalStat.Record(config, value, timeMs);
예제 #12
0
 protected override void Update(Sample sample, MetricConfig config, double value, long timeMs)
 {
     sample.Value = Math.Max(sample.Value, value);
 }
 object IGauge.Value(MetricConfig config, long now)
 => Value(config, now);
 public T Value(MetricConfig config, long now)
 => provider();
예제 #15
0
 public double Measure(MetricConfig config, long now)
 {
     PurgeObsoleteSamples(config, now);
     return(Combine(samples, config, now));
 }
예제 #16
0
 protected abstract void Update(Sample sample, MetricConfig config, double value, long timeMs);
예제 #17
0
 protected abstract double Combine(List <Sample> samples, MetricConfig config, long now);