Esempio n. 1
0
 private OptionalDouble calculateQoS(Interval interval, MetricSet metricSet) {
   OptionalDouble qualityOfService = OptionalDouble.empty();
   long intervalSize = interval.end() - interval.start();
   double timestampsCalculated = intervalSize / metricSet.step();
   log.trace("intervalSize = {}; metricSet.step() = {}", intervalSize, metricSet.step());
   log.trace("metricSet should contain {} timestamps", timestampsCalculated);
   if (timestampsCalculated >= 1) {
     qualityOfService = OptionalDouble.of(metricSet.size() / timestampsCalculated);
   }
   return qualityOfService;
 }
Esempio n. 2
0
 public Optional<MetricSet> getValues(String metricName, Interval interval) {
   Instant now = Clock.systemUTC().instant();
   Optional<RetentionLevel> accessLevel =
       environment.retentions().findAccessLevelForMetric(metricName);
   Optional<MetricSet> setWithHighestQoS = Optional.empty();
   double highestAvailableQoS = 0;
   if (!accessLevel.isPresent()) {
     return Optional.empty();
   }
   EvictionStrategy evictionStrategy = findEvictionStrategyForAccessLevel(accessLevel.get()).get();
   evictionStrategy.accessing(metricName);
   while (accessLevel.isPresent() && caches.containsKey(accessLevel.get().name())) {
     log.trace("Found accessLevel " + accessLevel.get().name());
     Optional<CachingLevel> cachingLevel =
         environment.cachingConfiguration().findLevelForLevelName(accessLevel.get().name());
     if (cachingLevel.isPresent()) {
       long cachingLevelStart =
           now.minusSeconds(cachingLevel.get().cacheLineWidth() * accessLevel.get().frequency())
               .getEpochSecond();
       if (cachingLevelStart < interval.start()) {
         Optional<MetricSet> metricSet = doGetValues(metricName, interval, cachingLevel.get());
         if (!metricSet.isPresent()) {
           try {
             createNewCacheLines(metricName).get();
           } catch (InterruptedException | ExecutionException e) {
             log.warn("Exception while waiting for threads loading metrics", e);
           }
           metricSet = doGetValues(metricName, interval, cachingLevel.get());
         }
         if (metricSet.isPresent()) {
           log.trace("metricSet contains {} timestamps", metricSet.get().size());
           log.trace("accesslevel: {} | metricSet: {}", accessLevel.get().name(), metricSet.get());
           OptionalDouble serviceAvailable = calculateQoS(interval, metricSet.get());
           if (serviceAvailable.isPresent()
               && serviceAvailable.getAsDouble()
                   >= environment.cachingConfiguration().qualityOfService()) {
             log.trace("returning metricSet");
             return metricSet;
           } else if (serviceAvailable.isPresent()
               && serviceAvailable.getAsDouble() > highestAvailableQoS) {
             log.trace("new highestAvailable set");
             highestAvailableQoS = serviceAvailable.getAsDouble();
             setWithHighestQoS = metricSet;
           }
         } else {
           log.debug(
               "no metricSet for cacheLevel {} metric {} found!",
               accessLevel.get().name(),
               metricName);
         }
       }
     }
     accessLevel = environment.retentions().getNextLevel(accessLevel.get());
   }
   log.trace("service requested not available, returning highest available");
   return setWithHighestQoS;
 }