Example usage for com.amazonaws.util TimingInfo getLastSubMeasurement

List of usage examples for com.amazonaws.util TimingInfo getLastSubMeasurement

Introduction

In this page you can find the example usage for com.amazonaws.util TimingInfo getLastSubMeasurement.

Prototype

public TimingInfo getLastSubMeasurement(String subMeasurementName) 

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