Class MetricUtils


  • public final class MetricUtils
    extends Object
    Utility methods for working with metrics.
    • Method Detail

      • measureDuration

        public static <T> software.amazon.awssdk.utils.Pair<T,​Duration> measureDuration​(Supplier<T> c)
        Measure the duration of the given callable.
        Parameters:
        c - The callable to measure.
        Returns:
        A Pair containing the result of c and the duration.
      • reportDuration

        public static <T> CompletableFuture<T> reportDuration​(Supplier<CompletableFuture<T>> c,
                                                              software.amazon.awssdk.metrics.MetricCollector metricCollector,
                                                              software.amazon.awssdk.metrics.SdkMetric<Duration> metric)
        Report a duration metric of the given CompletableFuture supplier.
        Parameters:
        c - The callable to measure.
        metricCollector - The MetricCollector where the metric is to be reported.
        metric - The metric to be reported.
        Returns:
        A Pair containing the result of c and the duration.
      • measureDurationUnsafe

        public static <T> software.amazon.awssdk.utils.Pair<T,​Duration> measureDurationUnsafe​(Callable<T> c)
                                                                                             throws Exception
        Measure the duration of the given callable.
        Parameters:
        c - The callable to measure.
        Returns:
        A Pair containing the result of c and the duration.
        Throws:
        Exception
      • measureDurationUnsafe

        public static <T> software.amazon.awssdk.utils.Pair<T,​Duration> measureDurationUnsafe​(Callable<T> c,
                                                                                                    long startTime)
                                                                                             throws Exception
        Measure the duration of the given callable, using the provided time as the basis.
        Throws:
        Exception
      • collectServiceEndpointMetrics

        public static void collectServiceEndpointMetrics​(software.amazon.awssdk.metrics.MetricCollector metricCollector,
                                                         software.amazon.awssdk.http.SdkHttpFullRequest httpRequest)
        Collect the SERVICE_ENDPOINT metric for this request.
      • collectHttpMetrics

        public static void collectHttpMetrics​(software.amazon.awssdk.metrics.MetricCollector metricCollector,
                                              software.amazon.awssdk.http.SdkHttpFullResponse httpResponse)
      • createAttemptMetricsCollector

        public static software.amazon.awssdk.metrics.MetricCollector createAttemptMetricsCollector​(RequestExecutionContext context)
      • createHttpMetricsCollector

        public static software.amazon.awssdk.metrics.MetricCollector createHttpMetricsCollector​(RequestExecutionContext context)
      • resetApiCallAttemptStartNanoTime

        public static long resetApiCallAttemptStartNanoTime​(RequestExecutionContext context)
      • bytesPerSec

        public static double bytesPerSec​(long totalBytes,
                                         long nanoStart,
                                         long nanoEnd)