Search in sources :

Example 1 with PutMetricAlarmResult

use of com.amazonaws.services.cloudwatch.model.PutMetricAlarmResult in project aws-doc-sdk-examples by awsdocs.

the class PutMetricAlarm method main.

public static void main(String[] args) {
    final String USAGE = "To run this example, supply an alarm name and instance id\n" + "Ex: DeleteAlarm <alarm-name> <instance-id>\n";
    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String alarmName = args[0];
    String instanceId = args[1];
    final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.defaultClient();
    Dimension dimension = new Dimension().withName("InstanceId").withValue(instanceId);
    PutMetricAlarmRequest request = new PutMetricAlarmRequest().withAlarmName(alarmName).withComparisonOperator(ComparisonOperator.GreaterThanThreshold).withEvaluationPeriods(1).withMetricName("CPUUtilization").withNamespace("AWS/EC2").withPeriod(60).withStatistic(Statistic.Average).withThreshold(70.0).withActionsEnabled(false).withAlarmDescription("Alarm when server CPU utilization exceeds 70%").withUnit(StandardUnit.Seconds).withDimensions(dimension);
    PutMetricAlarmResult response = cw.putMetricAlarm(request);
    System.out.printf("Successfully created alarm with name %s", alarmName);
}
Also used : PutMetricAlarmResult(com.amazonaws.services.cloudwatch.model.PutMetricAlarmResult) PutMetricAlarmRequest(com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest) AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) Dimension(com.amazonaws.services.cloudwatch.model.Dimension)

Aggregations

AmazonCloudWatch (com.amazonaws.services.cloudwatch.AmazonCloudWatch)1 Dimension (com.amazonaws.services.cloudwatch.model.Dimension)1 PutMetricAlarmRequest (com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest)1 PutMetricAlarmResult (com.amazonaws.services.cloudwatch.model.PutMetricAlarmResult)1