Jagger
 All Classes Namespaces Files Functions Variables Enumerator Groups Pages
PercentileAggregatorProvider.java
Go to the documentation of this file.
1 package com.griddynamics.jagger.engine.e1.collector;
2 
3 import com.griddynamics.jagger.util.statistics.StatisticsCalculator;
4 
9 public class PercentileAggregatorProvider implements MetricAggregatorProvider {
10  private Double percentile = 95D;
11 
12  public PercentileAggregatorProvider(Double percentile) {
13  this.percentile = percentile;
14  }
15 
17 
18  @Override
20  return new PercentileAggregator();
21  }
22 
23  private class PercentileAggregator implements MetricAggregator<Number> {
24  private StatisticsCalculator statisticsCalculator = new StatisticsCalculator();
25 
26  @Override
27  public void append(Number calculated) {
28  statisticsCalculator.addValue(calculated.doubleValue());
29  }
30 
31  @Override
32  public Number getAggregated() {
33  Double result = statisticsCalculator.getPercentile(percentile);
34  return result.isNaN() ? null : result;
35  }
36 
37  @Override
38  public void reset() {
39  statisticsCalculator.reset();
40  }
41 
42  @Override
43  public String getName() {
44  return percentile + "%";
45  }
46  }
47 }