@Bean @ConditionalOnMissingBean(AmazonCloudWatchAsyncClient.class) public AmazonCloudWatchAsync amazonCloudWatchAsync(AWSCredentialsProvider credentialsProvider) { return AmazonCloudWatchAsyncClientBuilder.standard() .withCredentials(credentialsProvider) .build(); }
ReportingApp() { this.metricRegistry = new MetricRegistry(); this.theTimer = metricRegistry.timer("TheTimer"); final AmazonCloudWatchAsync amazonCloudWatchAsync = AmazonCloudWatchAsyncClientBuilder .standard() .withRegion(Regions.US_WEST_2) .build(); final CloudWatchReporter cloudWatchReporter = CloudWatchReporter.forRegistry(metricRegistry, amazonCloudWatchAsync, Main.class.getName()) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .filter(MetricFilter.ALL) .withPercentiles(Percentile.P75, Percentile.P99) .withOneMinuteMeanRate() .withFiveMinuteMeanRate() .withFifteenMinuteMeanRate() .withMeanRate() .withArithmeticMean() .withStdDev() .withStatisticSet() .withJvmMetrics() .withGlobalDimensions("Region=us-west-2", "Instance=stage") .withDryRun() .build(); cloudWatchReporter.start(10, TimeUnit.SECONDS); }
public static AmazonCloudWatchAsyncClient getStatsAsyncClient( AuthCredentialsServiceState credentials, String region, ExecutorService executorService, boolean isMockRequest) { ClientConfiguration configuration = new ClientConfiguration(); configuration.withRetryPolicy(new RetryPolicy(new CustomRetryCondition(), DEFAULT_BACKOFF_STRATEGY, DEFAULT_MAX_ERROR_RETRY, false)); AWSStaticCredentialsProvider awsStaticCredentialsProvider = new AWSStaticCredentialsProvider( new BasicAWSCredentials(credentials.privateKeyId, EncryptionUtils.decrypt(credentials.privateKey))); AmazonCloudWatchAsyncClientBuilder amazonCloudWatchAsyncClientBuilder = AmazonCloudWatchAsyncClientBuilder .standard() .withClientConfiguration(configuration) .withCredentials(awsStaticCredentialsProvider) .withExecutorFactory(() -> executorService); if (region == null) { region = Regions.DEFAULT_REGION.getName(); } if (isAwsClientMock()) { configuration.addHeader(AWS_REGION_HEADER, region); amazonCloudWatchAsyncClientBuilder.setClientConfiguration(configuration); AwsClientBuilder.EndpointConfiguration endpointConfiguration = new AwsClientBuilder.EndpointConfiguration( getAWSMockHost() + AWS_MOCK_CLOUDWATCH_ENDPOINT, region); amazonCloudWatchAsyncClientBuilder.setEndpointConfiguration(endpointConfiguration); } else { amazonCloudWatchAsyncClientBuilder.setRegion(region); } return (AmazonCloudWatchAsyncClient) amazonCloudWatchAsyncClientBuilder.build(); }