com.amazonaws.util.AWSRequestMetrics Java Examples

The following examples show how to use com.amazonaws.util.AWSRequestMetrics. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpectatorRequestMetricCollectorTest.java    From spectator with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #2
Source File: AbstractSdkMetricsCollector.java    From presto with Apache License 2.0 5 votes vote down vote up
private static void recordSubTimingDurations(TimingInfo timingInfo, AWSRequestMetrics.Field field, Consumer<Duration> consumer)
{
    List<TimingInfo> subTimings = timingInfo.getAllSubMeasurements(field.name());
    if (subTimings != null) {
        for (TimingInfo subTiming : subTimings) {
            Double millis = subTiming.getTimeTakenMillisIfKnown();
            if (millis != null) {
                consumer.accept(new Duration(millis, MILLISECONDS));
            }
        }
    }
}
 
Example #3
Source File: SpectatorRequestMetricCollector.java    From spectator with Apache License 2.0 5 votes vote down vote up
@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());
    });
  }
}
 
Example #4
Source File: SpectatorRequestMetricCollector.java    From spectator with Apache License 2.0 5 votes vote down vote up
private static boolean isError(AWSRequestMetrics metrics) {
  for (TagField err : ERRORS) {
    if (err.getValue(metrics).isPresent()) {
      return true;
    }
  }
  return false;
}
 
Example #5
Source File: AWSRequest.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public AWSRequestMetrics getAWSRequestMetrics() {
  throw new UnsupportedOperationException("Not supported by AWSRequest");
}
 
Example #6
Source File: AWSRequest.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@Override
public void setAWSRequestMetrics(AWSRequestMetrics metrics) {
  throw new UnsupportedOperationException("Not supported by AWSRequest");
}
 
Example #7
Source File: SpectatorRequestMetricCollector.java    From spectator with Apache License 2.0 4 votes vote down vote up
Optional<String> getValue(AWSRequestMetrics metrics) {
  return firstValue(metrics.getProperty(field), tagExtractor);
}