public static Collection<PreaggregatedMetric> convertSets(String tenant, long timestamp, Collection<BluefloodSet> sets) { List<PreaggregatedMetric> list = new ArrayList<PreaggregatedMetric>(sets.size()); for (BluefloodSet set : sets) { Locator locator = Locator.createLocatorFromPathComponents(tenant, set.getName().split(NAME_DELIMITER, -1)); BluefloodSetRollup rollup = new BluefloodSetRollup(); for (String value : set.getValues()) { rollup = rollup.withObject(value); } PreaggregatedMetric metric = new PreaggregatedMetric(timestamp, locator, DEFAULT_TTL, rollup); list.add(metric); } return list; }
private static void ensureSerializability(Collection<PreaggregatedMetric> metrics) { for (PreaggregatedMetric metric : metrics) { AbstractSerializer serializer = Serializers.serializerFor(metric.getMetricValue().getClass()); serializer.toByteBuffer(metric.getMetricValue()); } }
public static Collection<PreaggregatedMetric> convertCounters(String tenant, long timestamp, long flushIntervalMillis, Collection<BluefloodCounter> counters) { List<PreaggregatedMetric> list = new ArrayList<PreaggregatedMetric>(counters.size()); for (BluefloodCounter counter : counters) { Locator locator = Locator.createLocatorFromPathComponents(tenant, counter.getName().split(NAME_DELIMITER, -1)); // flushIntervalMillis could be zero (if not specified in the statsD config). long sampleCount = flushIntervalMillis > 0 ? (long)(counter.getRate().doubleValue() * ((double)flushIntervalMillis/1000d)) : 1; Rollup rollup = new BluefloodCounterRollup() .withCount(resolveNumber(counter.getValue())) .withRate(counter.getRate().doubleValue()) .withSampleCount((int)sampleCount); PreaggregatedMetric metric = new PreaggregatedMetric(timestamp, locator, DEFAULT_TTL, rollup); list.add(metric); } return list; }
private static void ensureSerializability(Collection<PreaggregatedMetric> metrics) { for (PreaggregatedMetric metric : metrics) { AbstractSerializer serializer = Serializers.serializerFor(metric.getMetricValue().getClass()); serializer.toByteBuffer(metric.getMetricValue()); } }
public static Collection<PreaggregatedMetric> convertGauges(String tenant, long timestamp, Collection<BluefloodGauge> gauges) { List<PreaggregatedMetric> list = new ArrayList<PreaggregatedMetric>(gauges.size()); for (BluefloodGauge gauge : gauges) { Locator locator = Locator.createLocatorFromPathComponents(tenant, gauge.getName().split(NAME_DELIMITER, -1)); Points<SimpleNumber> points = new Points<SimpleNumber>(); points.add(new Points.Point<SimpleNumber>(timestamp, new SimpleNumber(resolveNumber(gauge.getValue())))); try { Rollup rollup = BluefloodGaugeRollup.buildFromRawSamples(points); PreaggregatedMetric metric = new PreaggregatedMetric(timestamp, locator, DEFAULT_TTL, rollup); list.add(metric); } catch (IOException ex) { throw new IOError(ex); } } return list; }
protected static List<IMetric> createTestMetricsFromInterface(String tenantId) { IMetric metric; List<IMetric> metrics = new ArrayList<>(); BluefloodCounterRollup counter = new BluefloodCounterRollup(); List<Locator> locators = createComplexTestLocators(tenantId); for (Locator locator : locators) { metric = new PreaggregatedMetric(0, locator, new TimeValue(1, TimeUnit.DAYS), counter); metrics.add(metric); } return metrics; }
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; }