use of com.amazonaws.services.cloudwatch.model.Dimension in project camel by apache.
the class CwProducer method setDimension.
private void setDimension(MetricDatum metricDatum, Exchange exchange) {
String name = exchange.getIn().getHeader(CwConstants.METRIC_DIMENSION_NAME, String.class);
String value = exchange.getIn().getHeader(CwConstants.METRIC_DIMENSION_VALUE, String.class);
if (name != null && value != null) {
metricDatum.withDimensions(new Dimension().withName(name).withValue(value));
} else {
Map<String, String> dimensions = exchange.getIn().getHeader(CwConstants.METRIC_DIMENSIONS, Map.class);
if (dimensions != null) {
Collection<Dimension> dimensionCollection = new ArrayList<Dimension>();
for (Map.Entry<String, String> dimensionEntry : dimensions.entrySet()) {
Dimension dimension = new Dimension().withName(dimensionEntry.getKey()).withValue(dimensionEntry.getValue());
dimensionCollection.add(dimension);
}
metricDatum.withDimensions(dimensionCollection);
}
}
}
use of com.amazonaws.services.cloudwatch.model.Dimension in project camel by apache.
the class CwComponentTest method setsMeticDimensions.
@Test
public void setsMeticDimensions() throws Exception {
template.send("direct:start", ExchangePattern.InOnly, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader(CwConstants.METRIC_NAME, "errorCount");
Map<String, String> dimensionsMap = new LinkedHashMap<String, String>();
dimensionsMap.put("keyOne", "valueOne");
dimensionsMap.put("keyTwo", "valueTwo");
exchange.getIn().setHeader(CwConstants.METRIC_DIMENSIONS, dimensionsMap);
}
});
ArgumentCaptor<PutMetricDataRequest> argument = ArgumentCaptor.forClass(PutMetricDataRequest.class);
verify(cloudWatchClient).putMetricData(argument.capture());
List<Dimension> dimensions = argument.getValue().getMetricData().get(0).getDimensions();
Dimension dimension = dimensions.get(0);
assertThat(dimensions.size(), is(2));
assertEquals("keyOne", dimension.getName());
assertEquals("valueOne", dimension.getValue());
}
use of com.amazonaws.services.cloudwatch.model.Dimension in project nifi by apache.
the class PutCloudWatchMetric method onTrigger.
@Override
public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException {
FlowFile flowFile = session.get();
if (flowFile == null) {
return;
}
MetricDatum datum = new MetricDatum();
try {
datum.setMetricName(context.getProperty(METRIC_NAME).evaluateAttributeExpressions(flowFile).getValue());
final String valueString = context.getProperty(VALUE).evaluateAttributeExpressions(flowFile).getValue();
if (valueString != null) {
datum.setValue(Double.parseDouble(valueString));
} else {
StatisticSet statisticSet = new StatisticSet();
statisticSet.setMaximum(Double.parseDouble(context.getProperty(MAXIMUM).evaluateAttributeExpressions(flowFile).getValue()));
statisticSet.setMinimum(Double.parseDouble(context.getProperty(MINIMUM).evaluateAttributeExpressions(flowFile).getValue()));
statisticSet.setSampleCount(Double.parseDouble(context.getProperty(SAMPLECOUNT).evaluateAttributeExpressions(flowFile).getValue()));
statisticSet.setSum(Double.parseDouble(context.getProperty(SUM).evaluateAttributeExpressions(flowFile).getValue()));
datum.setStatisticValues(statisticSet);
}
final String timestamp = context.getProperty(TIMESTAMP).evaluateAttributeExpressions(flowFile).getValue();
if (timestamp != null) {
datum.setTimestamp(new Date(Long.parseLong(timestamp)));
}
final String unit = context.getProperty(UNIT).evaluateAttributeExpressions(flowFile).getValue();
if (unit != null) {
datum.setUnit(unit);
}
// add dynamic properties as dimensions
if (!dynamicPropertyNames.isEmpty()) {
final List<Dimension> dimensions = new ArrayList<>(dynamicPropertyNames.size());
for (String propertyName : dynamicPropertyNames) {
final String propertyValue = context.getProperty(propertyName).evaluateAttributeExpressions(flowFile).getValue();
if (StringUtils.isNotBlank(propertyValue)) {
dimensions.add(new Dimension().withName(propertyName).withValue(propertyValue));
}
}
datum.withDimensions(dimensions);
}
final PutMetricDataRequest metricDataRequest = new PutMetricDataRequest().withNamespace(context.getProperty(NAMESPACE).evaluateAttributeExpressions(flowFile).getValue()).withMetricData(datum);
putMetricData(metricDataRequest);
session.transfer(flowFile, REL_SUCCESS);
getLogger().info("Successfully published cloudwatch metric for {}", new Object[] { flowFile });
} catch (final Exception e) {
getLogger().error("Failed to publish cloudwatch metric for {} due to {}", new Object[] { flowFile, e });
flowFile = session.penalize(flowFile);
session.transfer(flowFile, REL_FAILURE);
}
}
use of com.amazonaws.services.cloudwatch.model.Dimension in project nifi by apache.
the class TestPutCloudWatchMetric method testDimensions.
@Test
public void testDimensions() throws Exception {
MockPutCloudWatchMetric mockPutCloudWatchMetric = new MockPutCloudWatchMetric();
final TestRunner runner = TestRunners.newTestRunner(mockPutCloudWatchMetric);
runner.setProperty(PutCloudWatchMetric.NAMESPACE, "TestNamespace");
runner.setProperty(PutCloudWatchMetric.METRIC_NAME, "TestMetric");
runner.setProperty(PutCloudWatchMetric.VALUE, "1.0");
runner.setProperty(PutCloudWatchMetric.UNIT, "Count");
runner.setProperty(PutCloudWatchMetric.TIMESTAMP, "1476296132575");
runner.setProperty(new PropertyDescriptor.Builder().dynamic(true).name("dim1").build(), "${metric.dim1}");
runner.setProperty(new PropertyDescriptor.Builder().dynamic(true).name("dim2").build(), "val2");
runner.assertValid();
final Map<String, String> attributes = new HashMap<>();
attributes.put("metric.dim1", "1");
runner.enqueue(new byte[] {}, attributes);
runner.run();
runner.assertAllFlowFilesTransferred(PutCloudWatchMetric.REL_SUCCESS, 1);
Assert.assertEquals(1, mockPutCloudWatchMetric.putMetricDataCallCount);
Assert.assertEquals("TestNamespace", mockPutCloudWatchMetric.actualNamespace);
MetricDatum datum = mockPutCloudWatchMetric.actualMetricData.get(0);
Assert.assertEquals("TestMetric", datum.getMetricName());
Assert.assertEquals(1d, datum.getValue(), 0.0001d);
List<Dimension> dimensions = datum.getDimensions();
Collections.sort(dimensions, (d1, d2) -> d1.getName().compareTo(d2.getName()));
Assert.assertEquals(2, dimensions.size());
Assert.assertEquals("dim1", dimensions.get(0).getName());
Assert.assertEquals("1", dimensions.get(0).getValue());
Assert.assertEquals("dim2", dimensions.get(1).getName());
Assert.assertEquals("val2", dimensions.get(1).getValue());
}
use of com.amazonaws.services.cloudwatch.model.Dimension in project Synapse-Stack-Builder by Sage-Bionetworks.
the class RdsAlarmSetup method createDefaultPutMetricRequest.
/**
* @param instances
* @param topicArn
* @param alarmRequest
*/
static PutMetricAlarmRequest createDefaultPutMetricRequest(DBInstance instances, String topicArn) {
PutMetricAlarmRequest alarmRequest = new PutMetricAlarmRequest();
alarmRequest.setAlarmDescription("Setup by: " + RdsAlarmSetup.class.getName());
alarmRequest.setActionsEnabled(true);
alarmRequest.withAlarmActions(topicArn);
alarmRequest.setNamespace(NAME_SPACES_AWS_RDS);
alarmRequest.withDimensions(new Dimension().withName(DB_INSTANCE_IDENTIFIER).withValue(instances.getDBInstanceIdentifier()));
return alarmRequest;
}
Aggregations