Search in sources :

Example 16 with Dimension

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);
    }
}
Also used : Stat(com.nextdoor.bender.monitoring.Stat) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) ArrayList(java.util.ArrayList) MetricDatum(com.amazonaws.services.cloudwatch.model.MetricDatum) ArrayList(java.util.ArrayList) List(java.util.List) Dimension(com.amazonaws.services.cloudwatch.model.Dimension) Date(java.util.Date)

Example 17 with Dimension

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;
}
Also used : PutMetricAlarmRequest(com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest) ArrayList(java.util.ArrayList) Dimension(com.amazonaws.services.cloudwatch.model.Dimension)

Example 18 with Dimension

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);
}
Also used : PutMetricAlarmRequest(com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest) Dimension(com.amazonaws.services.cloudwatch.model.Dimension) Test(org.junit.Test)

Example 19 with Dimension

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;
}
Also used : PutMetricAlarmRequest(com.amazonaws.services.cloudwatch.model.PutMetricAlarmRequest) ArrayList(java.util.ArrayList) Dimension(com.amazonaws.services.cloudwatch.model.Dimension)

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