com.amazonaws.services.cloudwatch.AmazonCloudWatchAsync Java Examples

The following examples show how to use com.amazonaws.services.cloudwatch.AmazonCloudWatchAsync. 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: DynamoDBReplicationEmitter.java    From dynamodb-cross-region-library with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor with given parameters, used for when MultiRegionEmitter creates emitter dynamically.
 *
 * @param endpoint
 *            The endpoint of the emitter
 * @param region
 *            The region of the emitter
 * @param tableName
 *            The tableName the emitter should emit to
 * @param dynamoDBAsync
 *            The DynamoDB client used for this application
 * @param cloudwatch
 *            The cloudwatch client used for this application
 */
@SuppressWarnings("deprecation")
public DynamoDBReplicationEmitter(final String applicationName, final String endpoint, final String region, final String tableName,
                                  final AmazonDynamoDBAsync dynamoDBAsync, final AmazonCloudWatchAsync cloudwatch) {
    this.applicationName = applicationName;
    this.endpoint = endpoint;
    this.region = region;
    this.tableName = tableName;

    final boolean setDynamoDB = DYNAMODB.compareAndSet(null, dynamoDBAsync);
    if (setDynamoDB && dynamoDBAsync != null) {
        DYNAMODB.get().setEndpoint(endpoint);
    }
    final boolean setCloudWatch = CLOUDWATCH.compareAndSet(null, cloudwatch);
    if (setCloudWatch && cloudwatch != null) {
        CLOUDWATCH.get().setRegion(Regions.getCurrentRegion() == null ? Region.getRegion(Regions.US_EAST_1) : Regions.getCurrentRegion());
    }
    skipErrors = false; // TODO make configurable
}
 
Example #2
Source File: DynamoDBReplicationEmitter.java    From dynamodb-cross-region-library with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void fail(final List<Record> records) {
    if (isShutdown) {
        if (records.isEmpty()) {
            // This is OK (but not expected)
            log.warn("Emitter fail method called after shutdown method was called. Continuing because list is empty");
            return;
        } else {
            throw new IllegalStateException("Emitter fail method called after shutdown method was called.");
        }
    }
    for (Record record : records) {
        log.error("Could not emit record: " + record);
    }
    final AmazonCloudWatchAsync cloudwatch = CLOUDWATCH.get();
    if (null != cloudwatch) {
        final double failed = records.size();
        final MetricDatum recordsProcessedFailedDatum = new MetricDatum().withMetricName(RECORDS_FAILED).withValue(failed).withUnit(StandardUnit.Count)
            .withTimestamp(new Date());
        final PutMetricDataRequest request = new PutMetricDataRequest().withNamespace(applicationName).withMetricData(recordsProcessedFailedDatum);
        cloudwatch.putMetricDataAsync(request);
    }
}
 
Example #3
Source File: CloudWatchMeterRegistry.java    From micrometer with Apache License 2.0 5 votes vote down vote up
public CloudWatchMeterRegistry(CloudWatchConfig config, Clock clock,
                               AmazonCloudWatchAsync amazonCloudWatchAsync, ThreadFactory threadFactory) {
    super(config, clock);

    if (config.namespace() == null) {
        throw new io.micrometer.core.instrument.config.MissingRequiredConfigurationException(
                "namespace must be set to report metrics to CloudWatch");
    }

    this.amazonCloudWatchAsync = amazonCloudWatchAsync;
    this.config = config;
    config().namingConvention(new CloudWatchNamingConvention());
    start(threadFactory);
}
 
Example #4
Source File: KinesisBinderConfiguration.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(name = "spring.cloud.stream.kinesis.binder.kpl-kcl-enabled")
public AmazonCloudWatchAsync cloudWatch() {
	if (this.hasInputs) {
		return AmazonCloudWatchAsyncClientBuilder.standard()
				.withCredentials(this.awsCredentialsProvider)
				.withRegion(this.region)
				.build();
	}
	else {
		return null;
	}
}
 
Example #5
Source File: CloudWatchReporter.java    From metrics-cloudwatch with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link ScheduledReporter} instance. The reporter does not report metrics until
 * {@link #start(long, TimeUnit)}.
 *
 * @param registry        the {@link MetricRegistry} containing the metrics this reporter will report
 * @param metricNamespace (optional) CloudWatch metric namespace that all metrics reported by this reporter will
 *                        fall under
 * @param metricFilter    (optional) see {@link MetricFilter}
 * @param cloudWatch      client
 */
public CloudWatchReporter(MetricRegistry registry,
                          String metricNamespace,
                          MetricFilter metricFilter,
                          AmazonCloudWatchAsync cloudWatch) {

    super(registry, "CloudWatchReporter:" + metricNamespace, metricFilter, TimeUnit.MINUTES, TimeUnit.MINUTES);

    this.metricNamespace = metricNamespace;
    this.cloudWatch = cloudWatch;
}
 
Example #6
Source File: CloudWatchExportAutoConfiguration.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingAmazonClient(AmazonCloudWatchAsync.class)
public AmazonWebserviceClientFactoryBean<AmazonCloudWatchAsyncClient> amazonCloudWatchAsync(
		AWSCredentialsProvider credentialsProvider,
		ObjectProvider<RegionProvider> regionProvider) {
	return new AmazonWebserviceClientFactoryBean<>(AmazonCloudWatchAsyncClient.class,
			credentialsProvider, regionProvider.getIfAvailable());
}
 
Example #7
Source File: AmazonAsyncDockerClientsHolder.java    From spring-localstack with Apache License 2.0 5 votes vote down vote up
@Override
public AmazonCloudWatchAsync amazonCloudWatch() {
    return decorateWithConfigsAndBuild(
        AmazonCloudWatchAsyncClientBuilder.standard(),
        LocalstackDocker::getEndpointCloudWatch
    );
}
 
Example #8
Source File: CloudWatchExportAutoConfiguration.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnProperty(value = "management.metrics.export.cloudwatch.enabled",
		matchIfMissing = true)
public CloudWatchMeterRegistry cloudWatchMeterRegistry(CloudWatchConfig config,
		Clock clock, AmazonCloudWatchAsync client) {
	return new CloudWatchMeterRegistry(config, clock, client);
}
 
Example #9
Source File: CloudWatchMachineDimensionReporter.java    From dropwizard-metrics-cloudwatch with Apache License 2.0 4 votes vote down vote up
public CloudWatchMachineDimensionReporter(MetricRegistry registry, String metricNamespace, List<String> dimensions,
                                          MetricFilter metricFilter, AmazonCloudWatchAsync cloudWatch) {

    super(registry, metricNamespace, metricFilter, cloudWatch);
    this.dimensions = dimensions;
}
 
Example #10
Source File: CloudWatchReporterBuilder.java    From metrics-cloudwatch with Apache License 2.0 4 votes vote down vote up
/**
 * @return a new CloudWatchReporter instance based on the state of this builder
 */
public CloudWatchReporter build() {
    Preconditions.checkState(!Strings.isNullOrEmpty(namespace), "Metric namespace is required.");

    String resolvedNamespace = namespace;

    // Use specified or fall back to default. Don't secretly modify the fields of this builder
    // in case the caller wants to re-use it to build other reporters, or something.

    MetricRegistry resolvedRegistry = null != registry ? registry : new MetricRegistry();
    MetricFilter resolvedFilter = null != filter ? filter : MetricFilter.ALL;
    AmazonCloudWatchAsync resolvedCloudWatchClient = null != client ? client : new AmazonCloudWatchAsyncClient();
    String resolvedDimensions = null != dimensions ? dimensions : null;
    Boolean resolvedTimestampLocal = null != timestampLocal ? timestampLocal : false;

    String resolvedTypeDimName = null != typeDimName ? typeDimName : Constants.DEF_DIM_NAME_TYPE;
    String resolvedTypeDimValGauge = null != typeDimValGauge ? typeDimValGauge : Constants.DEF_DIM_VAL_GAUGE;
    String resolvedTypeDimValCounterCount = null != typeDimValCounterCount ? typeDimValCounterCount : Constants.DEF_DIM_VAL_COUNTER_COUNT;
    String resolvedTypeDimValMeterCount = null != typeDimValMeterCount ? typeDimValMeterCount : Constants.DEF_DIM_VAL_METER_COUNT;
    String resolvedTypeDimValHistoSamples = null != typeDimValHistoSamples ? typeDimValHistoSamples : Constants.DEF_DIM_VAL_HISTO_SAMPLES;
    String resolvedTypeDimValHistoStats = null != typeDimValHistoStats ? typeDimValHistoStats : Constants.DEF_DIM_VAL_HISTO_STATS;
    String resolvedTypeDimValTimerSamples = null != typeDimValTimerSamples ? typeDimValTimerSamples : Constants.DEF_DIM_VAL_TIMER_SAMPLES;
    String resolvedTypeDimValTimerStats = null != typeDimValTimerStats ? typeDimValTimerStats : Constants.DEF_DIM_VAL_TIMER_STATS;

    Predicate<MetricDatum> resolvedReporterFilter = null != reporterFilter ? reporterFilter : Predicates.<MetricDatum>alwaysTrue();

    return new CloudWatchReporter(
            resolvedRegistry,
            resolvedNamespace,
            resolvedFilter,
            resolvedCloudWatchClient)
            .withDimensions(resolvedDimensions)
            .withTimestampLocal(resolvedTimestampLocal)
            .withTypeDimName(resolvedTypeDimName)
            .withTypeDimValGauge(resolvedTypeDimValGauge)
            .withTypeDimValCounterCount(resolvedTypeDimValCounterCount)
            .withTypeDimValMeterCount(resolvedTypeDimValMeterCount)
            .withTypeDimValHistoSamples(resolvedTypeDimValHistoSamples)
            .withTypeDimValHistoStats(resolvedTypeDimValHistoStats)
            .withTypeDimValTimerSamples(resolvedTypeDimValTimerSamples)
            .withTypeDimValTimerStats(resolvedTypeDimValTimerStats)
            .withReporterFilter(resolvedReporterFilter);
}
 
Example #11
Source File: CloudWatchReporterBuilder.java    From metrics-cloudwatch with Apache License 2.0 4 votes vote down vote up
/**
 * @param client CloudWatch client
 * @return this (for chaining)
 */
public CloudWatchReporterBuilder withClient(AmazonCloudWatchAsync client) {
    this.client = client;
    return this;
}
 
Example #12
Source File: CloudWatchReporterFactoryTest.java    From dropwizard-metrics-cloudwatch with Apache License 2.0 4 votes vote down vote up
@Test
public void verifySendingToCloudWatch() throws Exception {
    CloudWatchReporterFactory factory = new CloudWatchReporterFactory();

    MetricRegistry registry = new MetricRegistry();
    Counter counter = registry.counter(MetricRegistry.name(this.getClass(), "test machine=123*"));


    AmazonCloudWatchAsync mockClient = mock(AmazonCloudWatchAsync.class);

    final Future<Void> mockFuture = mock(Future.class);
    when(mockClient.putMetricDataAsync(any(PutMetricDataRequest.class))).thenReturn(mockFuture);
    when(mockClient.putMetricDataAsync(any(PutMetricDataRequest.class))).thenAnswer(new Answer<Future>() {
        @Override
        public Future answer(InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();

            if (args.length > 0 && args[0] != null) {
                PutMetricDataRequest req = (PutMetricDataRequest) args[0];
                assertEquals(req.getNamespace(), "myspace");
                for (MetricDatum datum : req.getMetricData()) {
                    System.out.println(datum.toString());
                    assertTrue(datum.toString().contains("env"));
                }
            }

            return mockFuture;
        }
    });

    factory.setClient(mockClient);
    factory.setAwsAccessKeyId("fakeKey");
    factory.setAwsSecretKey("fakeSecret");
    factory.setNamespace("myspace");
    factory.setGlobalDimensions(Lists.newArrayList("env=dev"));
    ScheduledReporter reporter = factory.build(registry);

    for (int i = 0; i < 200; i++) {
        counter.inc();
    }
    reporter.report();
    verify(mockClient.putMetricDataAsync(any(PutMetricDataRequest.class)), times(1));
}
 
Example #13
Source File: CloudWatchReporterFactory.java    From dropwizard-metrics-cloudwatch with Apache License 2.0 4 votes vote down vote up
@JsonIgnore
public void setClient(AmazonCloudWatchAsync client) {
    this.client = client;
}
 
Example #14
Source File: CloudWatchMeterRegistry.java    From micrometer with Apache License 2.0 4 votes vote down vote up
public CloudWatchMeterRegistry(CloudWatchConfig config, Clock clock,
                               AmazonCloudWatchAsync amazonCloudWatchAsync) {
    this(config, clock, amazonCloudWatchAsync, new NamedThreadFactory("cloudwatch-metrics-publisher"));
}
 
Example #15
Source File: DynamoDBReplicationEmitter.java    From dynamodb-cross-region-library with Apache License 2.0 3 votes vote down vote up
/**
 * Constructor with given parameters, used for when MultiRegionEmitter creates emitter dynamically.
 *
 * @param endpoint
 *            The endpoint of the emitter
 * @param region
 *            The region of the emitter
 * @param tableName
 *            The tableName the emitter should emit to
 * @param cloudwatch
 *            The cloudwatch client used for this application
 * @param credentialProvider
 *            The credential provider used for the DynamoDB client
 * @deprecated Deprecated by {@link #DynamoDBReplicationEmitter(String, String, String, String, AmazonDynamoDBAsync, AmazonCloudWatchAsync)}
 */
@Deprecated
public DynamoDBReplicationEmitter(final String applicationName, final String endpoint, final String region, final String tableName,
                                  final AmazonCloudWatchAsync cloudwatch, final AWSCredentialsProvider credentialProvider) {
    this(applicationName, endpoint, region, tableName,
            new AmazonDynamoDBAsyncClient(credentialProvider, new ClientConfiguration().withMaxConnections(MAX_THREADS).withRetryPolicy(PredefinedRetryPolicies.DYNAMODB_DEFAULT), Executors.newFixedThreadPool(MAX_THREADS)),
            cloudwatch);
}
 
Example #16
Source File: DynamoDBReplicationEmitter.java    From dynamodb-cross-region-library with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor with given parameters and default CloudWatch client.
 * @param configuration
 *            The configuration for this emitter
 * @param dynamoDBAsync
 *            The DynamoDB client used for this application
 * @param cloudwatch
 *            The cloudwatch client used for this application
 */
public DynamoDBReplicationEmitter(final DynamoDBStreamsConnectorConfiguration configuration, final AmazonDynamoDBAsync dynamoDBAsync,
                                  final AmazonCloudWatchAsync cloudwatch) {
    this(configuration.APP_NAME, configuration.DYNAMODB_ENDPOINT, configuration.REGION_NAME, configuration.DYNAMODB_DATA_TABLE_NAME,
            dynamoDBAsync, cloudwatch);
}
 
Example #17
Source File: CloudWatchReporter.java    From metrics-cloudwatch with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new {@link ScheduledReporter} instance. The reporter does not report metrics until
 * {@link #start(long, TimeUnit)}.
 *
 * @param registry   the {@link MetricRegistry} containing the metrics this reporter will report
 * @param cloudWatch client
 */
public CloudWatchReporter(MetricRegistry registry, AmazonCloudWatchAsync cloudWatch) {
    this(registry, null, cloudWatch);
}
 
Example #18
Source File: CloudWatchReporter.java    From metrics-cloudwatch with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a new {@link ScheduledReporter} instance. The reporter does not report metrics until
 * {@link #start(long, TimeUnit)}.
 *
 * @param registry        the {@link MetricRegistry} containing the metrics this reporter will report
 * @param metricNamespace (optional) CloudWatch metric namespace that all metrics reported by this reporter will
 *                        fall under
 * @param cloudWatch      client
 */
public CloudWatchReporter(MetricRegistry registry,
                          String metricNamespace,
                          AmazonCloudWatchAsync cloudWatch) {
    this(registry, metricNamespace, MetricFilter.ALL, cloudWatch);
}
 
Example #19
Source File: DynamoDBReplicationEmitter.java    From dynamodb-cross-region-library with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor with default CloudWatch client and default DynamoDBAsync.
 *
 * @param configuration
 *            The configuration for this emitter.
 * @deprecated Deprecated by {@link #DynamoDBReplicationEmitter(DynamoDBStreamsConnectorConfiguration, AmazonDynamoDBAsync, AmazonCloudWatchAsync)}
 */
@Deprecated
public DynamoDBReplicationEmitter(final DynamoDBStreamsConnectorConfiguration configuration) {
    this(configuration.APP_NAME, configuration.DYNAMODB_ENDPOINT, configuration.REGION_NAME, configuration.DYNAMODB_DATA_TABLE_NAME,
        (AmazonCloudWatchAsync) new AmazonCloudWatchAsyncClient(new DefaultAWSCredentialsProviderChain(), Executors.newFixedThreadPool(MAX_THREADS)).withRegion(Regions.getCurrentRegion() == null ? Region.getRegion(Regions.US_EAST_1) : Regions.getCurrentRegion()), new DefaultAWSCredentialsProviderChain());
}