@Override public long interpolate(TimeValue start, TimeValue end, long ts) { if (start == null) { throw new NullPointerException("start cannot be null"); } if (end == null) { throw new NullPointerException("end cannot be null"); } if (ts > end.getTimestamp() || ts < start.getTimestamp()) { throw new IllegalArgumentException("ts must be within given start and end"); } // if its been too many seconds between datapoints, return a 0 for everything in between. if ((end.getTimestamp() - start.getTimestamp()) > maxAllowedGap) { return 0; } return limitedInterpolate(start, end, ts); }
@Override protected long limitedInterpolate(TimeValue start, TimeValue end, long ts) { long deltaX = ts - start.getTimestamp(); long totalX = end.getTimestamp() - start.getTimestamp(); long totalY = end.getValue() - start.getValue(); long deltaY = (int) (totalY * deltaX / totalX); return start.getValue() + deltaY; } }
private MetricQueryResult.TimeValue[] decorate(List<TimeValue> points) { MetricQueryResult.TimeValue[] timeValues = new MetricQueryResult.TimeValue[points.size()]; int k = 0; for (TimeValue timeValue : points) { timeValues[k++] = new MetricQueryResult.TimeValue(timeValue.getTimestamp(), timeValue.getValue()); } return timeValues; }
private MetricQueryResult.TimeValue[] decorate(List<TimeValue> points) { MetricQueryResult.TimeValue[] timeValues = new MetricQueryResult.TimeValue[points.size()]; int k = 0; for (TimeValue timeValue : points) { timeValues[k++] = new MetricQueryResult.TimeValue(timeValue.getTimestamp(), timeValue.getValue()); } return timeValues; }
@Override public TimeValue apply(TimeValue input) { return new TimeValue(input.getTimestamp(), input.getValue()); } }).iterator();
@Override protected long limitedInterpolate(TimeValue start, TimeValue end, long ts) { return (ts < end.getTimestamp()) ? start.getValue() : end.getValue(); } }
InterpolatedAggregatorIterator() { timeseries = new BiDirectionalPeekingIterator(Iterators.peekingIterator(timeSeries.iterator())); if (timeseries.hasNext()) { currentTs = timeseries.peek().getTimestamp(); } }
InterpolatedAggregatorIterator() { timeseries = new BiDirectionalPeekingIterator(Iterators.peekingIterator(timeSeries.iterator())); if (timeseries.hasNext()) { currentTs = timeseries.peek().getTimestamp(); } }
private Collection<TimeSeries> convertToQueryResult(CubeQuery query, Table<Map<String, String>, String, Map<Long, Long>> resultTable) { List<TimeSeries> result = Lists.newArrayList(); // iterating each groupValue dimensions for (Map.Entry<Map<String, String>, Map<String, Map<Long, Long>>> row : resultTable.rowMap().entrySet()) { // iterating each measure for (Map.Entry<String, Map<Long, Long>> measureEntry : row.getValue().entrySet()) { // generating time series for a grouping and a measure int count = 0; List<TimeValue> timeValues = Lists.newArrayList(); for (Map.Entry<Long, Long> timeValue : measureEntry.getValue().entrySet()) { timeValues.add(new TimeValue(timeValue.getKey(), timeValue.getValue())); } Collections.sort(timeValues); PeekingIterator<TimeValue> timeValueItor = Iterators.peekingIterator( new TimeSeriesInterpolator(timeValues, query.getInterpolator(), query.getResolution()).iterator()); List<TimeValue> resultTimeValues = Lists.newArrayList(); while (timeValueItor.hasNext()) { TimeValue timeValue = timeValueItor.next(); resultTimeValues.add(new TimeValue(timeValue.getTimestamp(), timeValue.getValue())); if (++count >= query.getLimit()) { break; } } result.add(new TimeSeries(measureEntry.getKey(), row.getKey(), resultTimeValues)); } } return result; }
private Collection<TimeSeries> convertToQueryResult(CubeQuery query, Table<Map<String, String>, String, Map<Long, Long>> resultTable) { List<TimeSeries> result = Lists.newArrayList(); // iterating each groupValue dimensions for (Map.Entry<Map<String, String>, Map<String, Map<Long, Long>>> row : resultTable.rowMap().entrySet()) { // iterating each measure for (Map.Entry<String, Map<Long, Long>> measureEntry : row.getValue().entrySet()) { // generating time series for a grouping and a measure int count = 0; List<TimeValue> timeValues = Lists.newArrayList(); for (Map.Entry<Long, Long> timeValue : measureEntry.getValue().entrySet()) { timeValues.add(new TimeValue(timeValue.getKey(), timeValue.getValue())); } Collections.sort(timeValues); PeekingIterator<TimeValue> timeValueItor = Iterators.peekingIterator( new TimeSeriesInterpolator(timeValues, query.getInterpolator(), query.getResolution()).iterator()); List<TimeValue> resultTimeValues = Lists.newArrayList(); while (timeValueItor.hasNext()) { TimeValue timeValue = timeValueItor.next(); resultTimeValues.add(new TimeValue(timeValue.getTimestamp(), timeValue.getValue())); if (++count >= query.getLimit()) { break; } } result.add(new TimeSeries(measureEntry.getKey(), row.getKey(), resultTimeValues)); } } return result; }
Long value = result.get(seriesDimensions, next.getMeasureName()).get(timeValue.getTimestamp()); value = value == null ? 0 : value; value += timeValue.getValue(); result.get(seriesDimensions, next.getMeasureName()).put(timeValue.getTimestamp(), value); } else if (AggregationFunction.MAX == function) { Long value = result.get(seriesDimensions, next.getMeasureName()).get(timeValue.getTimestamp()); value = value != null && value > timeValue.getValue() ? value : timeValue.getValue(); result.get(seriesDimensions, next.getMeasureName()).put(timeValue.getTimestamp(), value); } else if (AggregationFunction.MIN == function) { Long value = result.get(seriesDimensions, next.getMeasureName()).get(timeValue.getTimestamp()); value = value != null && value < timeValue.getValue() ? value : timeValue.getValue(); result.get(seriesDimensions, next.getMeasureName()).put(timeValue.getTimestamp(), value); } else if (AggregationFunction.LATEST == function) { result.get(seriesDimensions, next.getMeasureName()).put(timeValue.getTimestamp(), timeValue.getValue()); } else {
Long value = result.get(seriesDimensions, next.getMeasureName()).get(timeValue.getTimestamp()); value = value == null ? 0 : value; value += timeValue.getValue(); result.get(seriesDimensions, next.getMeasureName()).put(timeValue.getTimestamp(), value); } else if (AggregationFunction.MAX == function) { Long value = result.get(seriesDimensions, next.getMeasureName()).get(timeValue.getTimestamp()); value = value != null && value > timeValue.getValue() ? value : timeValue.getValue(); result.get(seriesDimensions, next.getMeasureName()).put(timeValue.getTimestamp(), value); } else if (AggregationFunction.MIN == function) { Long value = result.get(seriesDimensions, next.getMeasureName()).get(timeValue.getTimestamp()); value = value != null && value < timeValue.getValue() ? value : timeValue.getValue(); result.get(seriesDimensions, next.getMeasureName()).put(timeValue.getTimestamp(), value); } else if (AggregationFunction.LATEST == function) { result.get(seriesDimensions, next.getMeasureName()).put(timeValue.getTimestamp(), timeValue.getValue()); } else {
@Override protected TimeValue computeNext() { long currentTsValue = 0; // no more data points in the timeseries if (!timeseries.hasNext()) { return endOfData(); } // move the iterator to the next point in this timeseries if this is an actual data point and not interpolated. if (timeseries.peek().getTimestamp() == currentTs) { currentTsValue += timeseries.peek().getValue(); timeseries.next(); } else if (interpolator != null && timeseries.peekBefore() != null) { // don't interpolate unless we're in between data points currentTsValue += interpolator.interpolate(timeseries.peekBefore(), timeseries.peek(), currentTs); } TimeValue output = new TimeValue(currentTs, currentTsValue); if (timeseries.hasNext()) { // increment the currentTs by resolution to get the next data point. currentTs = (interpolator == null) ? timeseries.peek().getTimestamp() : currentTs + resolution; } return output; }
@Override protected TimeValue computeNext() { long currentTsValue = 0; // no more data points in the timeseries if (!timeseries.hasNext()) { return endOfData(); } // move the iterator to the next point in this timeseries if this is an actual data point and not interpolated. if (timeseries.peek().getTimestamp() == currentTs) { currentTsValue += timeseries.peek().getValue(); timeseries.next(); } else if (interpolator != null && timeseries.peekBefore() != null) { // don't interpolate unless we're in between data points currentTsValue += interpolator.interpolate(timeseries.peekBefore(), timeseries.peek(), currentTs); } TimeValue output = new TimeValue(currentTs, currentTsValue); if (timeseries.hasNext()) { // increment the currentTs by resolution to get the next data point. currentTs = (interpolator == null) ? timeseries.peek().getTimestamp() : currentTs + resolution; } return output; }
if (timeValueItor.hasNext() && timeValueItor.peek().getTimestamp() == resultTimeStamp) { builder.addData(resultTimeStamp, timeValueItor.next().getValue()); } else {
private void computeProcessBusyness(MetricDataQuery query, TimeSeriesResponse.Builder builder) throws Exception { PeekingIterator<TimeValue> tuplesReadItor = Iterators.peekingIterator(queryTimeSeries(new MetricDataQuery(query, "system.process.tuples.read", AggregationFunction.SUM))); PeekingIterator<TimeValue> eventsProcessedItor = Iterators.peekingIterator(queryTimeSeries(new MetricDataQuery(query, "system.process.events.processed", AggregationFunction.SUM))); long resultTimeStamp = query.getStartTs(); for (int i = 0; i < query.getLimit(); i++) { long tupleRead = 0; long eventProcessed = 0; if (tuplesReadItor.hasNext() && tuplesReadItor.peek().getTimestamp() == resultTimeStamp) { tupleRead = tuplesReadItor.next().getValue(); } if (eventsProcessedItor.hasNext() && eventsProcessedItor.peek().getTimestamp() == resultTimeStamp) { eventProcessed = eventsProcessedItor.next().getValue(); } if (eventProcessed != 0) { int busyness = (int) ((float) tupleRead / eventProcessed * 100); builder.addData(resultTimeStamp, busyness > 100 ? 100 : busyness); } else { // If the scan result doesn't have value for a timestamp, we add 0 to the returned result for that timestamp. builder.addData(resultTimeStamp, 0); } resultTimeStamp += query.getResolution(); } }
Assert.assertEquals(2, timeValues.size()); TimeValue timeValue = timeValues.get(0); Assert.assertEquals(tsInSec, timeValue.getTimestamp()); Assert.assertEquals(2, timeValue.getValue()); timeValue = timeValues.get(1); Assert.assertEquals(tsInSec + 2, timeValue.getTimestamp()); Assert.assertEquals(1, timeValue.getValue()); Assert.assertEquals(1, timeValues.size()); timeValue = timeValues.get(0); Assert.assertEquals(tsInSec, timeValue.getTimestamp()); Assert.assertEquals(3, timeValue.getValue());