Example usage for com.amazonaws.util AWSRequestMetrics isEnabled

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

Introduction

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

Prototype

public boolean isEnabled() 

Source Link

Document

Returns true if this metrics is enabled; false otherwise.

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   ww w  .  j  a va  2s .com

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