use of com.amazonaws.services.cloudwatch.model.Dimension in project bender by Nextdoor.
the class CloudwatchReporter method write.
@Override
public void write(ArrayList<Stat> stats, long invokeTimeMs, Set<Tag> tags) {
Date dt = new Date();
dt.setTime(invokeTimeMs);
Collection<Dimension> parentDims = tagsToDimensions(tags);
List<MetricDatum> metrics = new ArrayList<MetricDatum>();
/*
* Create CW metric objects from bender internal Stat objects
*/
for (Stat stat : stats) {
/*
* Dimension are CW's version of metric tags. A conversion must be done.
*/
Collection<Dimension> metricDims = tagsToDimensions(stat.getTags());
metricDims.addAll(parentDims);
MetricDatum metric = new MetricDatum();
metric.setMetricName(stat.getName());
// TODO: add units to Stat object SYSTEMS-870
metric.setUnit(StandardUnit.None);
metric.setTimestamp(dt);
metric.setDimensions(metricDims);
metric.setValue((double) stat.getValue());
metrics.add(metric);
}
/*
* Not very well documented in java docs but CW only allows 20 metrics at a time.
*/
List<List<MetricDatum>> chunks = ListUtils.partition(metrics, 20);
for (List<MetricDatum> chunk : chunks) {
PutMetricDataRequest req = new PutMetricDataRequest();
req.withMetricData(chunk);
req.setNamespace(namespace);
this.client.putMetricData(req);
}
}
use of com.amazonaws.services.cloudwatch.model.Dimension in project Synapse-Stack-Builder by Sage-Bionetworks.
the class ElbAlarmTestHelper method getExpectedBasePutMetricAlarmRequest.
public static PutMetricAlarmRequest getExpectedBasePutMetricAlarmRequest() {
final String expectedDesc = "Setup by Stack Builder: " + ElbAlarmSetup.class.getName();
final boolean expectedActionsEnabled = true;
final Collection<String> expectedAlarmActions = new ArrayList<String>();
expectedAlarmActions.add("topicArn");
final String expectedNameSpace = NAMESPACE_ELB;
Dimension expectedDimension = new Dimension().withName(DIMENSION_NAME_LOAD_BALANCER).withValue("loadBalancer");
Collection<Dimension> expectedDimensions = new ArrayList<Dimension>();
expectedDimensions.add(expectedDimension);
PutMetricAlarmRequest expectedReq = new PutMetricAlarmRequest();
expectedReq.setAlarmDescription(expectedDesc);
expectedReq.setActionsEnabled(expectedActionsEnabled);
expectedReq.setAlarmActions(expectedAlarmActions);
expectedReq.setNamespace(expectedNameSpace);
expectedReq.setDimensions(expectedDimensions);
return expectedReq;
}
use of com.amazonaws.services.cloudwatch.model.Dimension in project Synapse-Stack-Builder by Sage-Bionetworks.
the class RdsAlarmSetupTest method testCreateDefaultPutMetricRequest.
@Test
public void testCreateDefaultPutMetricRequest() {
PutMetricAlarmRequest expected = new PutMetricAlarmRequest();
expected.setAlarmDescription("Setup by: " + RdsAlarmSetup.class.getName());
expected.setActionsEnabled(true);
expected.withAlarmActions(topicArn);
expected.setNamespace(NAME_SPACES_AWS_RDS);
expected.withDimensions(new Dimension().withName(DB_INSTANCE_IDENTIFIER).withValue(databaseIdentifer));
PutMetricAlarmRequest result = RdsAlarmSetup.createDefaultPutMetricRequest(dbInstance, topicArn);
assertEquals(expected, result);
}
use of com.amazonaws.services.cloudwatch.model.Dimension in project Synapse-Stack-Builder by Sage-Bionetworks.
the class ElbAlarmSetup method createDefaultPutMetricAlarmRequest.
public static PutMetricAlarmRequest createDefaultPutMetricAlarmRequest(String loadBalancerName, String topicArn) {
if (loadBalancerName == null)
throw new IllegalArgumentException("Load balancer name cannot be null");
if (topicArn == null)
throw new IllegalArgumentException("Topic ARN cannot be null");
PutMetricAlarmRequest alarmRequest = new PutMetricAlarmRequest();
alarmRequest.setAlarmDescription("Setup by Stack Builder: " + ElbAlarmSetup.class.getName());
alarmRequest.setActionsEnabled(true);
alarmRequest.withAlarmActions(topicArn);
alarmRequest.setNamespace(NAMESPACE_ELB);
Collection<Dimension> dimensions = new ArrayList<Dimension>();
dimensions.add(new Dimension().withName(DIMENSION_NAME_LOAD_BALANCER).withValue(loadBalancerName));
alarmRequest.setDimensions(dimensions);
alarmRequest.withDimensions();
return alarmRequest;
}
Aggregations