Example usage for com.amazonaws.services.cloudwatch.model StandardUnit Percent

List of usage examples for com.amazonaws.services.cloudwatch.model StandardUnit Percent

Introduction

In this page you can find the example usage for com.amazonaws.services.cloudwatch.model StandardUnit Percent.

Prototype

StandardUnit Percent

To view the source code for com.amazonaws.services.cloudwatch.model StandardUnit Percent.

Click Source Link

Usage

From source file:com.kurtraschke.nyctrtproxy.model.MatchMetrics.java

License:Apache License

private static MetricDatum metricPct(Date timestamp, String name, double value, Dimension dim) {
    return new MetricDatum().withMetricName(name).withTimestamp(timestamp).withValue(value * 100.0)
            .withUnit(StandardUnit.Percent).withDimensions(dim);
}

From source file:de.tuhrig.deployman.launch.Launcher.java

/**
 * Starts a auto scaling launch configuration. This method is a little but complicated, since the
 * process to start a auto scaling configuration involves some steps: - create a launch
 * configuration which defines the machines to start - create an auto scaling definition which
 * defines how many machines should be started if something happens. - create an auto scaling
 * policy to which we add a metric - create the metric which is checked by the auto scaling -
 * print the starting instances/*from w w w . j ava2  s .co  m*/
 */
private List<Instance> runAutoScalingLaunch(Formation formation) {
    this.console.write("Run auto scaling...");

    Machine machine = formation.getMachine();
    Scaling scaling = machine.getScaling();

    AmazonAutoScalingClient autoScaling = new AutoScaling().getClient();

    try {
        CreateLaunchConfigurationRequest request = createLaunchConfigurationRequest(formation);
        autoScaling.createLaunchConfiguration(request);
        this.console.write("Created launch configuration " + scaling.getName());
    } catch (AlreadyExistsException e) {
        this.console.write("Launch configuration " + scaling.getName() + " already exists"); //$NON-NLS-2$
    }

    //
    //
    //

    try {
        CreateAutoScalingGroupRequest request = createAutoScalingRequest(scaling);
        autoScaling.createAutoScalingGroup(request);
        this.console.write("Created auto scaling group " + scaling.getGroup());
    } catch (AlreadyExistsException e) {
        this.console.write("Auto scaling group " + scaling.getGroup() + " already exists"); //$NON-NLS-2$
    }

    //
    //
    //

    PutScalingPolicyRequest request = new PutScalingPolicyRequest().withAutoScalingGroupName(scaling.getGroup())
            .withPolicyName(scaling.getPolicy()).withScalingAdjustment(1)
            .withAdjustmentType("ChangeInCapacity");

    PutScalingPolicyResult result = autoScaling.putScalingPolicy(request);

    this.console.write("Put scaling policy " + scaling.getPolicy());

    //
    //
    //

    // Scale Up

    Dimension dimension = new Dimension().withName("AutoScalingGroupName").withValue(scaling.getGroup());

    List<String> actions = new ArrayList<>();
    actions.add(result.getPolicyARN());

    PutMetricAlarmRequest upRequest = new PutMetricAlarmRequest().withAlarmName(scaling.getAlarm())
            .withMetricName("CPUUtilization").withDimensions(dimension).withNamespace("AWS/EC2")
            .withComparisonOperator(ComparisonOperator.GreaterThanThreshold).withStatistic(Statistic.Average)
            .withUnit(StandardUnit.Percent).withThreshold(60d).withPeriod(300).withEvaluationPeriods(2)
            .withAlarmActions(actions);

    AmazonCloudWatchClient cloudWatch = new CloudWatch().getClient();
    cloudWatch.putMetricAlarm(upRequest);

    this.console.write("Put alarm " + scaling.getAlarm());
    this.console.newLine();

    List<Instance> instances = new ArrayList<>();

    for (AutoScalingInstanceDetails instance : autoScaling.describeAutoScalingInstances()
            .getAutoScalingInstances()) {

        if (instance.getAutoScalingGroupName().equals(scaling.getGroup())) {

            instances.add(new Ec2().getEC2InstanceById(instance.getInstanceId()));
        }
    }

    return instances;
}

From source file:org.onebusaway.aws.monitoring.impl.alarms.RealtimeAlarmsImpl.java

License:Apache License

@Override
public void createRealtimeLocationsTotalPctAlarm() {
    PutMetricAlarmRequest putMetricAlarmRequest = getMetricAlarmRequest(MetricName.RealtimeLocationsTotalPct);
    putMetricAlarmRequest.setAlarmActions(getNonCriticalAction());
    putMetricAlarmRequest.setInsufficientDataActions(getNonCriticalAction());
    putMetricAlarmRequest.setUnit(StandardUnit.Percent);
    putMetricAlarmRequest/*from w  ww.  j a  va 2  s . c  o m*/
            .setThreshold(_configService.getConfigurationValueAsDouble("alarm.rtLocationsTotalPct", 10d));
    _cloudWatchService.publishAlarm(putMetricAlarmRequest);

}

From source file:org.onebusaway.aws.monitoring.impl.alarms.RealtimeAlarmsImpl.java

License:Apache License

@Override
public void createRealtimeInvalidLatLonPctAlarm() {
    PutMetricAlarmRequest putMetricAlarmRequest = getMetricAlarmRequest(MetricName.RealtimeInvalidLatLonPct);
    putMetricAlarmRequest.setAlarmActions(getNonCriticalAction());
    putMetricAlarmRequest.setInsufficientDataActions(getNonCriticalAction());
    putMetricAlarmRequest.setUnit(StandardUnit.Percent);
    putMetricAlarmRequest//from  w  w w.j av a2  s  . c  o  m
            .setThreshold(_configService.getConfigurationValueAsDouble("alarm.rtTnvalidLatLonPct", 10d));
    _cloudWatchService.publishAlarm(putMetricAlarmRequest);

}

From source file:org.onebusaway.aws.monitoring.impl.alarms.RealtimeAlarmsImpl.java

License:Apache License

@Override
public void createRealtimeStopsMatchedPctAlarm() {
    PutMetricAlarmRequest putMetricAlarmRequest = getMetricAlarmRequest(MetricName.RealtimeStopsMatchedPct);
    putMetricAlarmRequest.setAlarmActions(getNonCriticalAction());
    putMetricAlarmRequest.setInsufficientDataActions(getNonCriticalAction());
    putMetricAlarmRequest.setUnit(StandardUnit.Percent);
    putMetricAlarmRequest/*from  ww w.java2s  . c o m*/
            .setThreshold(_configService.getConfigurationValueAsDouble("alarm.rtStopsMatchedPct", 10d));
    _cloudWatchService.publishAlarm(putMetricAlarmRequest);

}

From source file:org.onebusaway.aws.monitoring.impl.alarms.RealtimeAlarmsImpl.java

License:Apache License

@Override
public void createRealtimeStopsUnmatchedPctAlarm() {
    PutMetricAlarmRequest putMetricAlarmRequest = getMetricAlarmRequest(MetricName.RealtimeStopsUnmatchedPct);
    putMetricAlarmRequest.setAlarmActions(getNonCriticalAction());
    putMetricAlarmRequest.setInsufficientDataActions(getNonCriticalAction());
    putMetricAlarmRequest.setUnit(StandardUnit.Percent);
    putMetricAlarmRequest.setComparisonOperator(ComparisonOperator.LessThanOrEqualToThreshold);
    putMetricAlarmRequest/*from   w w  w . j  a  v  a2s.c om*/
            .setThreshold(_configService.getConfigurationValueAsDouble("alarm.rtStopsUnmatchedPct", 0d));
    _cloudWatchService.publishAlarm(putMetricAlarmRequest);

}

From source file:org.onebusaway.aws.monitoring.impl.alarms.RealtimeAlarmsImpl.java

License:Apache License

@Override
public void createRealtimeTripTotalPctAlarm() {
    PutMetricAlarmRequest putMetricAlarmRequest = getMetricAlarmRequest(MetricName.RealtimeTripTotalPct);
    putMetricAlarmRequest.setAlarmActions(getCriticalAction());
    putMetricAlarmRequest.setInsufficientDataActions(getNonCriticalAction());
    putMetricAlarmRequest.setUnit(StandardUnit.Percent);
    putMetricAlarmRequest/* w  w w .  jav a 2 s.c om*/
            .setThreshold(_configService.getConfigurationValueAsDouble("alarm.rtTripTotalPct", 10d));
    _cloudWatchService.publishAlarm(putMetricAlarmRequest);

}

From source file:org.onebusaway.aws.monitoring.impl.alarms.RealtimeAlarmsImpl.java

License:Apache License

@Override
public void createRealtimeBusesInServiceAlarm() {
    PutMetricAlarmRequest putMetricAlarmRequest = getMetricAlarmRequest(MetricName.RealtimeBusesInServicePct);
    putMetricAlarmRequest.setAlarmActions(getCriticalAction());
    putMetricAlarmRequest.setInsufficientDataActions(getNonCriticalAction());
    putMetricAlarmRequest.setUnit(StandardUnit.Percent);
    putMetricAlarmRequest.setComparisonOperator(ComparisonOperator.LessThanOrEqualToThreshold);
    putMetricAlarmRequest// www.j  ava2  s  . com
            .setThreshold(_configService.getConfigurationValueAsDouble("alarm.rtBusesInServicePct", 0d));
    _cloudWatchService.publishAlarm(putMetricAlarmRequest);
}