List of usage examples for com.amazonaws.services.cloudwatch.model StandardUnit Bytes
StandardUnit Bytes
To view the source code for com.amazonaws.services.cloudwatch.model StandardUnit Bytes.
Click Source Link
From source file:com.amazon.kinesis.streaming.agent.tailing.FirehoseSender.java
License:Open Source License
@Override protected BufferSendResult<FirehoseRecord> attemptSend(RecordBuffer<FirehoseRecord> buffer) { activeBatchPutCalls.incrementAndGet(); IMetricsScope metrics = agentContext.beginScope(); metrics.addDimension(Metrics.DESTINATION_DIMENSION, "DeliveryStream:" + getDestination()); try {//from ww w .j a va 2 s .c o m BufferSendResult<FirehoseRecord> sendResult = null; List<Record> requestRecords = new ArrayList<>(); for (FirehoseRecord data : buffer) { Record record = new Record(); record.setData(data.data()); requestRecords.add(record); } PutRecordBatchRequest request = new PutRecordBatchRequest(); request.setRecords(requestRecords); request.setDeliveryStreamName(getDestination()); PutRecordBatchResult result = null; Stopwatch timer = Stopwatch.createStarted(); totalBatchPutCalls.incrementAndGet(); try { logger.trace("{}: Sending buffer {} to firehose {}...", flow.getId(), buffer, getDestination()); metrics.addCount(RECORDS_ATTEMPTED_METRIC, requestRecords.size()); result = agentContext.getFirehoseClient().putRecordBatch(request); metrics.addCount(SERVICE_ERRORS_METRIC, 0); } catch (AmazonServiceException e) { metrics.addCount(SERVICE_ERRORS_METRIC, 1); totalBatchPutServiceErrors.incrementAndGet(); throw e; } catch (Exception e) { metrics.addCount(SERVICE_ERRORS_METRIC, 1); totalBatchPutOtherErrors.incrementAndGet(); throw e; } finally { totalBatchPutLatency.addAndGet(timer.elapsed(TimeUnit.MILLISECONDS)); } if (sendResult == null) { List<Integer> sentRecords = new ArrayList<>(requestRecords.size()); Multiset<String> errors = HashMultiset.<String>create(); int index = 0; long totalBytesSent = 0; for (PutRecordBatchResponseEntry responseEntry : result.getRequestResponses()) { Record record = requestRecords.get(index); if (responseEntry.getErrorCode() == null) { sentRecords.add(index); totalBytesSent += record.getData().limit(); } else { logger.trace("{}:{} Record {} returned error code {}: {}", flow.getId(), buffer, index, responseEntry.getErrorCode(), responseEntry.getErrorMessage()); errors.add(responseEntry.getErrorCode()); } ++index; } if (sentRecords.size() == requestRecords.size()) { sendResult = BufferSendResult.succeeded(buffer); } else { buffer = buffer.remove(sentRecords); sendResult = BufferSendResult.succeeded_partially(buffer, requestRecords.size()); } metrics.addData(BYTES_SENT_METRIC, totalBytesSent, StandardUnit.Bytes); int failedRecordCount = requestRecords.size() - sentRecords.size(); metrics.addCount(RECORD_ERRORS_METRIC, failedRecordCount); logger.debug("{}:{} Records sent firehose {}: {}. Failed records: {}", flow.getId(), buffer, getDestination(), sentRecords.size(), failedRecordCount); totalRecordsAttempted.addAndGet(requestRecords.size()); totalRecordsSent.addAndGet(sentRecords.size()); totalRecordsFailed.addAndGet(failedRecordCount); if (logger.isDebugEnabled() && !errors.isEmpty()) { synchronized (totalErrors) { StringBuilder strErrors = new StringBuilder(); for (Multiset.Entry<String> err : errors.entrySet()) { AtomicLong counter = totalErrors.get(err.getElement()); if (counter == null) totalErrors.put(err.getElement(), counter = new AtomicLong()); counter.addAndGet(err.getCount()); if (strErrors.length() > 0) strErrors.append(", "); strErrors.append(err.getElement()).append(": ").append(err.getCount()); } logger.debug("{}:{} Errors from firehose {}: {}", flow.getId(), buffer, flow.getDestination(), strErrors.toString()); } } } return sendResult; } finally { metrics.commit(); activeBatchPutCalls.decrementAndGet(); } }
From source file:com.amazon.kinesis.streaming.agent.tailing.KinesisSender.java
License:Open Source License
@Override protected BufferSendResult<KinesisRecord> attemptSend(RecordBuffer<KinesisRecord> buffer) { activePutRecordsCalls.incrementAndGet(); IMetricsScope metrics = agentContext.beginScope(); metrics.addDimension(Metrics.DESTINATION_DIMENSION, "KinesisStream:" + getDestination()); try {/*from w w w.j a va 2 s . c o m*/ BufferSendResult<KinesisRecord> sendResult = null; List<PutRecordsRequestEntry> requestRecords = new ArrayList<>(); for (KinesisRecord data : buffer) { PutRecordsRequestEntry record = new PutRecordsRequestEntry(); record.setData(data.data()); record.setPartitionKey(data.partitionKey()); requestRecords.add(record); } PutRecordsRequest request = new PutRecordsRequest(); request.setStreamName(getDestination()); request.setRecords(requestRecords); PutRecordsResult result = null; Stopwatch timer = Stopwatch.createStarted(); totalPutRecordsCalls.incrementAndGet(); try { logger.trace("{}: Sending buffer {} to kinesis stream {}...", flow.getId(), buffer, getDestination()); metrics.addCount(RECORDS_ATTEMPTED_METRIC, requestRecords.size()); result = agentContext.getKinesisClient().putRecords(request); metrics.addCount(SERVICE_ERRORS_METRIC, 0); } catch (AmazonServiceException e) { metrics.addCount(SERVICE_ERRORS_METRIC, 1); totalPutRecordsServiceErrors.incrementAndGet(); throw e; } catch (Exception e) { metrics.addCount(SERVICE_ERRORS_METRIC, 1); totalPutRecordsOtherErrors.incrementAndGet(); throw e; } finally { totalPutRecordsLatency.addAndGet(timer.elapsed(TimeUnit.MILLISECONDS)); } if (sendResult == null) { List<Integer> sentRecords = new ArrayList<>(requestRecords.size()); Multiset<String> errors = HashMultiset.<String>create(); int index = 0; long totalBytesSent = 0; for (final PutRecordsResultEntry responseEntry : result.getRecords()) { final PutRecordsRequestEntry record = requestRecords.get(index); if (responseEntry.getErrorCode() == null) { sentRecords.add(index); totalBytesSent += record.getData().limit(); } else { logger.trace("{}:{} Record {} returned error code {}: {}", flow.getId(), buffer, index, responseEntry.getErrorCode(), responseEntry.getErrorMessage()); errors.add(responseEntry.getErrorCode()); } ++index; } if (sentRecords.size() == requestRecords.size()) { sendResult = BufferSendResult.succeeded(buffer); } else { buffer = buffer.remove(sentRecords); sendResult = BufferSendResult.succeeded_partially(buffer, requestRecords.size()); } metrics.addData(BYTES_SENT_METRIC, totalBytesSent, StandardUnit.Bytes); int failedRecordCount = requestRecords.size() - sentRecords.size(); metrics.addCount(RECORD_ERRORS_METRIC, failedRecordCount); logger.debug("{}:{} Records sent to kinesis stream {}: {}. Failed records: {}", flow.getId(), buffer, getDestination(), sentRecords.size(), failedRecordCount); totalRecordsAttempted.addAndGet(requestRecords.size()); totalRecordsSent.addAndGet(sentRecords.size()); totalRecordsFailed.addAndGet(failedRecordCount); if (logger.isDebugEnabled() && !errors.isEmpty()) { synchronized (totalErrors) { StringBuilder strErrors = new StringBuilder(); for (Multiset.Entry<String> err : errors.entrySet()) { AtomicLong counter = totalErrors.get(err.getElement()); if (counter == null) totalErrors.put(err.getElement(), counter = new AtomicLong()); counter.addAndGet(err.getCount()); if (strErrors.length() > 0) strErrors.append(", "); strErrors.append(err.getElement()).append(": ").append(err.getCount()); } logger.debug("{}:{} Errors from kinesis stream {}: {}", flow.getId(), buffer, flow.getDestination(), strErrors.toString()); } } } return sendResult; } finally { metrics.commit(); activePutRecordsCalls.decrementAndGet(); } }
From source file:com.github.lpezet.antiope.metrics.aws.MachineMetricFactory.java
License:Open Source License
private void addMemoryMetrics(List<MetricDatum> pTargetList, Set<MachineMetric> pCustomSet) { Runtime rt = Runtime.getRuntime(); long oTotalMem = rt.totalMemory(); long oFreeMem = rt.freeMemory(); long oUsedMem = oTotalMem - oFreeMem; long oSpareMem = rt.maxMemory() - oUsedMem; List<Long> oValues = Arrays.asList(oTotalMem, oFreeMem, oUsedMem, oSpareMem); MetricValues oMetricValues = memoryMetricValues(pCustomSet, oValues); addMetrics(pTargetList, oMetricValues, StandardUnit.Bytes); }
From source file:io.micrometer.cloudwatch.CloudWatchMeterRegistry.java
License:Apache License
private StandardUnit toStandardUnit(@Nullable String unit) { if (unit == null) { return StandardUnit.None; }/*from w w w .j a v a 2 s .c o m*/ switch (unit.toLowerCase()) { case "bytes": return StandardUnit.Bytes; case "milliseconds": return StandardUnit.Milliseconds; case "count": return StandardUnit.Count; } return StandardUnit.None; }