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");
}
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");
}
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");
}
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);
}
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);
}
Aggregations