Example usage for com.amazonaws Request getAWSRequestMetrics

List of usage examples for com.amazonaws Request getAWSRequestMetrics

Introduction

In this page you can find the example usage for com.amazonaws Request getAWSRequestMetrics.

Prototype

AWSRequestMetrics getAWSRequestMetrics();

Source Link

Document

Returns the request metrics.

Usage

From source file:com.facebook.presto.hive.PrestoS3FileSystemMetricCollector.java

License:Apache License

@Override
public void collectMetrics(Request<?> request, Response<?> response) {
    AWSRequestMetrics metrics = request.getAWSRequestMetrics();

    TimingInfo timingInfo = metrics.getTimingInfo();
    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());

    if (requestCounts != null) {
        stats.updateAwsRequestCount(requestCounts.longValue());
    }//from w  ww . j  a  va2  s .c om

    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));
    }

    if (clientExecuteTime != null && clientExecuteTime.getTimeTakenMillisIfKnown() != null) {
        stats.addAwsClientExecuteTime(
                new Duration(clientExecuteTime.getTimeTakenMillisIfKnown(), MILLISECONDS));
    }
}

From source file:com.netflix.spectator.aws.SpectatorRequestMetricCollector.java

License:Apache License

@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()));
        }//w  w  w  .ja  v a 2 s. c  o  m

        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());
        });
    }
}

From source file:com.netflix.spectator.aws.SpectatorRequestMetricCollector.java

License:Apache License

private Map<String, String> getAllTags(Request<?> request) {
    final AWSRequestMetrics metrics = request.getAWSRequestMetrics();
    final Map<String, String> allTags = new HashMap<>();
    for (TagField tag : TAGS) {
        allTags.put(tag.getName(), tag.getValue(metrics).orElse(UNKNOWN));
    }//w  ww. j  av a  2  s.  co  m
    allTags.put(TAG_REQUEST_TYPE, request.getOriginalRequest().getClass().getSimpleName());
    final boolean error = isError(metrics);
    if (error) {
        for (TagField tag : ERRORS) {
            allTags.put(tag.getName(), tag.getValue(metrics).orElse(UNKNOWN));
        }
    }
    allTags.put(TAG_ERROR, Boolean.toString(error));
    allTags.putAll(customTags);
    return Collections.unmodifiableMap(allTags);
}