List of usage examples for com.amazonaws.services.cloudwatch.model PutMetricDataRequest setMetricData
public void setMetricData(java.util.Collection<MetricDatum> metricData)
The data for the metric.
From source file:com.amazon.kinesis.streaming.agent.metrics.DefaultCWMetricsPublisher.java
License:Open Source License
@Override public void publishMetrics(List<MetricDatumWithKey<CWMetricKey>> dataToPublish) { for (int startIndex = 0; startIndex < dataToPublish.size(); startIndex += BATCH_SIZE) { int endIndex = Math.min(dataToPublish.size(), startIndex + BATCH_SIZE); PutMetricDataRequest request = new PutMetricDataRequest(); request.setNamespace(namespace); List<MetricDatum> metricData = new ArrayList<MetricDatum>(); for (int i = startIndex; i < endIndex; i++) { MetricDatum metric = dataToPublish.get(i).datum; if (!metric.getMetricName().startsWith(".")) metricData.add(dataToPublish.get(i).datum); }/*from ww w . j a va2 s . c o m*/ if (metricData.isEmpty()) return; request.setMetricData(metricData); try { cloudWatchClient.putMetricData(request); LOG.info(String.format("Successfully published %d datums.", endIndex - startIndex)); } catch (AmazonClientException e) { LOG.warn(String.format("Could not publish %d datums to CloudWatch", endIndex - startIndex), e); } } }
From source file:com.basistech.metrics.CloudWatchReporter.java
License:Open Source License
@Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { Collection<MetricDatum> data = new ArrayList<>(); for (Map.Entry<String, Gauge> meg : gauges.entrySet()) { if (meg.getValue().getValue() instanceof Number) { Number num = (Number) meg.getValue().getValue(); double val = num.doubleValue(); if (LOG.isDebugEnabled()) { LOG.debug("gauge {} val {}", meg.getKey(), val); }//from w w w .j av a 2 s . c o m data.add(new MetricDatum().withMetricName(meg.getKey()).withValue(val).withDimensions(dimensions)); } } for (Map.Entry<String, Counter> mec : counters.entrySet()) { if (LOG.isDebugEnabled()) { LOG.debug("counter {} val {}", mec.getKey(), mec.getValue().getCount()); } data.add(new MetricDatum().withMetricName(mec.getKey()).withValue((double) mec.getValue().getCount()) .withDimensions(dimensions)); } for (Map.Entry<String, Histogram> meh : histograms.entrySet()) { reportHistogram(data, meh); } for (Map.Entry<String, Timer> met : timers.entrySet()) { reportTimer(met.getKey(), data, met); } if (!data.isEmpty()) { PutMetricDataRequest put = new PutMetricDataRequest(); put.setNamespace(namespace); put.setMetricData(data); try { client.putMetricData(put); } catch (Throwable t) { LOG.error("Failed to put metrics", t); } } }
From source file:com.mulesoft.agent.monitoring.publisher.CloudwatchMonitorPublisher.java
License:Open Source License
@Override public boolean flush(@NotNull Collection<List<Metric>> listOfMetrics) { AWSCredentials credentials = new BasicAWSCredentials(accessKey, secretKey); AmazonCloudWatchAsyncClient cloudWatchClient = new AmazonCloudWatchAsyncClient(credentials); for (List<Metric> metrics : listOfMetrics) { List<MetricDatum> cloudWatchMetrics = transformMetrics(metrics); PutMetricDataRequest putMetricDataRequest = new PutMetricDataRequest(); putMetricDataRequest.setMetricData(cloudWatchMetrics); putMetricDataRequest.setNamespace(namespace); cloudWatchClient.putMetricData(putMetricDataRequest); }// w w w . j av a 2s . co m return true; }
From source file:com.netflix.bdp.s3mper.alert.impl.CloudWatchAlertDispatcher.java
License:Apache License
private void sendCloudWatchConsistencyAlert() { MetricDatum datum = new MetricDatum(); datum.setMetricName(cloudWatchConsistencyMetric); datum.setUnit(StandardUnit.Count);/* w w w .ja v a 2 s .co m*/ datum.setValue(1.0); PutMetricDataRequest request = new PutMetricDataRequest(); request.setNamespace(namespace); request.setMetricData(Collections.singleton(datum)); cloudWatch.putMetricData(request); }
From source file:com.netflix.bdp.s3mper.alert.impl.CloudWatchAlertDispatcher.java
License:Apache License
private void sendCloudWatchTimeoutAlert() { MetricDatum datum = new MetricDatum(); datum.setMetricName(cloudWatchTimeoutMetric); datum.setUnit(StandardUnit.Count);/* ww w . ja va2 s . c om*/ datum.setValue(1.0); PutMetricDataRequest request = new PutMetricDataRequest(); request.setNamespace(namespace); request.setMetricData(Collections.singleton(datum)); cloudWatch.putMetricData(request); }
From source file:com.pinterest.arcee.autoscaling.AwsAlarmManager.java
License:Apache License
private void sendMetricsInternal(Collection<MetricDatum> metricData, String groupName) throws Exception { PutMetricDataRequest request = new PutMetricDataRequest(); request.setMetricData(metricData); request.setNamespace(getNameSpace(groupName)); Exception lastException = null; for (int retry = 0; retry < TOTAL_RETRY; retry++) { try {// ww w . j a v a 2 s . c o m acwClient.putMetricData(request); return; } catch (InternalServiceException e) { lastException = e; LOG.error("Failed to put metrics to aws: ", e); } } throw lastException; }