コード例 #1
0
  public static void createCloudWatchPolicies() {

    System.out.println("Preparing Alarms..");

    watchClient = new AmazonCloudWatchClient(awsCredentials());

    // Scale out alarm
    PutMetricAlarmRequest scaleOutRequest = new PutMetricAlarmRequest();
    scaleOutRequest.setAlarmName("ScaleOutAlarm");
    scaleOutRequest.setMetricName("CPUUtilization");

    List<Dimension> dimensions = new ArrayList<Dimension>();
    Dimension dimension = new Dimension();
    dimension.setName("AutoScalingGroupName");
    dimension.setValue("ProjectTwoAutoScaleGroup");
    dimensions.add(dimension);
    scaleOutRequest.setDimensions(dimensions);

    scaleOutRequest.setNamespace("AWS/EC2");
    scaleOutRequest.setComparisonOperator(ComparisonOperator.GreaterThanThreshold);
    scaleOutRequest.setStatistic(Statistic.Average);
    scaleOutRequest.setUnit(StandardUnit.Percent);
    scaleOutRequest.setThreshold(70d);
    scaleOutRequest.setPeriod(60);
    scaleOutRequest.setEvaluationPeriods(1);

    // Linking alarm to policy
    List<String> actions = new ArrayList<String>();
    actions.add(scaleOut);
    scaleOutRequest.setAlarmActions(actions);

    // Scale in alarm
    PutMetricAlarmRequest scaleInRequest = new PutMetricAlarmRequest();
    scaleInRequest.setAlarmName("ScaleInAlarm");
    scaleInRequest.setMetricName("CPUUtilization");

    scaleInRequest.setDimensions(dimensions);

    scaleInRequest.setNamespace("AWS/EC2");
    scaleInRequest.setComparisonOperator(ComparisonOperator.LessThanThreshold);
    scaleInRequest.setStatistic(Statistic.Average);
    scaleInRequest.setUnit(StandardUnit.Percent);
    scaleInRequest.setThreshold(20d);
    scaleInRequest.setPeriod(60);
    scaleInRequest.setEvaluationPeriods(4);

    // Linking alarm to policy
    List<String> actionsTwo = new ArrayList<String>();
    actionsTwo.add(scaleIn);
    scaleInRequest.setAlarmActions(actionsTwo);

    watchClient.putMetricAlarm(scaleOutRequest);
    watchClient.putMetricAlarm(scaleInRequest);

    System.out.println("Alarms set successfully..");
  }
コード例 #2
0
 @Override
 public int compare(Dimension dim1, Dimension dim2) {
   int result = nullCompare(dim1, dim2);
   if (result == NON_NULLS) {
     result = nullSafeCompare(dim1.getName(), dim2.getName());
     if (result == 0) {
       return nullSafeCompare(dim1.getValue(), dim2.getValue());
     }
   }
   return result;
 }
コード例 #3
0
 /**
  * Passes into {@link #addDimension(String, String, boolean)}
  *
  * @return this for chaining
  * @throws MetricsNameSyntaxException on validation failure
  */
 public MetricNameBuilder addDimension(Dimension dimension, boolean permute)
     throws MetricsNameSyntaxException {
   return addDimension(dimension.getName(), dimension.getValue(), false);
 }