private void execRequest(String endpoint, int status) { AWSRequestMetrics metrics = new AWSRequestMetricsFullSupport(); metrics.addProperty(AWSRequestMetrics.Field.ServiceName, "AmazonCloudWatch"); metrics.addProperty(AWSRequestMetrics.Field.ServiceEndpoint, endpoint); metrics.addProperty(AWSRequestMetrics.Field.StatusCode, "" + status); if (status == 503) { metrics.addProperty(AWSRequestMetrics.Field.AWSErrorCode, "Throttled"); } String counterName = "BytesProcessed"; String timerName = "ClientExecuteTime"; metrics.setCounter(counterName, 12345); metrics.getTimingInfo().addSubMeasurement(timerName, TimingInfo.unmodifiableTimingInfo(100000L, 200000L)); Request<?> req = new DefaultRequest(new ListMetricsRequest(), "AmazonCloudWatch"); req.setAWSRequestMetrics(metrics); req.setEndpoint(URI.create(endpoint)); HttpResponse hr = new HttpResponse(req, new HttpPost(endpoint)); hr.setStatusCode(status); Response<?> resp = new Response<>(null, new HttpResponse(req, new HttpPost(endpoint))); collector.collectMetrics(req, resp); }
public double getDurationMilli() { if (endNano == startNano) { LogFactory.getLog(getClass()).debug( "Likely to be a missing invocation of endTiming()."); } return TimingInfo.durationMilliOf(startNano, endNano); }
@SuppressWarnings("deprecation") @Override public void afterResponse(Request<?> request, Response<?> response) { AWSRequestMetrics awsRequestMetrics = request == null ? null : request .getAWSRequestMetrics(); Object awsResponse = response == null ? null : response .getAwsResponse(); TimingInfo timingInfo = awsRequestMetrics == null ? null : awsRequestMetrics.getTimingInfo(); old.afterResponse(request, awsResponse, timingInfo); }
@Override public void collectMetrics(Request<?> request, Response<?> response) { AWSRequestMetrics metrics = request.getAWSRequestMetrics(); TimingInfo timingInfo = metrics.getTimingInfo(); Number requestCounts = timingInfo.getCounter(Field.RequestCount.name()); Number retryCounts = timingInfo.getCounter(Field.HttpClientRetryCount.name()); Number throttleExceptions = timingInfo.getCounter(Field.ThrottleException.name()); TimingInfo requestTime = timingInfo.getSubMeasurement(Field.HttpRequestTime.name()); if (requestCounts != null) { stats.updateAwsRequestCount(requestCounts.longValue()); } if (retryCounts != null) { stats.updateAwsRetryCount(retryCounts.longValue()); } if (throttleExceptions != null) { stats.updateAwsThrottleExceptionsCount(throttleExceptions.longValue()); } if (requestTime != null && requestTime.getTimeTakenMillisIfKnown() != null) { stats.addAwsRequestTime(new Duration(requestTime.getTimeTakenMillisIfKnown(), MILLISECONDS)); } }
@Override public void collectMetrics(Request<?> request, Response<?> response) { final AWSRequestMetrics metrics = request.getAWSRequestMetrics(); if (metrics.isEnabled()) { final Map<String, String> baseTags = getBaseTags(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, baseTags)).increment(v.longValue())); } for (Field timer : TIMERS) { Optional.ofNullable(timing.getLastSubMeasurement(timer.name())) .filter(TimingInfo::isEndTimeKnown) .ifPresent(t -> registry.timer(metricId(timer, baseTags)) .record(t.getEndTimeNano() - t.getStartTimeNano(), TimeUnit.NANOSECONDS)); } notEmpty(metrics.getProperty(Field.ThrottleException)).ifPresent(throttleExceptions -> { final Id throttling = metricId("throttling", baseTags); throttleExceptions.forEach(ex -> registry.counter(throttling.withTag("throttleException", ex.getClass().getSimpleName())) .increment()); }); } }
/** * Runs any additional processing logic on the specified request (after is * has been executed by the client runtime). * * @param request * The low level request being processed. * @param response * The response generated from the specified request. * @param timingInfo * Timing information on the request's processing. */ public void afterResponse(Request<?> request, Object response, TimingInfo timingInfo);
public void afterResponse(Request<?> request, Object response, TimingInfo timingInfo) {}