Search in sources :

Example 11 with AmazonCloudWatch

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

the class EnableAlarmActions method main.

public static void main(String[] args) {
    final String USAGE = "To run this example, supply an alarm name\n" + "Ex: EnableAlarmActions <alarm-name>\n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String alarm = args[0];
    final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.defaultClient();
    EnableAlarmActionsRequest request = new EnableAlarmActionsRequest().withAlarmNames(alarm);
    EnableAlarmActionsResult response = cw.enableAlarmActions(request);
    System.out.printf("Successfully enabled actions on alarm %s", alarm);
}
Also used : EnableAlarmActionsRequest(com.amazonaws.services.cloudwatch.model.EnableAlarmActionsRequest) AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) EnableAlarmActionsResult(com.amazonaws.services.cloudwatch.model.EnableAlarmActionsResult)

Example 12 with AmazonCloudWatch

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

the class ListMetrics method main.

public static void main(String[] args) {
    final String USAGE = "To run this example, supply a metric name and metric namespace\n" + "Ex: ListMetrics <metric-name> <metric-namespace>\n";
    if (args.length != 2) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String name = args[0];
    String namespace = args[1];
    final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.defaultClient();
    boolean done = false;
    while (!done) {
        ListMetricsRequest request = new ListMetricsRequest().withMetricName(name).withNamespace(namespace);
        ListMetricsResult response = cw.listMetrics(request);
        for (Metric metric : response.getMetrics()) {
            System.out.printf("Retrieved metric %s", metric.getMetricName());
        }
        request.setNextToken(response.getNextToken());
        if (response.getNextToken() == null) {
            done = true;
        }
    }
}
Also used : AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) ListMetricsResult(com.amazonaws.services.cloudwatch.model.ListMetricsResult) ListMetricsRequest(com.amazonaws.services.cloudwatch.model.ListMetricsRequest) Metric(com.amazonaws.services.cloudwatch.model.Metric)

Aggregations

AmazonCloudWatch (com.amazonaws.services.cloudwatch.AmazonCloudWatch)12 MetricRegistry (com.codahale.metrics.MetricRegistry)4 MetricsCloudWatchReporter (com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter)4 Test (org.junit.Test)4 PutMetricDataRequest (com.amazonaws.services.cloudwatch.model.PutMetricDataRequest)3 Dimension (com.amazonaws.services.cloudwatch.model.Dimension)2 ClientConfiguration (com.amazonaws.ClientConfiguration)1 AWSCredentials (com.amazonaws.auth.AWSCredentials)1 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)1 AmazonCloudWatchClient (com.amazonaws.services.cloudwatch.AmazonCloudWatchClient)1 DeleteAlarmsRequest (com.amazonaws.services.cloudwatch.model.DeleteAlarmsRequest)1 DeleteAlarmsResult (com.amazonaws.services.cloudwatch.model.DeleteAlarmsResult)1 DescribeAlarmsRequest (com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest)1 DescribeAlarmsResult (com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult)1 DisableAlarmActionsRequest (com.amazonaws.services.cloudwatch.model.DisableAlarmActionsRequest)1 DisableAlarmActionsResult (com.amazonaws.services.cloudwatch.model.DisableAlarmActionsResult)1 EnableAlarmActionsRequest (com.amazonaws.services.cloudwatch.model.EnableAlarmActionsRequest)1 EnableAlarmActionsResult (com.amazonaws.services.cloudwatch.model.EnableAlarmActionsResult)1 ListMetricsRequest (com.amazonaws.services.cloudwatch.model.ListMetricsRequest)1 ListMetricsResult (com.amazonaws.services.cloudwatch.model.ListMetricsResult)1