List of usage examples for com.amazonaws.services.cloudwatch.model MetricDatum withDimensions
public MetricDatum withDimensions(java.util.Collection<Dimension> dimensions)
The dimensions associated with the metric.
From source file:com.github.lpezet.antiope.metrics.aws.BlockingRequestBuilder.java
License:Open Source License
private PutMetricDataRequest newPutMetricDataRequest(Collection<MetricDatum> pData, final String pNamespace, final Dimension... pExtraDims) { if (pExtraDims != null) { // Need to add some extra dimensions. // To do so, we copy the metric data to avoid mutability problems. Collection<MetricDatum> oNewData = new ArrayList<MetricDatum>(pData.size()); for (MetricDatum md : pData) { MetricDatum oNewMD = cloneMetricDatum(md); for (Dimension dim : pExtraDims) oNewMD.withDimensions(dim); // add the extra dimensions to the new metric datum oNewData.add(oNewMD);//from www . ja va 2 s . c om } pData = oNewData; } return new PutMetricDataRequest().withNamespace(pNamespace).withMetricData(pData) .withRequestMetricCollector(RequestMetricCollector.NONE); }
From source file:com.mimesis.jmx.Exporter4CloudwatchAsyncClient.java
License:Apache License
@Override public void export(Collection<Result> data) throws Exception { //TODO configure client to use POST AmazonCloudWatchAsyncClient awsClient = new AmazonCloudWatchAsyncClient(_awsCredentials); if (_region != null) { awsClient.setEndpoint(String.format("monitoring.%s.amazonaws.com", _region)); }/*from w w w . j a va 2s .c o m*/ Collection<Dimension> dimensions = parseDimensions(_dimensions); ArrayList<MetricDatum> metrics = new ArrayList<MetricDatum>(AWS_METRICS_MAX); System.out.println("send START"); int i = 0; for (Result d : data) { if (!(d.value instanceof Number)) { logger.info(String.format("CloudWatch only accept value of type Number : [%s][%s] => %s", d.objectName, d.key, String.valueOf(d.value))); continue; } MetricDatum metricDatum = new MetricDatum().withMetricName(metricNameOf(d.objectName, d.key)) .withValue(((Number) d.value).doubleValue()).withTimestamp(d.timestampDate); if (dimensions.size() > 0) { metricDatum = metricDatum.withDimensions(dimensions); } if (d.unit != null) { metricDatum = metricDatum.withUnit(d.unit); } System.out.println("send : " + (++i) + metricDatum.getMetricName()); metrics.add(metricDatum); if (metrics.size() == AWS_METRICS_MAX) { waitEndOfLastExport(); _lastFuture = awsClient.putMetricDataAsync(newPutMetricDataRequest(metrics)); metrics = new ArrayList<MetricDatum>(AWS_METRICS_MAX); } } if (metrics.size() > 0) { waitEndOfLastExport(); _lastFuture = awsClient.putMetricDataAsync(newPutMetricDataRequest(metrics)); } }
From source file:com.proofpoint.event.monitor.CloudWatchUpdater.java
License:Apache License
public void updateCloudWatch() { if (!enabled) { log.info("Skipping CloudWatch update (disabled by configuration)"); return;//from w w w.j ava 2s . c o m } MetricDatum datum = new MetricDatum().withMetricName("Heartbeat").withUnit(StandardUnit.None.toString()) .withValue(1.0d) .withDimensions(new Dimension().withName("Environment").withValue(nodeInfo.getEnvironment()), new Dimension().withName("NodeId").withValue(nodeInfo.getNodeId()), new Dimension().withName("Pool").withValue(nodeInfo.getPool()), new Dimension().withName("Location").withValue(nodeInfo.getLocation())); if (nodeInfo.getBinarySpec() != null) { datum.withDimensions(new Dimension().withName("Binary").withValue(nodeInfo.getBinarySpec())); } if (nodeInfo.getConfigSpec() != null) { datum.withDimensions(new Dimension().withName("Config").withValue(nodeInfo.getConfigSpec())); } cloudWatch.putMetricData(new PutMetricDataRequest().withNamespace("PP/Monitor").withMetricData(datum)); }
From source file:org.apache.camel.component.aws.cw.CwProducer.java
License:Apache License
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 {/*from w w w.ja va2 s. c o m*/ 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); } } }
From source file:org.apache.nifi.processors.aws.cloudwatch.PutCloudWatchMetric.java
License:Apache License
@Override public void onTrigger(ProcessContext context, ProcessSession session) throws ProcessException { FlowFile flowFile = session.get();/*from w w w .ja va 2 s . c om*/ 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); } }