Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.nitorcreations.willow.autoscaler.metrics;
  
  
 import java.util.List;
 import java.util.Map;
 
 public class AutoScalingGroupStatus {
 
   private final AutoScalingGroupConfig group;
   private final Map<StringList<TimePoint<Double>>> metricsData;
 
     this. = group;
     this. = null;
     this. = new ConcurrentHashMap<>();
   }
 
   public synchronized void setDeploymentStatus(AutoScalingGroupDeploymentStatus deploymentStatus) {
     this. = deploymentStatus;
   }
 
   public synchronized void addMetricValue(String metricNameTimePoint<Doublevalue) {
     List<TimePoint<Double>> data = .get(metricName);
     if (data == null) {
       data = new ArrayList<>();
       .put(metricNamedata);
     }
     data.add(value);
     if (data.size() > 200) {
       data.remove(0);
     }
   }
 
   public synchronized List<TimePoint<Double>> getMetricValues(String metricName) {
     List<TimePoint<Double>> data = .get(metricName);
     if (data == null) {
       return Collections.emptyList();
     }
     return new ArrayList<>(data);
   }
 
     return ;
   }
 
     return ;
   }

  
Returns a list of auto scaling policies that have triggered, e.g. value is past threshold. Considers a policy triggered if there a few data points consistently past the threshold.

Returns:
 
     List<AutoScalingPolicytriggeredPolicies = new ArrayList<>();
     for (AutoScalingPolicy policy : .getScalingPolicies()) {
       List<TimePoint<Double>> metricValues = getMetricValues(policy.getMetricName());
       int triggerCount = 0;
       int triggerThreshold = 3;
       int inspectCount = 0;
       if (metricValues != null && metricValues.size() > 2) {
         List<TimePoint<Double>> reverse = new ArrayList<>(metricValues);
         Collections.reverse(reverse);
         for (TimePoint<Doublep : reverse) {
           ComparisonOperation op = ComparisonOperation.fromSymbol(policy.getMetricComparison());
           if (op.compare(p.getValue(), Double.valueOf(policy.getMetricThreshold()))) {
             triggerCount++;
           }
           inspectCount++;
           if (inspectCount >= 3) {
             break;
           }
         }
         if (triggerCount >= triggerThreshold) {
           triggeredPolicies.add(policy);
         }
       }
     }
     return triggeredPolicies;
   }
 
   public TimePoint<DoublegetLastValueFor(String metric) {
     List<TimePoint<Double>> data = getMetricValues(metric);
     if (!data.isEmpty()) {
       return data.get(data.size() - 1);
     } else {
       return null;
     }
  }
New to GrepCode? Check out our FAQ X