com.amazonaws.services.cloudwatch.AmazonCloudWatch Java Examples

The following examples show how to use com.amazonaws.services.cloudwatch.AmazonCloudWatch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EnableAlarmActions.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
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);
    }
 
Example #2
Source File: DescribeAlarms.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {

        final AmazonCloudWatch cw =
            AmazonCloudWatchClientBuilder.defaultClient();

        boolean done = false;
        DescribeAlarmsRequest request = new DescribeAlarmsRequest();

        while(!done) {

            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;
            }
        }
    }
 
Example #3
Source File: DeleteAlarm.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
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);
    }
 
Example #4
Source File: DisableAlarmActions.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
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);
    }
 
Example #5
Source File: CloudWatchRecorder.java    From swage with Apache License 2.0 6 votes vote down vote up
/**
 * Create a new recorder instance.
 * This recorder will periodically send aggregated metric events to CloudWatch
 * via the provided client. Requests will be queued and sent using a
 * single-threaded ScheduledExecutorService every publishFrequency (in seconds).
 * The initial submission to CloudWatch will be delayed by a random amount
 * on top of the publish frequency, bounded by maxJitter.
 *
 * The {@link #shutdown} method must be called when the application is done
 * with the recorder in order to flush and stop the reporting thread.
 *
 * @param client Client to use for connecting to CloudWatch
 * @param namespace CloudWatch namespace to publish under
 * @param maxJitter Maximum delay before counting publish frequency for
 *                  initial request, in seconds.
 *                  A value of 0 will provide no jitter.
 * @param publishFrequency Batch up and publish at this interval, in seconds.
 *                         Suggested value of 60, for one minute aggregation.
 * @param dimensionMapper Configuration specifying which dimensions to sent
 *                        to CloudWatch for each metric event.
 * @param scheduledExecutorService Executor to schedule metric publishing at a fixed rate.
 */
public CloudWatchRecorder(
        final AmazonCloudWatch client,
        final String namespace,
        final int maxJitter,
        final int publishFrequency,
        final DimensionMapper dimensionMapper,
        final ScheduledExecutorService scheduledExecutorService)
{
    if (client == null) {
        throw new IllegalArgumentException("AmazonCloudWatch must be provided");
    }
    if (namespace == null || namespace.isEmpty()) {
        throw new IllegalArgumentException("namespace must be provided");
    }
    if (dimensionMapper == null) {
        throw new IllegalArgumentException("DimensionMapper must be provided");
    }

    this.metricsClient = client;
    this.namespace = namespace;
    this.publishExecutor = scheduledExecutorService;
    this.aggregator = new MetricDataAggregator(dimensionMapper);

    start(maxJitter, publishFrequency);
}
 
Example #6
Source File: KinesisMessageChannelBinder.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 6 votes vote down vote up
public KinesisMessageChannelBinder(KinesisBinderConfigurationProperties configurationProperties,
		KinesisStreamProvisioner provisioningProvider, AmazonKinesisAsync amazonKinesis,
		AWSCredentialsProvider awsCredentialsProvider,
		@Nullable AmazonDynamoDB dynamoDBClient,
		@Nullable AmazonDynamoDBStreams dynamoDBStreams,
		@Nullable AmazonCloudWatch cloudWatchClient) {

	super(headersToMap(configurationProperties), provisioningProvider);
	Assert.notNull(amazonKinesis, "'amazonKinesis' must not be null");
	Assert.notNull(awsCredentialsProvider, "'awsCredentialsProvider' must not be null");
	this.configurationProperties = configurationProperties;
	this.amazonKinesis = amazonKinesis;
	this.cloudWatchClient = cloudWatchClient;
	this.dynamoDBClient = dynamoDBClient;
	this.awsCredentialsProvider = awsCredentialsProvider;

	if (dynamoDBStreams != null) {
		this.dynamoDBStreamsAdapter = new AmazonDynamoDBStreamsAdapterClient(dynamoDBStreams);
	}
	else {
		this.dynamoDBStreamsAdapter = null;
	}
}
 
Example #7
Source File: CloudWatch.java    From javamelody with Apache License 2.0 6 votes vote down vote up
CloudWatch(AmazonCloudWatch cloudWatch, String cloudWatchNamespace, String prefix,
		String application, String hostName) {
	super();
	assert cloudWatch != null;
	assert cloudWatchNamespace != null && !cloudWatchNamespace.startsWith("AWS/")
			&& cloudWatchNamespace.length() > 0 && cloudWatchNamespace.length() <= 255;
	assert prefix != null;
	assert application.length() >= 1 && application.length() <= 255;
	assert hostName.length() >= 1 && hostName.length() <= 255;

	this.awsCloudWatch = cloudWatch;
	this.cloudWatchNamespace = cloudWatchNamespace;
	this.prefix = prefix;
	// A dimension is like a tag which can be used to filter metrics in the CloudWatch UI.
	// Name and value of dimensions have min length 1 and max length 255.
	dimensions.add(new Dimension().withName("application").withValue(application));
	dimensions.add(new Dimension().withName("hostname").withValue(hostName));
	// note: to add other dimensions (max 10), we could call
	// new URL("http://instance-data/latest/meta-data/instance-id").openStream(),
	// or /ami-id, /placement/availability-zone, /instance-type, /local-hostname, /local-ipv4, /public-hostname, /public-ipv4
	// see http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
	// except that it would not work from the collector server
}
 
Example #8
Source File: TalendKinesisProvider.java    From components with Apache License 2.0 5 votes vote down vote up
@Override
public AmazonCloudWatch getCloudWatchClient() {
    AmazonCloudWatchClientBuilder clientBuilder =
            AmazonCloudWatchClientBuilder.standard().withCredentials(getCredentialsProvier());
    if (specifyEndpoint) {
        clientBuilder
                .withEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(endpoint, region.getName()));
    } else {
        clientBuilder.setRegion(region.getName());
    }
    return clientBuilder.build();
}
 
Example #9
Source File: BasicKinesisProvider.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public AmazonCloudWatch getCloudWatchClient() {
  AmazonCloudWatchClientBuilder clientBuilder =
      AmazonCloudWatchClientBuilder.standard().withCredentials(getCredentialsProvider());
  if (serviceEndpoint == null) {
    clientBuilder.withRegion(region);
  } else {
    clientBuilder.withEndpointConfiguration(
        new AwsClientBuilder.EndpointConfiguration(serviceEndpoint, region.getName()));
  }
  return clientBuilder.build();
}
 
Example #10
Source File: BasicSnsProvider.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public AmazonCloudWatch getCloudWatchClient() {
  AmazonCloudWatchClientBuilder clientBuilder =
      AmazonCloudWatchClientBuilder.standard().withCredentials(getCredentialsProvider());
  if (serviceEndpoint == null) {
    clientBuilder.withRegion(region);
  } else {
    clientBuilder.withEndpointConfiguration(
        new AwsClientBuilder.EndpointConfiguration(serviceEndpoint, region.getName()));
  }
  return clientBuilder.build();
}
 
Example #11
Source File: BasicDynamoDBProvider.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public AmazonCloudWatch getCloudWatchClient() {
  AmazonCloudWatchClientBuilder clientBuilder =
      AmazonCloudWatchClientBuilder.standard().withCredentials(getCredentialsProvider());
  if (serviceEndpoint == null) {
    clientBuilder.withRegion(region);
  } else {
    clientBuilder.withEndpointConfiguration(
        new AwsClientBuilder.EndpointConfiguration(serviceEndpoint, region.getName()));
  }
  return clientBuilder.build();
}
 
Example #12
Source File: DynamoDBSourceConfig.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public AmazonCloudWatch buildCloudwatchClient(AwsCredentialProviderPlugin credPlugin) {
    AmazonCloudWatchClientBuilder builder = AmazonCloudWatchClientBuilder.standard();

    if (!this.getAwsEndpoint().isEmpty()) {
        builder.setEndpointConfiguration(new AwsClientBuilder.EndpointConfiguration(this.getCloudwatchEndpoint(), this.getAwsRegion()));
    }
    if (!this.getAwsRegion().isEmpty()) {
        builder.setRegion(this.getAwsRegion());
    }
    builder.setCredentials(credPlugin.getCredentialProvider());
    return builder.build();
}
 
Example #13
Source File: MetricsRecordHandler.java    From aws-athena-query-federation with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
protected MetricsRecordHandler(AmazonS3 amazonS3, AWSSecretsManager secretsManager, AmazonAthena athena, AmazonCloudWatch metrics)
{
    super(amazonS3, secretsManager, athena, SOURCE_TYPE);
    this.amazonS3 = amazonS3;
    this.metrics = metrics;
}
 
Example #14
Source File: CloudWatchCollector.java    From cloudwatch_exporter with Apache License 2.0 5 votes vote down vote up
private void loadConfig(ArrayList<MetricRule> rules, AmazonCloudWatch cloudWatchClient, AWSResourceGroupsTaggingAPI taggingClient) {
    synchronized (activeConfig) {
        activeConfig.cloudWatchClient = cloudWatchClient;
        activeConfig.taggingClient = taggingClient;
        activeConfig.rules = rules;
    }
}
 
Example #15
Source File: CloudWatchCollector.java    From cloudwatch_exporter with Apache License 2.0 5 votes vote down vote up
private List<List<Dimension>> getDimensions(MetricRule rule, List<String> tagBasedResourceIds, AmazonCloudWatch cloudWatchClient) {
    if (
            rule.awsDimensions != null &&
            rule.awsDimensionSelect != null &&
            rule.awsDimensions.size() > 0 &&
            rule.awsDimensions.size() == rule.awsDimensionSelect.size() &&
            rule.awsDimensionSelect.keySet().containsAll(rule.awsDimensions) &&
            rule.awsTagSelect == null
    ) {
        // The full list of dimensions is known so no need to request it from cloudwatch.
        return permuteDimensions(rule.awsDimensions, rule.awsDimensionSelect);
    } else {
        return listDimensions(rule, tagBasedResourceIds, cloudWatchClient);
    }
}
 
Example #16
Source File: CloudWatchCollector.java    From cloudwatch_exporter with Apache License 2.0 5 votes vote down vote up
private List<List<Dimension>> listDimensions(MetricRule rule, List<String> tagBasedResourceIds, AmazonCloudWatch cloudWatchClient) {
  List<List<Dimension>> dimensions = new ArrayList<List<Dimension>>();
  if (rule.awsDimensions == null) {
    dimensions.add(new ArrayList<Dimension>());
    return dimensions;
  }

  ListMetricsRequest request = new ListMetricsRequest();
  request.setNamespace(rule.awsNamespace);
  request.setMetricName(rule.awsMetricName);
  List<DimensionFilter> dimensionFilters = new ArrayList<DimensionFilter>();
  for (String dimension: rule.awsDimensions) {
    dimensionFilters.add(new DimensionFilter().withName(dimension));
  }
  request.setDimensions(dimensionFilters);

  String nextToken = null;
  do {
    request.setNextToken(nextToken);
    ListMetricsResult result = cloudWatchClient.listMetrics(request);
    cloudwatchRequests.labels("listMetrics", rule.awsNamespace).inc();
    for (Metric metric: result.getMetrics()) {
      if (metric.getDimensions().size() != dimensionFilters.size()) {
        // AWS returns all the metrics with dimensions beyond the ones we ask for,
        // so filter them out.
        continue;
      }
      if (useMetric(rule, tagBasedResourceIds, metric)) {
        dimensions.add(metric.getDimensions());
      }
    }
    nextToken = result.getNextToken();
  } while (nextToken != null);

  return dimensions;
}
 
Example #17
Source File: CloudWatchReporterTest.java    From chassis with Apache License 2.0 5 votes vote down vote up
/**
 * 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));
}
 
Example #18
Source File: CloudWatchReporterTest.java    From chassis with Apache License 2.0 5 votes vote down vote up
/**
 * Ensure all metrics are published event when the max number of cloudwatch metrics (per request) is exceeded.
 */
@Test
public void testPublishInMultipleCloudWatchRequests() throws InterruptedException {
    MetricRegistry metricRegistry = new MetricRegistry();

    StringBuilder filter = new StringBuilder();
    for (int i = 0; i < MetricsCloudWatchReporter.MAX_CLOUDWATCH_DATUM_PER_REQUEST + 1; i++) {
        String metric = "UnitTestCounter" + i;
        metricRegistry.counter(metric).inc();
        if (i > 0) {
            filter.append(",");
        }
        filter.append(metric).append("=").append(metric);
    }

    final AmazonCloudWatch amazonCloudWatch = Mockito.mock(AmazonCloudWatch.class);

    reporter =
            new MetricsCloudWatchReporter(
                    APP_NAME,
                    APP_VERSION,
                    APP_ENVIRONMENT,
                    filter.toString(),
                    2,
                    TimeUnit.SECONDS,
                    metricRegistry,
                    createCloudWatchFactory(amazonCloudWatch));

    reporter.start();

    Mockito.verify(amazonCloudWatch, Mockito.never()).putMetricData(Mockito.any(PutMetricDataRequest.class));

    Thread.sleep(3000);

    Mockito.verify(amazonCloudWatch, Mockito.times(2)).putMetricData(Mockito.any(PutMetricDataRequest.class));
}
 
Example #19
Source File: CloudWatchReporterTest.java    From chassis with Apache License 2.0 5 votes vote down vote up
private CloudWatchFactory createCloudWatchFactory(final AmazonCloudWatch amazonCloudWatch) {
    return new CloudWatchFactory() {
        @Override
        public AmazonCloudWatch getCloudWatchClient() {
            return amazonCloudWatch;
        }
    };
}
 
Example #20
Source File: CloudWatchCollector.java    From cloudwatch_exporter with Apache License 2.0 5 votes vote down vote up
private void loadConfig(ArrayList<MetricRule> rules, AmazonCloudWatch cloudWatchClient, AWSResourceGroupsTaggingAPI taggingClient) {
    synchronized (activeConfig) {
        activeConfig.cloudWatchClient = cloudWatchClient;
        activeConfig.taggingClient = taggingClient;
        activeConfig.rules = rules;
    }
}
 
Example #21
Source File: CloudWatchCollector.java    From cloudwatch_exporter with Apache License 2.0 5 votes vote down vote up
private List<List<Dimension>> getDimensions(MetricRule rule, List<String> tagBasedResourceIds, AmazonCloudWatch cloudWatchClient) {
    if (
            rule.awsDimensions != null &&
            rule.awsDimensionSelect != null &&
            rule.awsDimensions.size() > 0 &&
            rule.awsDimensions.size() == rule.awsDimensionSelect.size() &&
            rule.awsDimensionSelect.keySet().containsAll(rule.awsDimensions) &&
            rule.awsTagSelect == null
    ) {
        // The full list of dimensions is known so no need to request it from cloudwatch.
        return permuteDimensions(rule.awsDimensions, rule.awsDimensionSelect);
    } else {
        return listDimensions(rule, tagBasedResourceIds, cloudWatchClient);
    }
}
 
Example #22
Source File: CloudWatchCollector.java    From cloudwatch_exporter with Apache License 2.0 5 votes vote down vote up
private List<List<Dimension>> listDimensions(MetricRule rule, List<String> tagBasedResourceIds, AmazonCloudWatch cloudWatchClient) {
  List<List<Dimension>> dimensions = new ArrayList<List<Dimension>>();
  if (rule.awsDimensions == null) {
    dimensions.add(new ArrayList<Dimension>());
    return dimensions;
  }

  ListMetricsRequest request = new ListMetricsRequest();
  request.setNamespace(rule.awsNamespace);
  request.setMetricName(rule.awsMetricName);
  List<DimensionFilter> dimensionFilters = new ArrayList<DimensionFilter>();
  for (String dimension: rule.awsDimensions) {
    dimensionFilters.add(new DimensionFilter().withName(dimension));
  }
  request.setDimensions(dimensionFilters);

  String nextToken = null;
  do {
    request.setNextToken(nextToken);
    ListMetricsResult result = cloudWatchClient.listMetrics(request);
    cloudwatchRequests.labels("listMetrics", rule.awsNamespace).inc();
    for (Metric metric: result.getMetrics()) {
      if (metric.getDimensions().size() != dimensionFilters.size()) {
        // AWS returns all the metrics with dimensions beyond the ones we ask for,
        // so filter them out.
        continue;
      }
      if (useMetric(rule, tagBasedResourceIds, metric)) {
        dimensions.add(metric.getDimensions());
      }
    }
    nextToken = result.getNextToken();
  } while (nextToken != null);

  return dimensions;
}
 
Example #23
Source File: PutMetricData.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
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);
    }
 
Example #24
Source File: MetricsMetadataHandler.java    From aws-athena-query-federation with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
protected MetricsMetadataHandler(AmazonCloudWatch metrics,
        EncryptionKeyFactory keyFactory,
        AWSSecretsManager secretsManager,
        AmazonAthena athena,
        String spillBucket,
        String spillPrefix)
{
    super(keyFactory, secretsManager, athena, SOURCE_TYPE, spillBucket, spillPrefix);
    this.metrics = metrics;
}
 
Example #25
Source File: CloudWatchRecorderTest.java    From swage with Apache License 2.0 5 votes vote down vote up
@Test
public void record_and_shutdown() throws Exception {
    final DimensionMapper mapper = new DimensionMapper.Builder()
            .addGlobalDimension(ContextData.ID)
            .build();

    final String namespace = "spacename";

    final String id = UUID.randomUUID().toString();
    final TypedMap data = ContextData.withId(id).build();
    final double time = 123.45;

    final AmazonCloudWatch client = mock(AmazonCloudWatch.class);

    final CloudWatchRecorder recorder = new CloudWatchRecorder.Builder()
            .client(client)
            .namespace(namespace)
            .publishFrequency(120)
            .maxJitter(60)
            .dimensionMapper(mapper)
            .build();

    final MetricContext context = recorder.context(data);
    context.record(M_TIME, time, Unit.MILLISECOND, Instant.now());
    context.close();

    // shutdown right away, before first scheduled publish
    recorder.shutdown();

    final List<MetricDatum> expected = new ArrayList<>(1);
    expected.add(makeDatum(id, M_TIME.toString(), time, time, time, 1, StandardUnit.Milliseconds));

    verify(client).putMetricData(argThat(new RequestMatcher(namespace, expected)));
}
 
Example #26
Source File: ListMetrics.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
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();

        ListMetricsRequest request = new ListMetricsRequest()
                .withMetricName(name)
                .withNamespace(namespace);

        boolean done = false;

        while(!done) {
            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;
            }
        }
    }
 
Example #27
Source File: ScanUploadModule.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Provides
@Singleton
protected AmazonCloudWatch provideAmazonCloudWatch(Region region, AWSCredentialsProvider credentialsProvider) {
    AmazonCloudWatch cloudWatch = new AmazonCloudWatchClient(credentialsProvider);
    cloudWatch.setRegion(region);
    return cloudWatch;
}
 
Example #28
Source File: AmazonDockerClientsHolder.java    From spring-localstack with Apache License 2.0 5 votes vote down vote up
@Override
public AmazonCloudWatch amazonCloudWatch() {
    return decorateWithConfigsAndBuild(
        AmazonCloudWatchClientBuilder.standard(),
        LocalstackDocker::getEndpointCloudWatch
    );
}
 
Example #29
Source File: DynamoDBTableReplicator.java    From podyn with Apache License 2.0 5 votes vote down vote up
public void startReplicatingChanges() throws StreamNotEnabledException {
	if (tableSchema == null) {
		throw new TableExistsException("table %s does not exist in destination", dynamoTableName);
	}

	String tableStreamArn = getStreamArn();

	if (tableStreamArn == null) {
		throw new StreamNotEnabledException("table %s does not have a stream enabled\n", dynamoTableName);
	}

	AmazonDynamoDBStreamsAdapterClient adapterClient = new AmazonDynamoDBStreamsAdapterClient(streamsClient);
	AmazonCloudWatch cloudWatchClient = AmazonCloudWatchClientBuilder.standard().build();

	String workerId = generateWorkerId();

	final KinesisClientLibConfiguration workerConfig = new KinesisClientLibConfiguration(
			APPLICATION_NAME, tableStreamArn, awsCredentialsProvider, workerId).
			withMaxRecords(1000).
			withIdleTimeBetweenReadsInMillis(500).
			withCallProcessRecordsEvenForEmptyRecordList(false).
			withCleanupLeasesUponShardCompletion(false).
			withFailoverTimeMillis(20000).
			withTableName(LEASE_TABLE_PREFIX + dynamoTableName).
			withInitialPositionInStream(InitialPositionInStream.TRIM_HORIZON);

	Worker worker = new Worker.Builder().
			recordProcessorFactory(recordProcessorFactory).
			config(workerConfig).
			kinesisClient(adapterClient).
			cloudWatchClient(cloudWatchClient).
			dynamoDBClient(dynamoDBClient).
			execService(executor).
			build();

	executor.execute(worker);
}
 
Example #30
Source File: EveryAwsClientAutoConfiguration.java    From spring-localstack with Apache License 2.0 4 votes vote down vote up
@Bean
public AmazonCloudWatch amazonCloudWatch() {
    return amazonClientsHolder.amazonCloudWatch();
}