Search in sources :

Example 11 with Dimension

use of com.amazonaws.services.cloudwatch.model.Dimension in project jmxtrans by jmxtrans.

the class MapEntryToDimensionTest method dimensionIsCreatedFromEC2Metadata.

@Test
@Ignore("Should run on EC2 to be actually relevant")
public void dimensionIsCreatedFromEC2Metadata() {
    Dimension dimension = mapEntryToDimension.apply(ImmutableMap.of("name", (Object) "some_name", "value", (Object) "$AmiId"));
    assertThat(dimension.getName()).isEqualTo("some_name");
    assertThat(dimension.getValue()).isEqualTo("null");
}
Also used : Dimension(com.amazonaws.services.cloudwatch.model.Dimension) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with Dimension

use of com.amazonaws.services.cloudwatch.model.Dimension in project jmxtrans by jmxtrans.

the class MapEntryToDimensionTest method simpleDimensionIsCreated.

@Test
public void simpleDimensionIsCreated() {
    Dimension dimension = mapEntryToDimension.apply(ImmutableMap.of("name", (Object) "some_name", "value", (Object) "some_value"));
    assertThat(dimension.getName()).isEqualTo("some_name");
    assertThat(dimension.getValue()).isEqualTo("some_value");
}
Also used : Dimension(com.amazonaws.services.cloudwatch.model.Dimension) Test(org.junit.Test)

Example 13 with Dimension

use of com.amazonaws.services.cloudwatch.model.Dimension in project jmxtrans by jmxtrans.

the class MapEntryToDimensionTest method valueMustBeGiven.

@Test(expected = IllegalArgumentException.class)
public void valueMustBeGiven() {
    Dimension dimension = mapEntryToDimension.apply(ImmutableMap.of("name", (Object) "some_name", "no_value", (Object) "some_value"));
    assertThat(dimension.getName()).isEqualTo("some_name");
    assertThat(dimension.getValue()).isEqualTo("some_value");
}
Also used : Dimension(com.amazonaws.services.cloudwatch.model.Dimension) Test(org.junit.Test)

Example 14 with Dimension

use of com.amazonaws.services.cloudwatch.model.Dimension in project jmxtrans by jmxtrans.

the class MapEntryToDimension method apply.

@Nullable
@Override
public Dimension apply(Map<String, Object> dimension) {
    String name = null;
    String value = null;
    if (dimension == null) {
        return null;
    }
    if (dimension.containsKey(NAME)) {
        name = String.valueOf(dimension.get(NAME));
    }
    if (dimension.containsKey(VALUE)) {
        value = String.valueOf(dimension.get(VALUE));
    }
    if (name == null || value == null) {
        throw new IllegalArgumentException(format("Incomplete dimension: Missing non-null '%s' and '%s' in '%s'", NAME, VALUE, dimension.toString()));
    }
    if (value.startsWith("$")) {
        try {
            Method m = EC2MetadataUtils.class.getMethod("get" + value.substring(1));
            value = String.valueOf(m.invoke(null));
        } catch (NoSuchMethodException e) {
            log.warn("Could not resolve {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e);
        } catch (IllegalAccessException e) {
            log.warn("Could not load {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e);
        } catch (InvocationTargetException e) {
            log.warn("Could not retrieve {} via a getters on {}!", value, EC2MetadataUtils.class.getName(), e);
        }
    }
    return new Dimension().withName(name).withValue(value);
}
Also used : Method(java.lang.reflect.Method) Dimension(com.amazonaws.services.cloudwatch.model.Dimension) InvocationTargetException(java.lang.reflect.InvocationTargetException) Nullable(javax.annotation.Nullable)

Example 15 with Dimension

use of com.amazonaws.services.cloudwatch.model.Dimension in project jmxtrans by jmxtrans.

the class CloudWatchWriterTests method createCloudWatchWriter.

@Before
public void createCloudWatchWriter() {
    ImmutableList<Dimension> dimensions = ImmutableList.of(new Dimension().withName("SomeKey").withValue("SomeValue"), new Dimension().withName("InstanceId").withValue("$InstanceId"));
    writer = new CloudWatchWriter.Writer("testNS", cloudWatchClient, dimensions);
}
Also used : Dimension(com.amazonaws.services.cloudwatch.model.Dimension) Before(org.junit.Before)

Aggregations

Dimension (com.amazonaws.services.cloudwatch.model.Dimension)19 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 PutMetricAlarmRequest (com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest)5 MetricDatum (com.amazonaws.services.cloudwatch.model.MetricDatum)4 PutMetricDataRequest (com.amazonaws.services.cloudwatch.model.PutMetricDataRequest)4 AmazonCloudWatch (com.amazonaws.services.cloudwatch.AmazonCloudWatch)2 GetMetricStatisticsRequest (com.amazonaws.services.cloudwatch.model.GetMetricStatisticsRequest)2 GetMetricStatisticsResult (com.amazonaws.services.cloudwatch.model.GetMetricStatisticsResult)2 Date (java.util.Date)2 Map (java.util.Map)2 AmazonClientException (com.amazonaws.AmazonClientException)1 PutMetricAlarmResult (com.amazonaws.services.cloudwatch.model.PutMetricAlarmResult)1 PutMetricDataResult (com.amazonaws.services.cloudwatch.model.PutMetricDataResult)1 StatisticSet (com.amazonaws.services.cloudwatch.model.StatisticSet)1 Stat (com.nextdoor.bender.monitoring.Stat)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1