public static Collection<PreaggregatedMetric> convertTimers(String tenant, long timestamp, Collection<BluefloodTimer> timers) { List<PreaggregatedMetric> list = new ArrayList<PreaggregatedMetric>(timers.size()); for (BluefloodTimer timer : timers) { Locator locator = Locator.createLocatorFromPathComponents(tenant, timer.getName().split(NAME_DELIMITER, -1)); BluefloodTimerRollup rollup = new BluefloodTimerRollup() .withCount(timer.getCount().longValue()) .withSampleCount(1) .withAverage(resolveNumber(timer.getAvg() == null ? 0.0d : timer.getAvg())) .withMaxValue(resolveNumber(timer.getMax() == null ? 0.0d : timer.getMax())) .withMinValue(resolveNumber(timer.getMin() == null ? 0.0d : timer.getMin())) .withCountPS(timer.getRate() == null ? 0.0d : timer.getRate().doubleValue()) .withSum(timer.getSum() == null ? 0L : timer.getSum().doubleValue()) .withVariance(Math.pow(timer.getStd() == null ? 0.0d : timer.getStd().doubleValue(), 2d)); for (Map.Entry<String, Percentile> entry : timer.getPercentiles().entrySet()) { // throw away max and sum. if (entry.getValue().getAvg() != null) { rollup.setPercentile(entry.getKey(), resolveNumber(entry.getValue().getAvg())); } } PreaggregatedMetric metric = new PreaggregatedMetric(timestamp, locator, DEFAULT_TTL, rollup); list.add(metric); } return list; }
public static Points<BluefloodTimerRollup> generateFakeTimerRollups() { Points<BluefloodTimerRollup> points = new Points<BluefloodTimerRollup>(); long startTime = 1234567L; for (int i = 0; i < 5; i++) { long timeNow = startTime + i*1000; BluefloodTimerRollup rollup = new BluefloodTimerRollup() .withAverage(i) .withCount(i) .withCountPS(i*0.1d) .withMaxValue(i) .withMinValue(i) .withSum(Double.valueOf(i+i)) .withVariance(i); rollup.setPercentile("50", i); rollup.setPercentile("99", i * 2 + 1); Points.Point<BluefloodTimerRollup> point = new Points.Point<BluefloodTimerRollup>(timeNow, rollup); points.add(point); } return points; } }