Java 类com.amazonaws.util.TimingInfo 实例源码

项目:spectator    文件:SpectatorRequestMetricCollectorTest.java   
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);
}
项目:ibm-cos-sdk-java    文件:ServiceLatencyProvider.java   
public double getDurationMilli() {
    if (endNano == startNano) {
        LogFactory.getLog(getClass()).debug(
                "Likely to be a missing invocation of endTiming().");
    }
    return TimingInfo.durationMilliOf(startNano, endNano); 
}
项目:ibm-cos-sdk-java    文件:RequestHandler2Adaptor.java   
@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);
}
项目:presto    文件:PrestoS3FileSystemMetricCollector.java   
@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));
    }
}
项目:spectator    文件:SpectatorRequestMetricCollector.java   
@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());
    });
  }
}
项目:ibm-cos-sdk-java    文件:RequestHandler.java   
/**
* 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);
项目:ibm-cos-sdk-java    文件:AbstractRequestHandler.java   
public void afterResponse(Request<?> request, Object response, TimingInfo timingInfo) {}