software.amazon.awssdk.services.cloudwatch.model.Dimension Java Examples

The following examples show how to use software.amazon.awssdk.services.cloudwatch.model.Dimension. 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: MetricsPublisherImplTest.java    From cloudformation-cli-java-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublishDurationMetric() {
    final MetricsPublisherImpl providerMetricsPublisher = new MetricsPublisherImpl(providerCloudWatchProvider, loggerProxy,
                                                                                   awsAccountId, resourceTypeName);
    providerMetricsPublisher.refreshClient();

    final Instant instant = Instant.parse("2019-06-04T17:50:00Z");
    providerMetricsPublisher.publishDurationMetric(instant, Action.UPDATE, 123456);

    final ArgumentCaptor<PutMetricDataRequest> argument1 = ArgumentCaptor.forClass(PutMetricDataRequest.class);
    verify(providerCloudWatchClient).putMetricData(argument1.capture());

    final PutMetricDataRequest request = argument1.getValue();
    assertThat(request.namespace())
        .isEqualTo(String.format("%s/%s/%s", "AWS/CloudFormation", awsAccountId, "AWS/Test/TestModel"));

    assertThat(request.metricData()).hasSize(1);
    final MetricDatum metricDatum = request.metricData().get(0);
    assertThat(metricDatum.metricName()).isEqualTo("HandlerInvocationDuration");
    assertThat(metricDatum.unit()).isEqualTo(StandardUnit.MILLISECONDS);
    assertThat(metricDatum.value()).isEqualTo(123456);
    assertThat(metricDatum.timestamp()).isEqualTo(Instant.parse("2019-06-04T17:50:00Z"));
    assertThat(metricDatum.dimensions()).containsExactlyInAnyOrder(Dimension.builder().name("Action").value("UPDATE").build(),
        Dimension.builder().name("ResourceType").value(resourceTypeName).build());
}
 
Example #2
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 6 votes vote down vote up
@Test
public void shouldReportExpectedGlobalAndCustomDimensions() throws Exception {


    metricRegistry.counter(DimensionedName.withName(ARBITRARY_COUNTER_NAME)
        .withDimension("key1", "value1")
        .withDimension("key2", "value2")
        .build().encode()).inc();
    reporterBuilder.withGlobalDimensions("Region=us-west-2").build().report();

    final List<Dimension> dimensions = firstMetricDatumDimensionsFromCapturedRequest();

    assertThat(dimensions).contains(Dimension.builder().name("Region").value("us-west-2").build());
    assertThat(dimensions).contains(Dimension.builder().name("key1").value("value1").build());
    assertThat(dimensions).contains(Dimension.builder().name("key2").value("value2").build());
}
 
Example #3
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 6 votes vote down vote up
private MetricDatum metricDatumByDimensionFromCapturedRequest(final String dimensionValue) {
    final PutMetricDataRequest putMetricDataRequest = metricDataRequestCaptor.getValue();
    final List<MetricDatum> metricData = putMetricDataRequest.metricData();

    final Optional<MetricDatum> metricDatumOptional =
            metricData
                    .stream()
                    .filter(metricDatum -> metricDatum.dimensions()
                            .contains(Dimension.builder().name(DIMENSION_NAME_TYPE).value(dimensionValue).build()))
                    .findFirst();

    if (metricDatumOptional.isPresent()) {
        return metricDatumOptional.get();
    }

    throw new IllegalStateException("Could not find MetricDatum for Dimension value: " + dimensionValue);
}
 
Example #4
Source File: CloudWatchReporter.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 6 votes vote down vote up
/**
 * Please note, the reported values submitted only if they show some data (greater than zero) in order to:
 * <p>
 * 1. save some money
 * 2. prevent com.amazonaws.services.cloudwatch.model.InvalidParameterValueException if empty {@link Snapshot}
 * is submitted
 * <p>
 * If {@link Builder#withZeroValuesSubmission()} is {@code true}, then all values will be submitted
 */
private void stageMetricDatum(final boolean metricConfigured,
                              final String metricName,
                              final double metricValue,
                              final StandardUnit standardUnit,
                              final String dimensionValue,
                              final List<MetricDatum> metricData) {
    // Only submit metrics that show some data, so let's save some money
    if (metricConfigured && (builder.withZeroValuesSubmission || metricValue > 0)) {
        final DimensionedName dimensionedName = DimensionedName.decode(metricName);

        final Set<Dimension> dimensions = new LinkedHashSet<>(builder.globalDimensions);
        dimensions.add(Dimension.builder().name(DIMENSION_NAME_TYPE).value(dimensionValue).build());
        dimensions.addAll(dimensionedName.getDimensions());

        metricData.add(MetricDatum.builder()
                .timestamp(Instant.ofEpochMilli(builder.clock.getTime()))
                .value(cleanMetricValue(metricValue))
                .metricName(dimensionedName.getName())
                .dimensions(dimensions)
                .storageResolution(highResolution ? HIGH_RESOLUTION : STANDARD_RESOLUTION)
                .unit(standardUnit)
                .build());
    }
}
 
Example #5
Source File: PutMetricData.java    From aws-doc-sdk-examples with Apache License 2.0 6 votes vote down vote up
public static void putMetData(CloudWatchClient cw, Double dataPoint ) {

        try {
            Dimension dimension = Dimension.builder()
                .name("UNIQUE_PAGES")
                .value("URLS").build();

            MetricDatum datum = MetricDatum.builder()
                .metricName("PAGES_VISITED")
                .unit(StandardUnit.NONE)
                .value(dataPoint)
                .dimensions(dimension).build();

            PutMetricDataRequest request = PutMetricDataRequest.builder()
                .namespace("SITE/TRAFFIC")
                .metricData(datum).build();

            PutMetricDataResponse response = cw.putMetricData(request);

        } catch (CloudWatchException e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }
        System.out.printf("Successfully put data point %f", dataPoint);
        // snippet-end:[cloudwatch.java2.put_metric_data.main]
    }
 
Example #6
Source File: MetricsPublisherImplTest.java    From cloudformation-cli-java-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void testPublishInvocationMetric() {
    final MetricsPublisherImpl providerMetricsPublisher = new MetricsPublisherImpl(providerCloudWatchProvider, loggerProxy,
                                                                                   awsAccountId, resourceTypeName);
    providerMetricsPublisher.refreshClient();

    final Instant instant = Instant.parse("2019-06-04T17:50:00Z");
    providerMetricsPublisher.publishInvocationMetric(instant, Action.UPDATE);

    final ArgumentCaptor<PutMetricDataRequest> argument1 = ArgumentCaptor.forClass(PutMetricDataRequest.class);
    verify(providerCloudWatchClient).putMetricData(argument1.capture());

    final PutMetricDataRequest request = argument1.getValue();
    assertThat(request.namespace())
        .isEqualTo(String.format("%s/%s/%s", "AWS/CloudFormation", awsAccountId, "AWS/Test/TestModel"));

    assertThat(request.metricData()).hasSize(1);
    final MetricDatum metricDatum = request.metricData().get(0);
    assertThat(metricDatum.metricName()).isEqualTo("HandlerInvocationCount");
    assertThat(metricDatum.unit()).isEqualTo(StandardUnit.COUNT);
    assertThat(metricDatum.value()).isEqualTo(1.0);
    assertThat(metricDatum.timestamp()).isEqualTo(Instant.parse("2019-06-04T17:50:00Z"));
    assertThat(metricDatum.dimensions()).containsExactlyInAnyOrder(Dimension.builder().name("Action").value("UPDATE").build(),
        Dimension.builder().name("ResourceType").value(resourceTypeName).build());
}
 
Example #7
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void shouldReportExpectedMultipleGlobalDimensions() throws Exception {
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    reporterBuilder.withGlobalDimensions("Region=us-west-2", "Instance=stage").build().report();

    final List<Dimension> dimensions = firstMetricDatumDimensionsFromCapturedRequest();

    assertThat(dimensions).contains(Dimension.builder().name("Region").value("us-west-2").build());
    assertThat(dimensions).contains(Dimension.builder().name("Instance").value("stage").build());
}
 
Example #8
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void reportedMeterShouldContainExpectedFifteenMinuteMeanRateDimension() throws Exception {
    metricRegistry.meter(ARBITRARY_METER_NAME).mark(1);
    buildReportWithSleep(reporterBuilder.withFifteenMinuteMeanRate());

    final List<Dimension> dimensions = allDimensionsFromCapturedRequest();

    assertThat(dimensions).contains(Dimension.builder().name(DIMENSION_NAME_TYPE).value("15-min-mean-rate [per-second]").build());
}
 
Example #9
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void reportedMeterShouldContainExpectedMeanRateDimension() throws Exception {
    metricRegistry.meter(ARBITRARY_METER_NAME).mark(1);
    reporterBuilder.withMeanRate().build().report();

    final List<Dimension> dimensions = allDimensionsFromCapturedRequest();

    assertThat(dimensions).contains(Dimension.builder().name(DIMENSION_NAME_TYPE).value("mean-rate [per-second]").build());
}
 
Example #10
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void reportedHistogramShouldContainExpectedArithmeticMeanDimension() throws Exception {
    metricRegistry.histogram(ARBITRARY_HISTOGRAM_NAME).update(1);
    reporterBuilder.withArithmeticMean().build().report();

    final List<Dimension> dimensions = allDimensionsFromCapturedRequest();

    assertThat(dimensions).contains(Dimension.builder().name(DIMENSION_NAME_TYPE).value(DIMENSION_SNAPSHOT_MEAN).build());
}
 
Example #11
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void reportedHistogramShouldContainExpectedStdDevDimension() throws Exception {
    metricRegistry.histogram(CloudWatchReporterTest.ARBITRARY_HISTOGRAM_NAME).update(1);
    metricRegistry.histogram(CloudWatchReporterTest.ARBITRARY_HISTOGRAM_NAME).update(2);
    reporterBuilder.withStdDev().build().report();

    final List<Dimension> dimensions = allDimensionsFromCapturedRequest();

    assertThat(dimensions).contains(Dimension.builder().name(DIMENSION_NAME_TYPE).value(DIMENSION_SNAPSHOT_STD_DEV).build());
}
 
Example #12
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void reportedTimerShouldContainExpectedArithmeticMeanDimension() throws Exception {
    metricRegistry.timer(ARBITRARY_TIMER_NAME).update(3, TimeUnit.MILLISECONDS);
    reporterBuilder.withArithmeticMean().build().report();

    final List<Dimension> dimensions = allDimensionsFromCapturedRequest();

    assertThat(dimensions).contains(Dimension.builder().name(DIMENSION_NAME_TYPE).value("snapshot-mean [in-milliseconds]").build());
}
 
Example #13
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void reportedTimerShouldContainExpectedStdDevDimension() throws Exception {
    metricRegistry.timer(ARBITRARY_TIMER_NAME).update(1, TimeUnit.MILLISECONDS);
    metricRegistry.timer(ARBITRARY_TIMER_NAME).update(3, TimeUnit.MILLISECONDS);
    reporterBuilder.withStdDev().build().report();

    final List<Dimension> dimensions = allDimensionsFromCapturedRequest();

    assertThat(dimensions).contains(Dimension.builder().name(DIMENSION_NAME_TYPE).value("snapshot-std-dev [in-milliseconds]").build());
}
 
Example #14
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void shouldReportExpectedSingleGlobalDimension() throws Exception {
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    reporterBuilder.withGlobalDimensions("Region=us-west-2").build().report();

    final List<Dimension> dimensions = firstMetricDatumDimensionsFromCapturedRequest();

    assertThat(dimensions).contains(Dimension.builder().name("Region").value("us-west-2").build());
}
 
Example #15
Source File: MetricsPublisherImplTest.java    From cloudformation-cli-java-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testPublishExceptionMetric() {
    final MetricsPublisherImpl providerMetricsPublisher = new MetricsPublisherImpl(providerCloudWatchProvider, loggerProxy,
                                                                                   awsAccountId, resourceTypeName);
    providerMetricsPublisher.refreshClient();

    final Instant instant = Instant.parse("2019-06-03T17:50:00Z");
    final RuntimeException e = new RuntimeException("some error");
    providerMetricsPublisher.publishExceptionMetric(instant, Action.CREATE, e, HandlerErrorCode.InternalFailure);

    final ArgumentCaptor<PutMetricDataRequest> argument1 = ArgumentCaptor.forClass(PutMetricDataRequest.class);
    verify(providerCloudWatchClient).putMetricData(argument1.capture());

    final PutMetricDataRequest request = argument1.getValue();
    assertThat(request.namespace())
        .isEqualTo(String.format("%s/%s/%s", "AWS/CloudFormation", awsAccountId, "AWS/Test/TestModel"));

    assertThat(request.metricData()).hasSize(1);
    final MetricDatum metricDatum = request.metricData().get(0);
    assertThat(metricDatum.metricName()).isEqualTo("HandlerException");
    assertThat(metricDatum.unit()).isEqualTo(StandardUnit.COUNT);
    assertThat(metricDatum.value()).isEqualTo(1.0);
    assertThat(metricDatum.timestamp()).isEqualTo(Instant.parse("2019-06-03T17:50:00Z"));
    assertThat(metricDatum.dimensions()).containsExactlyInAnyOrder(Dimension.builder().name("Action").value("CREATE").build(),
        Dimension.builder().name("ExceptionType").value("class java.lang.RuntimeException").build(),
        Dimension.builder().name("ResourceType").value(resourceTypeName).build(),
        Dimension.builder().name("HandlerErrorCode").value("InternalFailure").build());
}
 
Example #16
Source File: LogMetricsScope.java    From amazon-kinesis-client with Apache License 2.0 5 votes vote down vote up
@Override
public void end() {
    StringBuilder output = new StringBuilder();
    output.append("Metrics:\n");

    output.append("Dimensions: ");
    boolean needsComma = false;
    for (Dimension dimension : getDimensions()) {
        output.append(String.format("%s[%s: %s]", needsComma ? ", " : "", dimension.name(), dimension.value()));
        needsComma = true;
    }
    output.append("\n");

    for (MetricDatum datum : data.values()) {
        StatisticSet statistics = datum.statisticValues();
        output.append(String.format("Name=%25s\tMin=%.2f\tMax=%.2f\tCount=%.2f\tSum=%.2f\tAvg=%.2f\tUnit=%s\n",
                datum.metricName(),
                statistics.minimum(),
                statistics.maximum(),
                statistics.sampleCount(),
                statistics.sum(),
                statistics.sum() / statistics.sampleCount(),
                datum.unit()));
    }

    log.info(output.toString());
}
 
Example #17
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void shouldNotReportDuplicateGlobalDimensions() throws Exception {
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    reporterBuilder.withGlobalDimensions("Region=us-west-2", "Region=us-west-2").build().report();

    final List<Dimension> dimensions = firstMetricDatumDimensionsFromCapturedRequest();

    assertThat(dimensions).containsNoDuplicates();
}
 
Example #18
Source File: FilteringMetricsScopeTest.java    From amazon-kinesis-client with Apache License 2.0 5 votes vote down vote up
void assertDimensions(Dimension... dimensions) {
    for (Dimension dimension : dimensions) {
        Assert.assertTrue(getDimensions().remove(dimension));
    }

    Assert.assertTrue("Dimensions should be empty at the end of assertDimensions", getDimensions().isEmpty());
}
 
Example #19
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
private List<Dimension> allDimensionsFromCapturedRequest() {
    final PutMetricDataRequest putMetricDataRequest = metricDataRequestCaptor.getValue();
    final List<MetricDatum> metricData = putMetricDataRequest.metricData();
    final List<Dimension> all = new LinkedList<>();
    for (final MetricDatum metricDatum : metricData) {
        all.addAll(metricDatum.dimensions());
    }
    return all;
}
 
Example #20
Source File: MetricAccumulatingQueueTest.java    From amazon-kinesis-client with Apache License 2.0 5 votes vote down vote up
@Test
public void testAccumulation() {
    Collection<Dimension> dimensionsA = Collections.singleton(dim("name","a"));
    Collection<Dimension> dimensionsB = Collections.singleton(dim("name","b"));
    String keyA = "a";
    String keyB = "b";

    MetricDatum datum1 =
            TestHelper.constructDatum(keyA, StandardUnit.COUNT, 10, 5, 15, 2).toBuilder().dimensions(dimensionsA).build();
    queue.offer(new CloudWatchMetricKey(datum1), datum1);
    MetricDatum datum2 =
            TestHelper.constructDatum(keyA, StandardUnit.COUNT, 1, 1, 2, 2).toBuilder().dimensions(dimensionsA).build();
    queue.offer(new CloudWatchMetricKey(datum2), datum2);

    MetricDatum datum3 =
            TestHelper.constructDatum(keyA, StandardUnit.COUNT, 1, 1, 2, 2).toBuilder().dimensions(dimensionsB).build();
    queue.offer(new CloudWatchMetricKey(datum3), datum3);

    MetricDatum datum4 = TestHelper.constructDatum(keyA, StandardUnit.COUNT, 1, 1, 2, 2);
    queue.offer(new CloudWatchMetricKey(datum4), datum4);
    queue.offer(new CloudWatchMetricKey(datum4), datum4);

    MetricDatum datum5 =
            TestHelper.constructDatum(keyB, StandardUnit.COUNT, 100, 10, 110, 2).toBuilder().dimensions(dimensionsA).build();
    queue.offer(new CloudWatchMetricKey(datum5), datum5);

    Assert.assertEquals(4, queue.size());
    List<MetricDatumWithKey<CloudWatchMetricKey>> items = queue.drain(4);

    Assert.assertEquals(items.get(0).datum, TestHelper.constructDatum(keyA, StandardUnit.COUNT, 10, 1, 17, 4)
            .toBuilder().dimensions(dimensionsA).build());
    Assert.assertEquals(items.get(1).datum, datum3);
    Assert.assertEquals(items.get(2).datum, TestHelper.constructDatum(keyA, StandardUnit.COUNT, 1, 1, 4, 4));
    Assert.assertEquals(items.get(3).datum, TestHelper.constructDatum(keyB, StandardUnit.COUNT, 100, 10, 110, 2)
            .toBuilder().dimensions(dimensionsA).build());
}
 
Example #21
Source File: PutMetricAlarm.java    From aws-doc-sdk-examples with Apache License 2.0 5 votes vote down vote up
public static void putMetricAlarm(CloudWatchClient cw, String alarmName, String instanceId) {

        try {
            Dimension dimension = Dimension.builder()
                .name("InstanceId")
                .value(instanceId).build();

            PutMetricAlarmRequest request = PutMetricAlarmRequest.builder()
                .alarmName(alarmName)
                .comparisonOperator(
                        ComparisonOperator.GREATER_THAN_THRESHOLD)
                .evaluationPeriods(1)
                .metricName("CPUUtilization")
                .namespace("AWS/EC2")
                .period(60)
                .statistic(Statistic.AVERAGE)
                .threshold(70.0)
                .actionsEnabled(false)
                .alarmDescription(
                        "Alarm when server CPU utilization exceeds 70%")
                .unit(StandardUnit.SECONDS)
                .dimensions(dimension)
                .build();

            PutMetricAlarmResponse response = cw.putMetricAlarm(request);

        } catch (CloudWatchException e) {
            System.err.println(e.awsErrorDetails().errorMessage());
            System.exit(1);
        }

       System.out.printf(
                "Successfully created alarm with name %s", alarmName);
        // snippet-end:[cloudwatch.java2.put_metric_alarm.main]
    }
 
Example #22
Source File: StreamMetricManager.java    From amazon-kinesis-scaling-utils with Apache License 2.0 5 votes vote down vote up
public StreamMetricManager(String streamName, int cloudWatchPeriod, List<KinesisOperationType> types,
		CloudWatchClient cloudWatchClient, KinesisClient kinesisClient) {
	this.streamName = streamName;
	this.trackedOperations.addAll(types);
	this.cloudWatchClient = cloudWatchClient;
	this.kinesisClient = kinesisClient;
	this.cloudWatchPeriod = cloudWatchPeriod;

	for (KinesisOperationType op : this.trackedOperations) {
		// create CloudWatch request templates for the information we have
		// at this point
		for (String metricName : op.getMetricsToFetch()) {
			GetMetricStatisticsRequest.Builder cwRequestBuilder = GetMetricStatisticsRequest.builder();

			cwRequestBuilder.namespace(CW_NAMESPACE)
					.dimensions(Dimension.builder().name("StreamName").value(this.streamName).build())
					.period(cloudWatchPeriod).statistics(Statistic.SUM).metricName(metricName);

			if (!this.cloudwatchRequestTemplates.containsKey(op)) {
				this.cloudwatchRequestTemplates.put(op, new ArrayList<GetMetricStatisticsRequest.Builder>() {
					{
						add(cwRequestBuilder);
					}
				});
			} else {
				this.cloudwatchRequestTemplates.get(op).add(cwRequestBuilder);
			}
		}
	}
}
 
Example #23
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void reportedMeterShouldContainExpectedOneMinuteMeanRateDimension() throws Exception {
    metricRegistry.meter(ARBITRARY_METER_NAME).mark(1);
    buildReportWithSleep(reporterBuilder.withOneMinuteMeanRate());

    final List<Dimension> dimensions = allDimensionsFromCapturedRequest();

    assertThat(dimensions).contains(Dimension.builder().name(DIMENSION_NAME_TYPE).value("1-min-mean-rate [per-second]").build());
}
 
Example #24
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void reportedGaugeShouldContainExpectedDimension() throws Exception {
    metricRegistry.register(ARBITRARY_GAUGE_NAME, (Gauge<Long>) () -> 1L);
    reporterBuilder.build().report();

    final List<Dimension> dimensions = firstMetricDatumDimensionsFromCapturedRequest();

    assertThat(dimensions).contains(Dimension.builder().name(DIMENSION_NAME_TYPE).value(DIMENSION_GAUGE).build());
}
 
Example #25
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void reportedCounterShouldContainExpectedDimension() throws Exception {
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    reporterBuilder.build().report();

    final List<Dimension> dimensions = firstMetricDatumDimensionsFromCapturedRequest();

    assertThat(dimensions).contains(Dimension.builder().name(DIMENSION_NAME_TYPE).value(DIMENSION_COUNT).build());
}
 
Example #26
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void shouldReportWithoutGlobalDimensionsWhenGlobalDimensionsNotConfigured() throws Exception {
    metricRegistry.counter(ARBITRARY_COUNTER_NAME).inc();
    reporterBuilder.build().report(); // When 'withGlobalDimensions' was not called

    final List<Dimension> dimensions = firstMetricDatumDimensionsFromCapturedRequest();

    assertThat(dimensions).hasSize(1);
    assertThat(dimensions).contains(Dimension.builder().name(DIMENSION_NAME_TYPE).value(DIMENSION_COUNT).build());
}
 
Example #27
Source File: DimensionedNameTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void canDecodeDimensionedString() {
  final String dimensioned = "test[key1:val1,key2:val2,key3:val3]";

  final DimensionedName dimensionedName = DimensionedName.decode(dimensioned);

  assertEquals("test", dimensionedName.getName());
  assertEquals(3, dimensionedName.getDimensions().size());

  assertThat(dimensionedName.getDimensions(), hasItems(
      Dimension.builder().name("key1").value("val1").build(),
      Dimension.builder().name("key2").value("val2").build(),
      Dimension.builder().name("key3").value("val3").build()));
}
 
Example #28
Source File: CloudWatchReporterTest.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
@Test
public void reportedMeterShouldContainExpectedFiveMinuteMeanRateDimension() throws Exception {
    metricRegistry.meter(ARBITRARY_METER_NAME).mark(1);
    buildReportWithSleep(reporterBuilder.withFiveMinuteMeanRate());

    final List<Dimension> dimensions = allDimensionsFromCapturedRequest();

    assertThat(dimensions).contains(Dimension.builder().name(DIMENSION_NAME_TYPE).value("5-min-mean-rate [per-second]").build());
}
 
Example #29
Source File: CloudWatchMeterRegistryTest.java    From micrometer with Apache License 2.0 5 votes vote down vote up
@Test
void writeShouldDropTagWithBlankValue() {
    registry.gauge("my.gauge", Tags.of("accepted", "foo").and("empty", ""), 1d);
    assertThat(registry.metricData())
            .hasSize(1)
            .allSatisfy(datum -> assertThat(datum.dimensions()).hasSize(1).contains(
                    Dimension.builder().name("accepted").value("foo").build()));
}
 
Example #30
Source File: CloudWatchReporter.java    From codahale-aggregated-metrics-cloudwatch-reporter with MIT License 5 votes vote down vote up
private void stageMetricDatumWithRawSnapshot(final boolean metricConfigured,
                                             final String metricName,
                                             final Snapshot snapshot,
                                             final StandardUnit standardUnit,
                                             final List<MetricDatum> metricData) {
    if (metricConfigured) {
        final DimensionedName dimensionedName = DimensionedName.decode(metricName);
        double total = LongStream.of(snapshot.getValues()).sum();
        final StatisticSet statisticSet =StatisticSet
                .builder()
                .sum(total)
                .sampleCount((double) snapshot.size())
                .minimum((double) snapshot.getMin())
                .maximum((double) snapshot.getMax())
                .build();

        final Set<Dimension> dimensions = new LinkedHashSet<>(builder.globalDimensions);
        dimensions.add(Dimension.builder().name(DIMENSION_NAME_TYPE).value(DIMENSION_SNAPSHOT_SUMMARY).build());
        dimensions.addAll(dimensionedName.getDimensions());

        metricData.add(MetricDatum
                .builder()
                .timestamp(Instant.ofEpochMilli(builder.clock.getTime()))
                .metricName(dimensionedName.getName())
                .dimensions(dimensions)
                .statisticValues(statisticSet)
                .storageResolution(highResolution ? HIGH_RESOLUTION : STANDARD_RESOLUTION)
                .unit(standardUnit)
                .build());
    }
}