protected JSONArray transformDataToJSONArray(MetricData metricData, Set<MetricStat> filterStats) throws SerializationException { Points points = metricData.getData(); final JSONArray data = new JSONArray(); final Set<Map.Entry<Long, Points.Point>> dataPoints = points.getPoints().entrySet(); for (Map.Entry<Long, Points.Point> point : dataPoints) { data.add(toJSON(point.getKey(), point.getValue(), metricData.getUnit(), filterStats)); } return data; }
public static Points<SimpleNumber> generateFakeFullResPoints() { Points<SimpleNumber> points = new Points<SimpleNumber>(); long baseTime = 1234567L; for (int count = 0; count < 5; count++) { Points.Point<SimpleNumber> point = new Points.Point<SimpleNumber>(baseTime + (count*1000), new SimpleNumber((long) count)); points.add(point); } return points; }
protected Set<MetricStat> fixFilterStats(MetricData metricData, Set<MetricStat> filterStats) { // if no stats were entered, figure out what type we are dealing with and select out default stats. if (metricData.getData().getPoints().size() > 0 && filterStats == PlotRequestParser.DEFAULT_STATS) { Class dataClass = metricData.getData().getDataClass(); if (dataClass.equals(BasicRollup.class)) filterStats = PlotRequestParser.DEFAULT_BASIC; else if (dataClass.equals(BluefloodGaugeRollup.class)) filterStats = PlotRequestParser.DEFAULT_GAUGE; else if (dataClass.equals(BluefloodCounterRollup.class)) filterStats = PlotRequestParser.DEFAULT_COUNTER; else if (dataClass.equals(BluefloodSetRollup.class)) filterStats = PlotRequestParser.DEFAULT_SET; else if (dataClass.equals(BluefloodTimerRollup.class)) filterStats = PlotRequestParser.DEFAULT_TIMER; // else, I got nothing. } return filterStats; }
public static Points<BluefloodGaugeRollup> generateFakeGaugeRollups() { Points<BluefloodGaugeRollup> points = new Points<BluefloodGaugeRollup>(); long startTime = 1234567L; for (int i = 0; i < 5; i++) { long timeNow = startTime + i*1000; Points.Point<BluefloodGaugeRollup> point = new Points.Point<BluefloodGaugeRollup>(timeNow, new BluefloodGaugeRollup() .withLatest(timeNow, i)); points.add(point); } return points; }
boolean hasAllZeroData(MetricData dataPoints) { boolean allZeroFlag = true; // Points should be of type BasicRollup. Will throw an exception if they are not. Map<Long, Points.Point<BasicRollup>> points = dataPoints.getData().getPoints(); for (Map.Entry<Long, Points.Point<BasicRollup>> entry : points.entrySet()) { BasicRollup basicRollup = entry.getValue().getData(); if((basicRollup.getMaxValue().isFloatingPoint() ? basicRollup.getMaxValue().toDouble() != 0.0 : basicRollup.getMaxValue().toLong() != 0) && (basicRollup.getMinValue().isFloatingPoint() ? basicRollup.getMinValue().toDouble() != 0.0 : basicRollup.getMinValue().toLong() != 0) && (basicRollup.getAverage().isFloatingPoint() ? basicRollup.getAverage().toDouble() != 0.0 : basicRollup.getAverage().toLong() != 0)) { allZeroFlag = false; break; } } return allZeroFlag; }
public static Points<BasicRollup> generateFakeRollupPoints() { Points<BasicRollup> points = new Points<BasicRollup>(); long baseTime = 1234567L; for (int count = 0; count < 5; count++) { final BasicRollup basicRollup = new BasicRollup(); basicRollup.setCount(count * 100); basicRollup.getAverage().setLongValue(count); Points.Point<BasicRollup> point = new Points.Point<BasicRollup>(baseTime + (count*1000), basicRollup); points.add(point); } return points; }
final Points.Point point = (Points.Point) metricData.getData().getPoints().get(dataJSON.get("timestamp"));
public static Points<BluefloodSetRollup> generateFakeSetRollupPoints() { Points<BluefloodSetRollup> points = new Points<BluefloodSetRollup>(); long startTime = 1234567L; for (int i = 0; i < 5; i++) { long timeNow = startTime + i*1000; Points.Point<BluefloodSetRollup> point = new Points.Point<BluefloodSetRollup>(timeNow, new BluefloodSetRollup() .withObject(i) .withObject(i % 2) .withObject(i / 2)); points.add(point); } return points; }
@Test public void testTransformRollupDataAtFullRes() throws Exception { final JSONBasicRollupsOutputSerializer serializer = new JSONBasicRollupsOutputSerializer(); final MetricData metricData = new MetricData(FakeMetricDataGenerator.generateFakeFullResPoints(), "unknown"); JSONObject metricDataJSON = serializer.transformRollupData(metricData, filterStats); final JSONArray data = (JSONArray) metricDataJSON.get("values"); // Assert that we have some data to test Assert.assertTrue(data.size() > 0); for (int i = 0; i < data.size(); i++) { final JSONObject dataJSON = (JSONObject) data.get(i); final Points.Point<SimpleNumber> point = (Points.Point<SimpleNumber>) metricData.getData().getPoints().get(dataJSON.get("timestamp")); Assert.assertEquals(point.getData().getValue(), dataJSON.get("average")); Assert.assertEquals(point.getData().getValue(), dataJSON.get("min")); Assert.assertEquals(point.getData().getValue(), dataJSON.get("max")); // Assert that variance isn't present Assert.assertNull(dataJSON.get("variance")); // Assert numPoints isn't present Assert.assertNull(dataJSON.get("numPoints")); // Assert sum isn't present Assert.assertNull(dataJSON.get("sum")); } }
public static Points<BluefloodCounterRollup> generateFakeCounterRollupPoints() { Points<BluefloodCounterRollup> points = new Points<BluefloodCounterRollup>(); long startTime = 1234567L; for (int i = 0; i < 5; i++) { long timeNow = startTime + i*1000; Points.Point<BluefloodCounterRollup> point = new Points.Point<BluefloodCounterRollup>(timeNow, new BluefloodCounterRollup() .withCount(i + 1000) .withRate((double) i) .withSampleCount(i+1)); points.add(point); } return points; }
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; }
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; } }