Example usage for com.amazonaws.util AWSRequestMetrics getProperty

List of usage examples for com.amazonaws.util AWSRequestMetrics getProperty

Introduction

In this page you can find the example usage for com.amazonaws.util AWSRequestMetrics getProperty.

Prototype

public List<Object> getProperty(MetricType f) 

Source Link

Usage

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()));
        }//from   w w w .  jav  a2  s.  c om

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