protected List<MetricDatum> metricOfCount( Field metricType, Request<?> req, Object resp) { AWSRequestMetrics m = req.getAWSRequestMetrics(); TimingInfo ti = m.getTimingInfo(); Number counter = ti.getCounter(metricType.name()); if (counter == null) { return Collections.emptyList(); } final double count = counter.doubleValue(); if (count < 1) { return Collections.emptyList(); } else { return Collections.singletonList(new MetricDatum() .withMetricName(req.getServiceName()) .withDimensions(new Dimension() .withName(Dimensions.MetricType.name()) .withValue(metricType.name())) .withUnit(StandardUnit.Count) .withValue(Double.valueOf(count)) .withTimestamp(endTimestamp(ti))) ; } }
/** * Calculate the request latency. RequestLatency = httpClientSendRequestTime + HttpClientReceiveResponseTime */ private Long calculateRequestLatency(TimingInfo timingInfo) { if (timingInfo == null) { return null; } TimingInfo httpClientSendRequestTime = timingInfo.getLastSubMeasurement(AWSRequestMetrics.Field.HttpClientSendRequestTime .name()); TimingInfo httpClientReceiveResponseTime = timingInfo.getLastSubMeasurement(AWSRequestMetrics.Field .HttpClientReceiveResponseTime.name()); if (httpClientSendRequestTime != null && httpClientSendRequestTime.getTimeTakenMillisIfKnown() != null && httpClientReceiveResponseTime != null && httpClientReceiveResponseTime.getTimeTakenMillisIfKnown() != null) { return httpClientSendRequestTime.getTimeTakenMillisIfKnown().longValue() + httpClientReceiveResponseTime.getTimeTakenMillisIfKnown().longValue(); } return null; }
/** * Returns a request type specific metrics for * {@link Field#ClientExecuteTime} which is special in the sense that it * makes a more accurate measurement by taking the {@link TimingInfo} at the * root into account. */ protected List<MetricDatum> latencyOfClientExecuteTime(Request<?> req, Object response) { AWSRequestMetrics m = req.getAWSRequestMetrics(); TimingInfo root = m.getTimingInfo(); final String metricName = Field.ClientExecuteTime.name(); if (root.isEndTimeKnown()) { // being defensive List<Dimension> dims = new ArrayList<Dimension>(); dims.add(new Dimension() .withName(Dimensions.MetricType.name()) .withValue(metricName)); // request type specific dims.add(new Dimension() .withName(Dimensions.RequestType.name()) .withValue(requestType(req))); MetricDatum datum = new MetricDatum() .withMetricName(req.getServiceName()) .withDimensions(dims) .withUnit(StandardUnit.Milliseconds) .withValue(root.getTimeTakenMillisIfKnown()); return Collections.singletonList(datum); } return Collections.emptyList(); }
@Override public void collectMetrics(Request<?> request, Response<?> response) { final AWSRequestMetrics metrics = request.getAWSRequestMetrics(); if (metrics.isEnabled()) { final Map<String, String> allTags = getAllTags(request); final TimingInfo timing = metrics.getTimingInfo(); for (Field counter : COUNTERS) { Optional.ofNullable(timing.getCounter(counter.name())) .filter(v -> v.longValue() > 0) .ifPresent(v -> registry.counter(metricId(counter, allTags)).increment(v.longValue())); } for (Field timer : TIMERS) { Optional.ofNullable(timing.getLastSubMeasurement(timer.name())) .filter(TimingInfo::isEndTimeKnown) .ifPresent(t -> registry.timer(metricId(timer, allTags)) .record(t.getEndTimeNano() - t.getStartTimeNano(), TimeUnit.NANOSECONDS)); } notEmpty(metrics.getProperty(Field.ThrottleException)).ifPresent(throttleExceptions -> { final Id throttling = metricId("throttling", allTags); throttleExceptions.forEach(ex -> registry.counter(throttling.withTag(TAG_THROTTLE_EXCEPTION, ex.getClass().getSimpleName())).increment()); }); } }
Number requestCounts = timingInfo.getCounter(RequestCount.name()); Number retryCounts = timingInfo.getCounter(HttpClientRetryCount.name()); Number throttleExceptions = timingInfo.getCounter(ThrottleException.name()); TimingInfo requestTime = timingInfo.getSubMeasurement(HttpRequestTime.name()); TimingInfo clientExecuteTime = timingInfo.getSubMeasurement(ClientExecuteTime.name());
protected List<MetricDatum> metricOfCount( Field metricType, Request<?> req, Object resp) { AWSRequestMetrics m = req.getAWSRequestMetrics(); TimingInfo ti = m.getTimingInfo(); Number counter = ti.getCounter(metricType.name()); if (counter == null) { return Collections.emptyList(); } final double count = counter.doubleValue(); if (count < 1) { return Collections.emptyList(); } else { return Collections.singletonList(new MetricDatum() .withMetricName(req.getServiceName()) .withDimensions(new Dimension() .withName(Dimensions.MetricType.name()) .withValue(metricType.name())) .withUnit(StandardUnit.Count) .withValue(Double.valueOf(count)) .withTimestamp(endTimestamp(ti))) ; } }
@Override public void collectMetrics(Request<?> request, Response<?> response) { final AWSRequestMetrics metrics = request.getAWSRequestMetrics(); if (metrics.isEnabled()) { final Map<String, String> allTags = getAllTags(request); final TimingInfo timing = metrics.getTimingInfo(); for (Field counter : COUNTERS) { Optional.ofNullable(timing.getCounter(counter.name())) .filter(v -> v.longValue() > 0) .ifPresent(v -> registry.counter(metricId(counter, allTags)).increment(v.longValue())); } for (Field timer : TIMERS) { Optional.ofNullable(timing.getLastSubMeasurement(timer.name())) .filter(TimingInfo::isEndTimeKnown) .ifPresent(t -> registry.timer(metricId(timer, allTags)) .record(t.getEndTimeNano() - t.getStartTimeNano(), TimeUnit.NANOSECONDS)); } notEmpty(metrics.getProperty(Field.ThrottleException)).ifPresent(throttleExceptions -> { final Id throttling = metricId("throttling", allTags); throttleExceptions.forEach(ex -> registry.counter(throttling.withTag(TAG_THROTTLE_EXCEPTION, ex.getClass().getSimpleName())).increment()); }); } }
private <T> T invoke(HttpMethodName httpMethodName, String resourcePath, Object representation, HttpResponseHandler<AmazonWebServiceResponse<T>> responseHandler) throws AmazonClientException { ExecutionContext executionContext = createExecutionContext(); AWSRequestMetrics awsRequestMetrics = executionContext.getAwsRequestMetrics(); awsRequestMetrics.startEvent(AWSRequestMetrics.Field.RequestMarshallTime.name()); Request request = buildRequest(httpMethodName, resourcePath, representation); awsRequestMetrics.endEvent(AWSRequestMetrics.Field.RequestMarshallTime.name()); awsRequestMetrics.startEvent(AWSRequestMetrics.Field.CredentialsRequestTime.name()); AWSCredentials credentials = awsCredentialsProvider.getCredentials(); awsRequestMetrics.endEvent(AWSRequestMetrics.Field.CredentialsRequestTime.name()); executionContext.setCredentials(credentials); awsRequestMetrics.startEvent(AWSRequestMetrics.Field.ClientExecuteTime.name()); Response<T> response = client.execute(request, responseHandler, errorResponseHandler, executionContext); awsRequestMetrics.endEvent(AWSRequestMetrics.Field.ClientExecuteTime.name()); awsRequestMetrics.log(); return response.getAwsResponse(); }
private Id metricId(Field metric, Map<String, String> tags) { return metricId(metric.name(), tags); }
private Id metricId(Field metric, Map<String, String> tags) { return metricId(metric.name(), tags); }
TagField(Field field, Function<Object, String> tagExtractor) { this.field = field; this.tagExtractor = tagExtractor; this.name = Introspector.decapitalize(field.name()); }
TagField(Field field, Function<Object, String> tagExtractor) { this.field = field; this.tagExtractor = tagExtractor; this.name = Introspector.decapitalize(field.name()); }
Long attemptLatency = null; if (timingInfo != null && timingInfo.getLastSubMeasurement(HttpRequestTime.name()) != null) { httpRequestTime = timingInfo.getLastSubMeasurement(HttpRequestTime.name()); timestamp = httpRequestTime.getStartEpochTimeMilliIfKnown(); attemptLatency = convertToLongIfNotNull(httpRequestTime.getTimeTakenMillisIfKnown());
/** * Calculate the request latency. RequestLatency = httpClientSendRequestTime + HttpClientReceiveResponseTime */ private Long calculateRequestLatency(TimingInfo timingInfo) { if (timingInfo == null) { return null; } TimingInfo httpClientSendRequestTime = timingInfo.getLastSubMeasurement(AWSRequestMetrics.Field.HttpClientSendRequestTime .name()); TimingInfo httpClientReceiveResponseTime = timingInfo.getLastSubMeasurement(AWSRequestMetrics.Field .HttpClientReceiveResponseTime.name()); if (httpClientSendRequestTime != null && httpClientSendRequestTime.getTimeTakenMillisIfKnown() != null && httpClientReceiveResponseTime != null && httpClientReceiveResponseTime.getTimeTakenMillisIfKnown() != null) { return httpClientSendRequestTime.getTimeTakenMillisIfKnown().longValue() + httpClientReceiveResponseTime.getTimeTakenMillisIfKnown().longValue(); } return null; }
Long attemptLatency = null; if (timingInfo != null && timingInfo.getLastSubMeasurement(HttpRequestTime.name()) != null) { httpRequestTime = timingInfo.getLastSubMeasurement(HttpRequestTime.name()); timestamp = httpRequestTime.getStartEpochTimeMilliIfKnown(); attemptLatency = convertToLongIfNotNull(httpRequestTime.getTimeTakenMillisIfKnown());
/** * Returns a request type specific metrics for * {@link Field#ClientExecuteTime} which is special in the sense that it * makes a more accurate measurement by taking the {@link TimingInfo} at the * root into account. */ protected List<MetricDatum> latencyOfClientExecuteTime(Request<?> req, Object response) { AWSRequestMetrics m = req.getAWSRequestMetrics(); TimingInfo root = m.getTimingInfo(); final String metricName = Field.ClientExecuteTime.name(); if (root.isEndTimeKnown()) { // being defensive List<Dimension> dims = new ArrayList<Dimension>(); dims.add(new Dimension() .withName(Dimensions.MetricType.name()) .withValue(metricName)); // request type specific dims.add(new Dimension() .withName(Dimensions.RequestType.name()) .withValue(requestType(req))); MetricDatum datum = new MetricDatum() .withMetricName(req.getServiceName()) .withDimensions(dims) .withUnit(StandardUnit.Milliseconds) .withValue(root.getTimeTakenMillisIfKnown()); return Collections.singletonList(datum); } return Collections.emptyList(); }
Number requestCounts = timingInfo.getCounter(RequestCount.name()); Number retryCounts = timingInfo.getCounter(HttpClientRetryCount.name()); Number throttleExceptions = timingInfo.getCounter(ThrottleException.name()); TimingInfo requestTime = timingInfo.getSubMeasurement(HttpRequestTime.name()); TimingInfo clientExecuteTime = timingInfo.getSubMeasurement(ClientExecuteTime.name());