Search in sources :

Example 6 with AmazonCloudWatch

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

the class PutMetricData method main.

public static void main(String[] args) {
    final String USAGE = "To run this example, supply a data point:\n" + "Ex: PutMetricData <data_point>\n";
    if (args.length != 1) {
        System.out.println(USAGE);
        System.exit(1);
    }
    Double data_point = Double.parseDouble(args[0]);
    final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.defaultClient();
    Dimension dimension = new Dimension().withName("UNIQUE_PAGES").withValue("URLS");
    MetricDatum datum = new MetricDatum().withMetricName("PAGES_VISITED").withUnit(StandardUnit.None).withValue(data_point).withDimensions(dimension);
    PutMetricDataRequest request = new PutMetricDataRequest().withNamespace("SITE/TRAFFIC").withMetricData(datum);
    PutMetricDataResult response = cw.putMetricData(request);
    System.out.printf("Successfully put data point %f", data_point);
}
Also used : AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) PutMetricDataResult(com.amazonaws.services.cloudwatch.model.PutMetricDataResult) MetricDatum(com.amazonaws.services.cloudwatch.model.MetricDatum) Dimension(com.amazonaws.services.cloudwatch.model.Dimension)

Example 7 with AmazonCloudWatch

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

the class DisableAlarmActions method main.

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

Example 8 with AmazonCloudWatch

use of com.amazonaws.services.cloudwatch.AmazonCloudWatch in project chassis by Kixeye.

the class CloudWatchReporterTest method testPublishFilteredMetrics_metricStatFiltered.

/**
     * A metric is not fully filtered, but some stats within the metric are
     */
@Test
public void testPublishFilteredMetrics_metricStatFiltered() throws InterruptedException {
    MetricRegistry metricRegistry = new MetricRegistry();
    metricRegistry.meter("UnitTestMeter1").mark();
    metricRegistry.meter("UnitTestMeter2").mark();
    final AmazonCloudWatch amazonCloudWatch = Mockito.mock(AmazonCloudWatch.class);
    reporter = new MetricsCloudWatchReporter(APP_NAME, APP_VERSION, APP_ENVIRONMENT, "utm1=UnitTestMeter1,utm2=UnitTestMeter2:1m:5m:15m", 2, TimeUnit.SECONDS, metricRegistry, createCloudWatchFactory(amazonCloudWatch));
    reporter.start();
    //give the reporter a chance to publish
    Thread.sleep(3000);
    PutMetricDataRequestMatcher matcher = new PutMetricDataRequestMatcher(new MetricDatumValidator("utm1.1m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utm1.5m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utm1.15m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utm1.mean", APP_ENVIRONMENT, null), new MetricDatumValidator("utm2.1m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utm2.5m", APP_ENVIRONMENT, 0d), new MetricDatumValidator("utm2.15m", APP_ENVIRONMENT, 0d));
    Mockito.verify(amazonCloudWatch, Mockito.times(1)).putMetricData(Mockito.argThat(matcher));
}
Also used : MetricsCloudWatchReporter(com.kixeye.chassis.support.metrics.aws.MetricsCloudWatchReporter) AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) MetricRegistry(com.codahale.metrics.MetricRegistry) Test(org.junit.Test)

Example 9 with AmazonCloudWatch

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

the class DeleteAlarm method main.

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

Example 10 with AmazonCloudWatch

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

the class DescribeAlarms method main.

public static void main(String[] args) {
    final AmazonCloudWatch cw = AmazonCloudWatchClientBuilder.defaultClient();
    boolean done = false;
    while (!done) {
        DescribeAlarmsRequest request = new DescribeAlarmsRequest();
        DescribeAlarmsResult response = cw.describeAlarms(request);
        for (MetricAlarm alarm : response.getMetricAlarms()) {
            System.out.printf("Retrieved alarm %s", alarm.getAlarmName());
        }
        request.setNextToken(response.getNextToken());
        if (response.getNextToken() == null) {
            done = true;
        }
    }
}
Also used : MetricAlarm(com.amazonaws.services.cloudwatch.model.MetricAlarm) DescribeAlarmsResult(com.amazonaws.services.cloudwatch.model.DescribeAlarmsResult) AmazonCloudWatch(com.amazonaws.services.cloudwatch.AmazonCloudWatch) DescribeAlarmsRequest(com.amazonaws.services.cloudwatch.model.DescribeAlarmsRequest)

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