Example #1
0
  public AggregateNumericMetric getSummaryAggregate(
      List<Integer> scheduleIds, long beginTime, long endTime) {
    Stopwatch stopwatch = new Stopwatch().start();
    try {
      DateTime begin = new DateTime(beginTime);

      if (dateTimeService.isInRawDataRange(new DateTime(beginTime))) {
        Iterable<RawNumericMetric> metrics = dao.findRawMetrics(scheduleIds, beginTime, endTime);
        return calculateAggregatedRaw(metrics, beginTime);
      }
      Bucket bucket = getBucket(begin);
      List<AggregateNumericMetric> metrics = loadMetrics(scheduleIds, beginTime, endTime, bucket);

      return calculateAggregate(metrics, beginTime, bucket);
    } finally {
      stopwatch.stop();
      if (log.isDebugEnabled()) {
        log.debug(
            "Finished calculating group summary aggregate for [scheduleIds: "
                + scheduleIds
                + ", beginTime: "
                + beginTime
                + ", endTime: "
                + endTime
                + "] in "
                + stopwatch.elapsed(TimeUnit.MILLISECONDS)
                + " ms");
      }
    }
  }
Example #2
0
  public List<MeasurementDataNumericHighLowComposite> findDataForGroup(
      List<Integer> scheduleIds, long beginTime, long endTime, int numberOfBuckets) {
    if (log.isDebugEnabled()) {
      log.debug(
          "Querying for metric data using parameters [scheduleIds: "
              + scheduleIds
              + ", beingTime: "
              + beginTime
              + ", endTime: "
              + endTime
              + ", numberOfBuckets: "
              + numberOfBuckets
              + "]");
    }

    DateTime begin = new DateTime(beginTime);
    if (dateTimeService.isInRawDataRange(begin)) {
      Iterable<RawNumericMetric> metrics = dao.findRawMetrics(scheduleIds, beginTime, endTime);
      return createRawComposites(metrics, beginTime, endTime, numberOfBuckets);
    }
    Bucket bucket = getBucket(begin);
    List<AggregateNumericMetric> metrics = loadMetrics(scheduleIds, beginTime, endTime, bucket);

    return createComposites(metrics, beginTime, endTime, numberOfBuckets);
  }
Example #3
0
  public ListenableFuture<AggregateNumericMetric> getSummaryAggregateAsync(
      int scheduleId, long beginTime, long endTime) {
    long start = System.currentTimeMillis();
    try {
      if (log.isDebugEnabled()) {
        log.debug(
            "Calculating resource summary aggregate (async) for [scheduleId: "
                + scheduleId
                + ", beginTime: "
                + beginTime
                + ", endTime: "
                + endTime
                + "]");
      }
      DateTime begin = new DateTime(beginTime);
      StorageResultSetFuture queryFuture;

      if (dateTimeService.isInRawDataRange(begin)) {
        queryFuture = dao.findRawMetricsAsync(scheduleId, beginTime, endTime);
        return Futures.transform(queryFuture, new ComputeRawAggregate(beginTime));
      }
      Bucket bucket = getBucket(begin);
      queryFuture = dao.findAggregateMetricsAsync(scheduleId, bucket, beginTime, endTime);

      return Futures.transform(queryFuture, new ComputeAggregate(beginTime, bucket));
    } finally {
      long end = System.currentTimeMillis();
      if (log.isDebugEnabled()) {
        log.debug(
            "Finished calculating resource summary aggregate (async) in " + (end - start) + " ms");
      }
    }
  }
Example #4
0
  public Iterable<MeasurementDataNumericHighLowComposite> findDataForResource(
      int scheduleId, long beginTime, long endTime, int numberOfBuckets) {
    Stopwatch stopwatch = new Stopwatch().start();
    try {
      DateTime begin = new DateTime(beginTime);

      if (dateTimeService.isInRawDataRange(begin)) {
        Iterable<RawNumericMetric> metrics = dao.findRawMetrics(scheduleId, beginTime, endTime);
        return createRawComposites(metrics, beginTime, endTime, numberOfBuckets);
      }

      List<AggregateNumericMetric> metrics = null;
      if (dateTimeService.isIn1HourDataRange(begin)) {
        metrics = dao.findAggregateMetrics(scheduleId, Bucket.ONE_HOUR, beginTime, endTime);
        return createComposites(metrics, beginTime, endTime, numberOfBuckets);
      } else if (dateTimeService.isIn6HourDataRange(begin)) {
        metrics = dao.findAggregateMetrics(scheduleId, Bucket.SIX_HOUR, beginTime, endTime);
        return createComposites(metrics, beginTime, endTime, numberOfBuckets);
      } else if (dateTimeService.isIn24HourDataRange(begin)) {
        metrics = dao.findAggregateMetrics(scheduleId, Bucket.TWENTY_FOUR_HOUR, beginTime, endTime);
        return createComposites(metrics, beginTime, endTime, numberOfBuckets);
      } else {
        throw new IllegalArgumentException(
            "beginTime[" + beginTime + "] is outside the accepted range.");
      }
    } finally {
      stopwatch.stop();
      if (log.isDebugEnabled()) {
        log.debug(
            "Finished calculating resource summary aggregate in "
                + stopwatch.elapsed(TimeUnit.MILLISECONDS)
                + " ms");
      }
    }
  }