Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Licensed under the Apache License, Version 2.0 (the "License").
   * You may not use this file except in compliance with the License.
   * A copy of the License is located at
   * or in the "license" file accompanying this file. This file is distributed
  * express or implied. See the License for the specific language governing
  * permissions and limitations under the License.
 package com.amazonaws.metrics.internal.cloudwatch;
Configuration for the default AWS SDK collection implementation. This class is not intended to be used directly by client code except for cases where the default behavior of the internal Amazon CloudWatch collector implementation needs to be customized.


  * My custom Request Metric Collector by extending from the internal Amazon CloudWatch
  * implementation.
 static class MyCloudWatchMetricCollector extends
         CloudWatchRequestMetricCollector {
     MyCloudWatchMetricCollector(CloudWatchMetricConfig config) {
 MyCloudWatchMetricCollector myCollector = new MyCloudWatchMetricCollector(
         new CloudWatchMetricConfig()
                         new DefaultAWSCredentialsProviderChain())
                         new HashSet<Field>(Arrays.asList(Field.HttpRequestTime,
 // Enable the AWS SDK level request metric collection with a custom collector

 public class CloudWatchMetricConfig {
     static final String NAMESPACE_DELIMITER = "/";
Maximum number of metric data that Amazon CloudWatch can accept in a single request
     static final int MAX_METRICS_DATUM_SIZE = 20;
Default metrics queue size. If the queue size exceeds this value, then excessive metrics will be dropped to prevent resource exhaustion.
     public static final int DEFAULT_METRICS_QSIZE = 1000;
Default timeout in millisecond for queue polling. Set to one-minute which is the finest granularity of Amazon CloudWatch.
     public static final int DEFAULT_QUEUE_POLL_TIMEOUT_MILLI = (int)..toMillis(1);

Credentials for the uploader to communicate with Amazon CloudWatch
     private AWSCredentialsProvider credentialsProvider;

Number of milliseconds to wait before the polling of the metrics queue times out.
     private long queuePollTimeoutMilli = ;

Endpoint for Amazon CloudWatch where the metric data can be uploaded; or null if the default endpoint is to be used.
     private String cloudWatchEndPoint;
     private int metricQueueSize = ;

Returns the credential provider that holds the credentials to connect to Amazon CloudWatch.
        return ;

Sets the credential provider to the given provider. This credential provider is used by the uploader thread to connect to Amazon CloudWatch.
    public void setCredentialsProvider(AWSCredentialsProvider credentialsProvider) {
        this. = credentialsProvider;
        return this;

Returns the metrics queue polling timeout in millisecond.
    public long getQueuePollTimeoutMilli() {
        return ;

Sets the metric queue polling timeout in millisecond. The default set set to one-minute per the finest granularity of Amazon CloudWatch
    public void setQueuePollTimeoutMilli(long queuePollTimeoutMilli) {
        this. = queuePollTimeoutMilli;
    public CloudWatchMetricConfig withQueuePollTimeoutMilli(long queuePollTimeoutMilli) {
        return this;

Returns the end point of AmazonCloudWatch to upload the metrics.
    public String getCloudWatchEndPoint() {
        return ;

Sets the end point of AmazonCloudWatch to upload the metrics.
    public void setCloudWatchEndPoint(String cloudWatchEndPoint) {
        this. = cloudWatchEndPoint;
    public CloudWatchMetricConfig withCloudWatchEndPoint(String cloudWatchEndPoint) {
        return this;
    public int getMetricQueueSize() {
        return ;

Configure the metric queue size, overriding the default. Must be at least 1.

    public void setMetricQueueSize(int metricQueueSize) {
        if (metricQueueSize < 1) {
            throw new IllegalArgumentException();
        this. = metricQueueSize;
    public CloudWatchMetricConfig withMetricQueueSize(int metricQueueSize) {
        return this;
New to GrepCode? Check out our FAQ X