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); }
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; }
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); } } }
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); }
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); }
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); }
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); } }
public bool IsComplete(long timeMs, MetricConfig config) { return(timeMs - LastWindowMs >= config.TimeWindowMs || EventCount >= config.EventWindow); }
protected override void Update(Sample sample, MetricConfig config, double value, long timeMs) { sample.Value += value; }
public double Measure(MetricConfig config, long now) { double value = internalStat.Measure(config, now); return(value / timeUnit.Convert(WindowSize(config, now))); }
public void Record(MetricConfig config, double value, long timeMs) => internalStat.Record(config, value, timeMs);
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();
public double Measure(MetricConfig config, long now) { PurgeObsoleteSamples(config, now); return(Combine(samples, config, now)); }
protected abstract void Update(Sample sample, MetricConfig config, double value, long timeMs);
protected abstract double Combine(List <Sample> samples, MetricConfig config, long now);