

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 從 發佈 SDK 指標 AWS SDK for Java 2.x
<a name="metrics"></a>

使用 AWS SDK for Java 2.x ，您可以收集應用程式中服務用戶端和請求的指標，分析 Amazon CloudWatch Logs 中的輸出，然後對其採取行動。

根據預設，在 SDK 中會停用指標集合。本主題可協助您啟用和設定它。

## SDK 指標入門
<a name="getting-started-with-metrics"></a>

若要在您的應用程式中啟用指標收集，請根據您的使用案例選擇適當的`[MetricPublisher](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/metrics/MetricPublisher.html)`界面實作，並遵循詳細的設定指示：

**對於長時間執行的應用程式：**
+ 使用 `[CloudWatchMetricPublisher](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/metrics/publishers/cloudwatch/CloudWatchMetricPublisher.html)`
+ 如需完整的設定指示、程式碼範例和組態選項，請參閱[從長時間執行的應用程式發佈 SDK 指標](metric-pub-impl-cwmp.md)。

**對於 AWS Lambda 函數：**
+ 使用 `[EmfMetricLoggingPublisher](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/metrics/publishers/emf/EmfMetricLoggingPublisher.html)`
+ 如需完整的設定指示、相依性和 Lambda 特定組態，請參閱[發佈 AWS Lambda 函數的 SDK 指標](metric-pub-impl-emf.md)。

**針對故障診斷和主控台輸出：**
+ 使用 `[LoggingMetricPublisher](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/metrics/LoggingMetricPublisher.html)`
+ 如需設定指示、格式化選項，以及本機[開發和故障診斷的範例，請參閱將 SDK 指標輸出至主控台以進行開發和偵錯](metric-pub-impl-logging.md)。

## 快速實作預覽
<a name="quick-implementation-preview"></a>

以下是為每個使用案例啟用指標的外觀：

**長時間執行的應用程式：**

```
MetricPublisher metricsPub = CloudWatchMetricPublisher.create();
DynamoDbClient ddb = DynamoDbClient.builder()
    .overrideConfiguration(c -> c.addMetricPublisher(metricsPub))
    .build();
```

**Lambda 函數：**

```
EmfMetricLoggingPublisher emfPublisher = EmfMetricLoggingPublisher.builder()
    .namespace("MyApp")
    .build();
DynamoDbClient dynamoDb = DynamoDbClient.builder()
    .overrideConfiguration(c -> c.addMetricPublisher(emfPublisher))
    .build();
```

**開發和偵錯：**

```
MetricPublisher loggingPublisher = LoggingMetricPublisher.create();
S3Client s3 = S3Client.builder()
    .overrideConfiguration(c -> c.addMetricPublisher(loggingPublisher))
    .build();
```

## AWS CRT 型 S3 用戶端的指標限制
<a name="metrics-using-s3-crt-based-client"></a>

[AWS CRT 型 S3 用戶端](crt-based-s3-client.md)目前不支援 SDK 指標集合。 AWS CRT 型 S3 用戶端執行個體 的建置器[https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/S3CrtAsyncClientBuilder.html](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/services/s3/S3CrtAsyncClientBuilder.html)不提供設定指標發佈者的方法。

## 何時可使用指標？
<a name="when-are-metrics-available"></a>

指標通常會在適用於 Java 的 開發套件發出後 5-10 分鐘內提供。如需準確且up-to-date指標，請在從 Java 應用程式發出指標後至少 10 分鐘檢查 Cloudwatch。

## 會收集哪些資訊？
<a name="what-information-is-collected"></a>

指標集合包括下列項目：
+ API 請求的數量，包括它們是成功還是失敗
+  AWS 服務 您在 API 請求中呼叫 的相關資訊，包括傳回的例外狀況
+ 各種操作的持續時間，例如封送、簽署和 HTTP 請求
+ HTTP 用戶端指標，例如開啟的連線數量、待處理的請求數量，以及使用的 HTTP 用戶端名稱

**注意**  
可用的指標因 HTTP 用戶端而異。

如需完整清單，請參閱[服務用戶端指標](metrics-list.md)。

## 如何使用此資訊？
<a name="how-can-i-use-this-information"></a>

您可以使用 SDK 收集的指標來監控應用程式中的服務用戶端。您可以查看整體用量趨勢、識別異常、檢閱傳回的服務用戶端例外狀況，或深入了解特定問題。使用 Amazon CloudWatch Logs，您也可以建立警示，在應用程式到達您定義的條件時立即通知您。

如需詳細資訊，請參閱《[Amazon CloudWatch Logs 使用者指南》中的使用 Amazon CloudWatch Logs 指標](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/working_with_metrics.html)[和 Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/)[使用 Amazon CloudWatch Logs Amazon CloudWatch 警示](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html)。

# 使用 從長時間執行的應用程式發佈 SDK 指標 AWS SDK for Java 2.x
<a name="metric-pub-impl-cwmp"></a>

由於`[CloudWatchMetricPublisher](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/metrics/publishers/cloudwatch/CloudWatchMetricPublisher.html)`實作會彙總指標並定期延遲上傳至 Amazon CloudWatch，因此最適合長時間執行的應用程式。

指標發佈者的預設設定旨在將記憶體用量和 CloudWatch 成本降至最低，同時仍提供對指標資料的實用洞見。

## 設定
<a name="prerequisitesmetrics"></a>

您必須先完成下列步驟`CloudWatchMetricPublisher`，才能使用 啟用和使用指標。

### 步驟 1：新增必要的相依性
<a name="cwmp-set-up-deps"></a>

將專案相依性 （例如，在您的 `pom.xml`或 `build.gradle` 檔案中） 設定為使用 版本 `2.14.0` 或更新版本 適用於 Java 的 AWS SDK。

在專案的相依性中，將 artifactId `cloudwatch-metric-publisher` 包含版本編號 `2.14.0`或更新版本。

例如：

```
<project>
  <dependencyManagement>
   <dependencies>
      <dependency>
        <groupId>software.amazon.awssdk</groupId>
        <artifactId>bom</artifactId>
        <version>[2.30.11](https://central.sonatype.com/artifact/software.amazon.awssdk/bom)</version>  <!-- Navigate the link to see the latest version. -->
        <type>pom</type>
        <scope>import</scope>
      </dependency>
   </dependencies>
  </dependencyManagement>
  <dependencies>
   <dependency>
      <groupId>software.amazon.awssdk</groupId>
      <artifactId>cloudwatch-metric-publisher</artifactId>
   </dependency>
  </dependencies>
</project>
```

### 步驟 2：設定必要的許可
<a name="cwmp-set-up-perms"></a>

啟用指標發佈者使用的 IAM 身分`cloudwatch:PutMetricData`許可，以允許適用於 Java 的 SDK 寫入指標。

## 啟用特定請求的指標
<a name="enable-metrics-for-a-specific-request"></a>

下列類別說明如何為 Amazon DynamoDB 的請求啟用 CloudWatch 指標發佈者。它使用預設指標發佈者組態。

```
import software.amazon.awssdk.metrics.MetricPublisher;
import software.amazon.awssdk.metrics.publishers.cloudwatch.CloudWatchMetricPublisher;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;
import software.amazon.awssdk.services.dynamodb.model.ListTablesRequest;

public class DefaultConfigForRequest {
    // Use one MetricPublisher for your application. It can be used with requests or service clients.
    static MetricPublisher metricsPub = CloudWatchMetricPublisher.create();

    public static void main(String[] args) {
        DynamoDbClient ddb = DynamoDbClient.create();
        // Publish metrics the for ListTables operation.
        ddb.listTables(ListTablesRequest.builder()
            .overrideConfiguration(c -> c.addMetricPublisher(metricsPub))
            .build());

        // Perform more work in your application.

        // A MetricsPublisher has its own lifecycle independent of any service client or request that uses it.
        // If you no longer need the publisher, close it to free up resources.
        metricsPub.close();  // All metrics stored in memory are flushed to CloudWatch.

        // Perform more work with the DynamoDbClient instance without publishing metrics.
        // Close the service client when you no longer need it.
        ddb.close();
    }
}
```

**重要**  
確保您的應用程式`close`在服務用戶端不再使用時呼叫`[MetricPublisher](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/metrics/MetricPublisher.html)`執行個體。否則可能會導致執行緒或檔案描述項洩漏。

## 啟用特定服務用戶端的摘要指標
<a name="enable-metrics-for-a-specific-service-client"></a>

下列程式碼片段示範如何使用服務用戶端的預設設定啟用 CloudWatch 指標發佈者。

```
MetricPublisher metricsPub = CloudWatchMetricPublisher.create();

DynamoDbClient ddb = DynamoDbClient.builder()
          .overrideConfiguration(c -> c.addMetricPublisher(metricsPub))
          .build();
```

## 自訂 CloudWatch 指標發佈者
<a name="customize-metrics-publisher"></a>

下列類別示範如何為特定服務用戶端的指標發佈者設定自訂組態。自訂包括載入特定設定檔、指定指標發佈者傳送請求 AWS 的區域，以及自訂發佈者將指標傳送至 CloudWatch 的頻率。

```
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
import software.amazon.awssdk.core.metrics.CoreMetric;
import software.amazon.awssdk.metrics.MetricPublisher;
import software.amazon.awssdk.metrics.publishers.cloudwatch.CloudWatchMetricPublisher;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient;
import software.amazon.awssdk.services.dynamodb.DynamoDbClient;

import java.time.Duration;

public class CustomConfigForDDBClient {
    // Use one MetricPublisher for your application. It can be used with requests or service clients.
    static MetricPublisher metricsPub = CloudWatchMetricPublisher.builder()
        .cloudWatchClient(CloudWatchAsyncClient.builder()
            .region(Region.US_WEST_2)
            .credentialsProvider(ProfileCredentialsProvider.create("cloudwatch"))
            .build())
        .uploadFrequency(Duration.ofMinutes(5))
        .maximumCallsPerUpload(100)
        .namespace("ExampleSDKV2Metrics")
        .detailedMetrics(CoreMetric.API_CALL_DURATION)
        .build();

    public static void main(String[] args) {
        DynamoDbClient ddb = DynamoDbClient.builder()
            .overrideConfiguration(c -> c.addMetricPublisher(metricsPub))
            .build();
        // Publish metrics for DynamoDB operations.
        ddb.listTables();
        ddb.describeEndpoints();
        ddb.describeLimits();
        // Perform more work in your application.

        // A MetricsPublisher has its own lifecycle independent of any service client or request that uses it.
        // If you no longer need the publisher, close it to free up resources.
        metricsPub.close();  // All metrics stored in memory are flushed to CloudWatch.


        // Perform more work with the DynamoDbClient instance without publishing metrics.
        // Close the service client when you no longer need it.
        ddb.close();
    }
}
```

上一個程式碼片段中顯示的自訂具有下列效果。
+ `cloudWatchClient` 方法可讓您自訂用於傳送指標的 CloudWatch 用戶端。在此範例中，我們使用與 *us-east-1* 預設值不同的區域，用戶端會在其中傳送指標。我們也使用不同的具名設定檔 *cloudwatch*，其登入資料將用於驗證對 CloudWatch 的請求。這些登入資料必須具有 的許可`cloudwatch:PutMetricData`。
+ `uploadFrequency` 方法可讓您指定指標發佈者將指標上傳至 CloudWatch 的頻率。預設值為每分鐘一次。
+ `maximumCallsPerUpload` 方法會限制每次上傳進行的呼叫數量。預設值為無限制。
+ 依預設，適用於 Java 的 SDK 2.x 會在命名空間 下發佈指標。 `AwsSdk/JavaSdk2`您可以使用 `namespace`方法來指定不同的值。
+ 根據預設，軟體開發套件會發佈摘要指標。摘要指標包含平均值、最小值、最大值、總和和範例計數。透過在 `detailedMetrics`方法中指定一或多個 SDK 指標，SDK 會為每個指標發佈其他資料。此額外資料可讓您在 CloudWatch 中查詢 p90 和 p99 等百分位數統計資料。詳細指標特別適用於延遲指標，例如 `APICallDuration`，可測量 SDK 用戶端請求的end-to-end延遲。您可以使用 `[CoreMetric](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/core/metrics/CoreMetric.html)`類別的欄位來指定其他常見的 SDK 指標。

**後續步驟：**如果您也使用 Lambda 函數，請參閱[為以 EMF 為基礎的指標發佈 AWS Lambda 函數發佈 SDK](metric-pub-impl-emf.md) 指標。

# 使用 發佈 AWS Lambda 函數的 SDK 指標 AWS SDK for Java 2.x
<a name="metric-pub-impl-emf"></a>

由於 Lambda 函數通常會執行幾毫秒到幾分鐘，因此傳送指標時發生的任何延遲都會造成資料遺失`CloudWatchMetricPublisher`的風險。

`[EmfMetricLoggingPublisher](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/metrics/publishers/emf/EmfMetricLoggingPublisher.html)` 透過立即將指標寫入 [CloudWatch Embedded Metric Format (EMF)](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html) 中的結構化日誌項目，提供更合適的方法。 `EmfMetricLoggingPublisher` 可在與 Amazon CloudWatch Logs AWS Lambda 和 Amazon Elastic Container Service 等內建整合的執行環境中運作。

## 設定
<a name="metric-pub-impl-emf-set-up"></a>

您必須先完成下列步驟`EmfMetricLoggingPublisher`，才能使用 啟用和使用指標。

### 步驟 1：新增必要的相依性
<a name="metric-pub-impl-emf-set-up-deps"></a>

將專案相依性 （例如，在您的 `pom.xml`或 `build.gradle` 檔案中） 設定為使用 版本 `2.30.3` 或更新版本 適用於 Java 的 AWS SDK。

在專案的相依性中，將 artifactId `emf-metric-logging-publisher` 包含版本編號 `2.30.3`或更新版本。

例如：

```
<project>
  <dependencyManagement>
   <dependencies>
      <dependency>
        <groupId>software.amazon.awssdk</groupId>
        <artifactId>bom</artifactId>
        <version>[2.30.11](https://central.sonatype.com/artifact/software.amazon.awssdk/bom)</version>  <!-- Navigate the link to see the latest version. -->
        <type>pom</type>
        <scope>import</scope>
      </dependency>
   </dependencies>
  </dependencyManagement>
  <dependencies>
   <dependency>
      <groupId>software.amazon.awssdk</groupId>
      <artifactId>emf-metric-logging-publisher</artifactId>
   </dependency>
  </dependencies>
</project>
```

### 步驟 2：設定必要的許可
<a name="metric-pub-impl-emf-set-up-perm"></a>

啟用指標發佈者使用的 IAM 身分`logs:PutLogEvents`許可，以允許適用於 Java 的 SDK 寫入 EMF 格式的日誌。

### 步驟 3：設定記錄
<a name="metric-pub-impl-emf-set-up-logger"></a>

為了確保適當的指標收集，請將您的記錄設定為輸出至 `INFO` 層級或更低的 主控台 （例如 `DEBUG`)。在您的 `log4j2.xml` 檔案中：

```
<Loggers>
  <Root level="WARN">
   <AppenderRef ref="ConsoleAppender"/>
  </Root>
  <Logger name="software.amazon.awssdk.metrics.publishers.emf.EmfMetricLoggingPublisher" level="INFO" />
</Loggers>
```

如需如何設定`log4j2.xml`檔案的詳細資訊，請參閱本指南中的[記錄主題](logging-slf4j.md)。

## 設定和使用 `EmfMetricLoggingPublisher`
<a name="metric-pub-impl-emf-use"></a>

下列 Lambda 函數類別會先建立和設定`EmfMetricLoggingPublisher`執行個體，然後將其與 Amazon DynamoDB 服務用戶端搭配使用：

```
public class GameIdHandler implements RequestHandler<Map<String, String>, String> {
    private final EmfMetricLoggingPublisher emfPublisher;
    private final DynamoDbClient dynamoDb;

    public GameIdHandler() {
        // Build the publisher. 
        this.emfPublisher = EmfMetricLoggingPublisher.builder()
                .namespace("namespace")
                .dimensions(CoreMetric.SERVICE_ID,
                        CoreMetric.OPERATION_NAME)
                .build();
        // Add the publisher to the client.
        this.dynamoDb = DynamoDbClient.builder()
                .overrideConfiguration(c -> c.addMetricPublisher(emfPublisher))
                .region(Region.of(System.getenv("AWS_REGION")))
                .build();
    }

    @Override
    public String handleRequest(Map<String, String> event, Context context) {
        Map<String, AttributeValue> gameItem = new HashMap<>();

        gameItem.put("gameId", AttributeValue.builder().s(event.get("id")).build());

        PutItemRequest putItemRequest = PutItemRequest.builder()
                .tableName("games")
                .item(gameItem)
                .build();

        dynamoDb.putItem(putItemRequest);

        return "Request handled";
    }
}
```

DynamoDB 用戶端執行 `putItem`方法時，會自動以 EMF 格式將指標發佈至 CloudWatch 日誌串流。

### EMF 日誌事件的範例
<a name="emf-logged-output"></a>

例如，如果您將下列事件傳送至 GameHandler Lambda 函數，並設定記錄，如先前所示：

```
{
  "id": "23456"
}
```

函數處理事件後，您會找到兩個類似下列範例的日誌事件。第二個事件中的 JSON 物件包含 DynamoDB `PutItem`操作的 Java SDK 指標資料。

當 CloudWatch 收到 EMF 格式的日誌事件時，會自動剖析結構化 JSON 以擷取指標資料。然後CloudWatch 會在將原始日誌項目存放在 CloudWatch Logs 時建立對應的指標。

```
2025-07-11 15:58:30 [main] INFO  org.example.GameIdHandler:39 - Received map: {id=23456}

2025-07-11 15:58:34 [main] INFO  software.amazon.awssdk.metrics.publishers.emf.EmfMetricLoggingPublisher:43 - 
{
    "_aws": {
        "Timestamp": 1752249513975,
        "LogGroupName": "/aws/lambda/GameId",
        "CloudWatchMetrics": [
            {
                "Namespace": "namespace",
                "Dimensions": [
                    [
                        "OperationName",
                        "ServiceId"
                    ]
                ],
                "Metrics": [
                    {
                        "Name": "AvailableConcurrency"
                    },
                    {
                        "Name": "PendingConcurrencyAcquires"
                    },
                    {
                        "Name": "ServiceCallDuration",
                        "Unit": "Milliseconds"
                    },
                    {
                        "Name": "EndpointResolveDuration",
                        "Unit": "Milliseconds"
                    },
                    {
                        "Name": "MaxConcurrency"
                    },
                    {
                        "Name": "BackoffDelayDuration",
                        "Unit": "Milliseconds"
                    },
                    {
                        "Name": "MarshallingDuration",
                        "Unit": "Milliseconds"
                    },
                    {
                        "Name": "LeasedConcurrency"
                    },
                    {
                        "Name": "SigningDuration",
                        "Unit": "Milliseconds"
                    },
                    {
                        "Name": "ConcurrencyAcquireDuration",
                        "Unit": "Milliseconds"
                    },
                    {
                        "Name": "ApiCallSuccessful"
                    },
                    {
                        "Name": "RetryCount"
                    },
                    {
                        "Name": "UnmarshallingDuration",
                        "Unit": "Milliseconds"
                    },
                    {
                        "Name": "ApiCallDuration",
                        "Unit": "Milliseconds"
                    },
                    {
                        "Name": "CredentialsFetchDuration",
                        "Unit": "Milliseconds"
                    }
                ]
            }
        ]
    },
    "AvailableConcurrency": 0,
    "PendingConcurrencyAcquires": 0,
    "OperationName": "PutItem",
    "ServiceCallDuration": 1339,
    "EndpointResolveDuration": 81,
    "MaxConcurrency": 50,
    "BackoffDelayDuration": 0,
    "ServiceId": "DynamoDB",
    "MarshallingDuration": 181,
    "LeasedConcurrency": 1,
    "SigningDuration": 184,
    "ConcurrencyAcquireDuration": 83,
    "ApiCallSuccessful": 1,
    "RetryCount": 0,
    "UnmarshallingDuration": 85,
    "ApiCallDuration": 1880,
    "CredentialsFetchDuration": 138
}
```

的 [API 文件](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/metrics/publishers/emf/EmfMetricLoggingPublisher.Builder.html)`EmfMetricLoggingPublisher.Builder`會顯示您可以使用的組態選項。

您也可以為單一請求啟用 EMF 指標記錄，如 [ CloudWatchMetricPublisher 所示](metric-pub-impl-cwmp.md#enable-metrics-for-a-specific-request)。

**後續步驟：**如需長時間執行的應用程式，請參閱[從長時間執行的應用程式發佈 SDK 指標](metric-pub-impl-cwmp.md)，以進行 CloudWatch 型指標發佈。

# 使用 將 SDK 指標輸出至主控台 AWS SDK for Java 2.x
<a name="metric-pub-impl-logging"></a>

`[LoggingMetricPublisher](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/metrics/LoggingMetricPublisher.html)` 實作會將指標直接輸出至應用程式的主控台或日誌檔案。此方法非常適合用於開發、偵錯和了解 SDK 收集哪些指標，而不需要 Amazon CloudWatch 等外部服務。

與 `CloudWatchMetricPublisher`和 不同`EmfMetricLoggingPublisher`， `LoggingMetricPublisher`提供即時輸出，沒有延遲或外部相依性。這使得它非常適合本機開發和故障診斷案例。

## 何時使用 LoggingMetricPublisher
<a name="logging-metric-publisher-when-to-use"></a>

當您需要以下功能時，可使用 `LoggingMetricPublisher`：
+ 在開發期間偵錯指標集合
+ 了解 SDK 為您的操作收集哪些指標
+ 在本機對效能問題進行故障診斷
+ 沒有外部服務相依性的測試指標集合
+ 立即在主控台或日誌檔案中檢視指標

**注意**  
`LoggingMetricPublisher` 不建議用於需要持久性指標儲存和分析功能的生產環境。

## 設定指標的主控台記錄
<a name="logging-metric-publisher-setup"></a>

若要查看`LoggingMetricPublisher`輸出，請將您的記錄架構設定為顯示`INFO`關卡訊息。下列`log4j2.xml`組態可確保指標出現在主控台中：

```
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="ConsoleAppender" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="INFO">
            <AppenderRef ref="ConsoleAppender"/>
        </Root>
        <!-- Ensure LoggingMetricPublisher output appears. -->
        <Logger name="software.amazon.awssdk.metrics.LoggingMetricPublisher" level="INFO" />
    </Loggers>
</Configuration>
```

此組態會指示 SDK 在 `INFO`層級將指標輸出到您的主控台。`LoggingMetricPublisher` 記錄器組態可確保即使您的根記錄器使用更高層級的 `WARN`或 ，指標輸出也會出現`ERROR`。

## 啟用服務用戶端的主控台指標
<a name="logging-metric-publisher-basic-usage"></a>

下列範例示範如何建立 `LoggingMetricPublisher`，並將其與 Amazon Simple Storage Service 用戶端搭配使用：

```
import software.amazon.awssdk.metrics.LoggingMetricPublisher;
import software.amazon.awssdk.metrics.MetricPublisher;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;

// Create a LoggingMetricPublisher with default settings.
MetricPublisher metricPublisher = LoggingMetricPublisher.create();

// Add the publisher to your service client.
S3Client s3Client = S3Client.builder()
    .region(Region.US_EAST_1)
    .overrideConfiguration(config -> config.addMetricPublisher(metricPublisher))
    .build();

// Make requests - metrics will appear in your console.
s3Client.listBuckets();

// Clean up resources.
metricPublisher.close();
s3Client.close();
```

## 選擇指標輸出格式
<a name="logging-metric-publisher-formatting-options"></a>

`LoggingMetricPublisher` 支援兩種輸出格式：
+ **PLAIN 格式 （預設）：**將指標輸出為精簡的單行項目
+ **PRETTY 格式：**以多行、人類可讀的格式輸出指標

下列範例示範如何使用 PRETTY 格式，以便在開發期間更輕鬆地閱讀：

```
import org.slf4j.event.Level;
import software.amazon.awssdk.metrics.LoggingMetricPublisher;

// Create a LoggingMetricPublisher with PRETTY format.
MetricPublisher prettyMetricPublisher = LoggingMetricPublisher.create(
    Level.INFO, 
    LoggingMetricPublisher.Format.PRETTY
);

// Use with your service client.
S3Client s3Client = S3Client.builder()
    .region(Region.US_EAST_1)
    .overrideConfiguration(config -> config.addMetricPublisher(prettyMetricPublisher))
    .build();
```

## 完成範例
<a name="logging-metric-publisher-complete-example"></a>

下列範例`LoggingMetricPublisher`示範以兩種方式使用 ：
+ 在服務用戶端層級
+ 對於單一請求

```
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.event.Level;
import software.amazon.awssdk.metrics.LoggingMetricPublisher;
import software.amazon.awssdk.metrics.MetricPublisher;
import software.amazon.awssdk.regions.Region;
import software.amazon.awssdk.services.s3.S3Client;
import software.amazon.awssdk.services.s3.model.ListBucketsRequest;
import software.amazon.awssdk.services.s3.model.ListBucketsResponse;

/**
 * Demonstrates how to use LoggingMetricPublisher with AWS S3 SDK for Java 2.x.
 * <p>
 * This demo focuses on the S3 listBuckets operation to show how metrics are collected
 * and logged to the console for development and debugging purposes.
 * <p>
 * LoggingMetricPublisher is ideal for:
 * - Development and debugging
 * - Console output for troubleshooting
 * - Understanding what metrics are being collected
 * - Testing metric collection without external dependencies
 */
public class S3LoggingMetricPublisherDemo {

    private static final Logger logger = LoggerFactory.getLogger(S3LoggingMetricPublisherDemo.class);

    public static void main(String[] args) {
        S3LoggingMetricPublisherDemo demo = new S3LoggingMetricPublisherDemo();
        demo.demonstrateUsage();
    }

    /**
     * Demonstrates basic usage with S3Client and metrics enabled at the client level.
     */
    private void demonstrateUsage() {

        // Create a LoggingMetricPublisher with default settings. The SDK logs metrics as text in a single line.
        // The default settings are equivalent to using `LoggingMetricPublisher.Format.PLAIN`.

        MetricPublisher metricPublisher = LoggingMetricPublisher.create();

        // Create an S3 client with metrics enabled.
        try (S3Client s3Client = S3Client.builder()
                .region(Region.US_EAST_1)
                .overrideConfiguration(config -> config.addMetricPublisher(metricPublisher))
                .build()) {

            // Make the listBuckets request - metrics will be logged to console.
            ListBucketsResponse response = s3Client.listBuckets(ListBucketsRequest.builder().build());

            // The next block shows the using a different LoggingMetricPublisher with a `PRETTY` format.
            // Since the metric publisher is added to the request using the `overrideConfiguration`, this formatting
            // applies only to the one request.
            try {
                s3Client.listBuckets(ListBucketsRequest.builder()
                        .overrideConfiguration(config -> config
                                .addMetricPublisher(LoggingMetricPublisher.create(
                                        Level.INFO, LoggingMetricPublisher.Format.PRETTY)))
                        .build());
            } catch (Exception e) {
                logger.info("Request failed with metrics logged: {}", e.getMessage());
            }
            logger.info("Found {} buckets in your AWS account.", response.buckets().size());

        } catch (Exception e) {
            logger.error("Error during S3 operation: {}", e.getMessage());
            logger.info("Note: This is expected if AWS credentials are not configured.");
        }

        // Close the metric publisher to flush any remaining metrics.
        metricPublisher.close();
    }
}
```

程式碼會將下列項目記錄到 主控台：

```
INFO  LoggingMetricPublisher - Metrics published: MetricCollection(name=ApiCall, metrics=[MetricRecord(metric=MarshallingDuration, value=PT0.005409792S), MetricRecord(metric=RetryCount, value=0), MetricRecord(metric=ApiCallSuccessful, value=true), MetricRecord(metric=OperationName, value=ListBuckets), MetricRecord(metric=EndpointResolveDuration, value=PT0.000068S), MetricRecord(metric=ApiCallDuration, value=PT0.163802958S), MetricRecord(metric=CredentialsFetchDuration, value=PT0.145686542S), MetricRecord(metric=ServiceEndpoint, value=https://s3.amazonaws.com), MetricRecord(metric=ServiceId, value=S3)], children=[MetricCollection(name=ApiCallAttempt, metrics=[MetricRecord(metric=TimeToFirstByte, value=PT0.138816S), MetricRecord(metric=SigningDuration, value=PT0.007803459S), MetricRecord(metric=ReadThroughput, value=165153.96002660287), MetricRecord(metric=ServiceCallDuration, value=PT0.138816S), MetricRecord(metric=AwsExtendedRequestId, value=e13Swj3uwn0qP1Oz+m7II5OGq7jf8xxT8H18iDfRBCQmDg+gU4ek91Xrsl8XxRLROlIzCAPQtsQF0DAAWOb8ntuKCzX2AJdj), MetricRecord(metric=HttpStatusCode, value=200), MetricRecord(metric=BackoffDelayDuration, value=PT0S), MetricRecord(metric=TimeToLastByte, value=PT0.148915667S), MetricRecord(metric=AwsRequestId, value=78AW9BM7SWR6YMGB)], children=[MetricCollection(name=HttpClient, metrics=[MetricRecord(metric=MaxConcurrency, value=50), MetricRecord(metric=AvailableConcurrency, value=0), MetricRecord(metric=LeasedConcurrency, value=1), MetricRecord(metric=ConcurrencyAcquireDuration, value=PT0.002623S), MetricRecord(metric=PendingConcurrencyAcquires, value=0), MetricRecord(metric=HttpClientName, value=Apache)], children=[])])])
INFO  LoggingMetricPublisher - [4e6f2bb5] ApiCall
INFO  LoggingMetricPublisher - [4e6f2bb5] ┌──────────────────────────────────────────┐
INFO  LoggingMetricPublisher - [4e6f2bb5] │ MarshallingDuration=PT0.000063S          │
INFO  LoggingMetricPublisher - [4e6f2bb5] │ RetryCount=0                             │
INFO  LoggingMetricPublisher - [4e6f2bb5] │ ApiCallSuccessful=true                   │
INFO  LoggingMetricPublisher - [4e6f2bb5] │ OperationName=ListBuckets                │
INFO  LoggingMetricPublisher - [4e6f2bb5] │ EndpointResolveDuration=PT0.000024375S   │
INFO  LoggingMetricPublisher - [4e6f2bb5] │ ApiCallDuration=PT0.018463083S           │
INFO  LoggingMetricPublisher - [4e6f2bb5] │ CredentialsFetchDuration=PT0.000022334S  │
INFO  LoggingMetricPublisher - [4e6f2bb5] │ ServiceEndpoint=https://s3.amazonaws.com │
INFO  LoggingMetricPublisher - [4e6f2bb5] │ ServiceId=S3                             │
INFO  LoggingMetricPublisher - [4e6f2bb5] └──────────────────────────────────────────┘
INFO  LoggingMetricPublisher - [4e6f2bb5]     ApiCallAttempt
INFO  LoggingMetricPublisher - [4e6f2bb5]     ┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
INFO  LoggingMetricPublisher - [4e6f2bb5]     │ TimeToFirstByte=PT0.0165575S                                                                                          │
INFO  LoggingMetricPublisher - [4e6f2bb5]     │ SigningDuration=PT0.000301125S                                                                                        │
INFO  LoggingMetricPublisher - [4e6f2bb5]     │ ReadThroughput=1195591.792850103                                                                                      │
INFO  LoggingMetricPublisher - [4e6f2bb5]     │ ServiceCallDuration=PT0.0165575S                                                                                      │
INFO  LoggingMetricPublisher - [4e6f2bb5]     │ AwsExtendedRequestId=3QI1eenRuokdszWqZBmBMDUmko6FlSmHkM+CUMNMeLor7gJml4D4lv6QXUZ1zWoTgG+tHbr6yo2vHdz4h1P8PDovvtMFRCeB │
INFO  LoggingMetricPublisher - [4e6f2bb5]     │ HttpStatusCode=200                                                                                                    │
INFO  LoggingMetricPublisher - [4e6f2bb5]     │ BackoffDelayDuration=PT0S                                                                                             │
INFO  LoggingMetricPublisher - [4e6f2bb5]     │ TimeToLastByte=PT0.017952625S                                                                                         │
INFO  LoggingMetricPublisher - [4e6f2bb5]     │ AwsRequestId=78AVFAF795AAWAXH                                                                                         │
INFO  LoggingMetricPublisher - [4e6f2bb5]     └───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
INFO  LoggingMetricPublisher - [4e6f2bb5]         HttpClient
INFO  LoggingMetricPublisher - [4e6f2bb5]         ┌───────────────────────────────────────┐
INFO  LoggingMetricPublisher - [4e6f2bb5]         │ MaxConcurrency=50                     │
INFO  LoggingMetricPublisher - [4e6f2bb5]         │ AvailableConcurrency=0                │
INFO  LoggingMetricPublisher - [4e6f2bb5]         │ LeasedConcurrency=1                   │
INFO  LoggingMetricPublisher - [4e6f2bb5]         │ ConcurrencyAcquireDuration=PT0.00004S │
INFO  LoggingMetricPublisher - [4e6f2bb5]         │ PendingConcurrencyAcquires=0          │
INFO  LoggingMetricPublisher - [4e6f2bb5]         │ HttpClientName=Apache                 │
INFO  LoggingMetricPublisher - [4e6f2bb5]         └───────────────────────────────────────┘
INFO  S3LoggingMetricPublisherDemo - Found 6 buckets in your AWS account.
```

### 範例的其他成品
<a name="logging-metric-publisher-complete-example-artifacts"></a>

Maven `pom.xml` 檔案

```
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
         http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>s3-logging-metric-publisher-demo</artifactId>
    <version>1.0.0</version>
    <packaging>jar</packaging>

    <name>AWS S3 LoggingMetricPublisher Demo</name>
    <description>Demonstrates how to use LoggingMetricPublisher with AWS S3 SDK for Java 2.x</description>

    <properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <aws.java.sdk.version>2.31.66</aws.java.sdk.version>
        <log4j.version>2.24.3</log4j.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <!-- AWS SDK BOM for dependency management -->
            <dependency>
                <groupId>software.amazon.awssdk</groupId>
                <artifactId>bom</artifactId>
                <version>${aws.java.sdk.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <!-- Log4j BOM for logging dependency management -->
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-bom</artifactId>
                <version>${log4j.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <!-- AWS S3 SDK for demonstration -->
        <dependency>
            <groupId>software.amazon.awssdk</groupId>
            <artifactId>s3</artifactId>
        </dependency>

        <!-- Log4j2 SLF4J implementation -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j2-impl</artifactId>
        </dependency>

        <!-- Log4j2 Core -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
```

`Log4j2.xml` 組態檔案

```
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Appenders>
        <Console name="ConsoleAppender" target="SYSTEM_OUT">
            <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
        </Console>
    </Appenders>
    <Loggers>
        <Root level="INFO">
            <AppenderRef ref="ConsoleAppender"/>
        </Root>
        <!-- Ensure LoggingMetricPublisher output appears. -->
        <Logger name="software.amazon.awssdk.metrics.LoggingMetricPublisher" level="INFO"/>
    </Loggers>
</Configuration>
```

這些指標包括時間資訊、服務詳細資訊、操作名稱和 HTTP 狀態碼，可協助您了解應用程式的 AWS API 使用模式。

## 後續步驟
<a name="logging-metric-publisher-next-steps"></a>

使用 `LoggingMetricPublisher`進行開發和偵錯之後，請考慮生產環境的下列選項：
+ 對於長時間執行的應用程式，請使用 [CloudWatchMetricPublisher](metric-pub-impl-cwmp.md) 將指標傳送至 Amazon CloudWatch 進行分析和提醒
+ 對於 AWS Lambda 函數，使用 [EmfMetricLoggingPublisher](metric-pub-impl-emf.md) 以 CloudWatch Embedded Metric Format 發佈指標

# AWS SDK for Java 2.x：綜合指標參考
<a name="metrics-list"></a>

使用 AWS SDK for Java 2.x，您可以從應用程式中的服務用戶端收集指標，然後將這些指標發佈 （輸出） 至 [Amazon CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html)。

這些資料表列出您可以收集的指標，以及任何 HTTP 用戶端用量需求。

如需啟用和設定 SDK 指標的詳細資訊，請參閱[啟用 SDK 指標](metrics.md)。

## 每個請求收集的指標
<a name="metrics-perrequest"></a>


| 指標名稱 | 說明 | Type | 
| --- | --- | --- | 
|  ApiCallDuration  |  API 呼叫的持續時間。這包括所有進行的呼叫嘗試。  |  持續時間\$1  | 
|  ApiCallSuccessful  |  如果 API 呼叫成功，則為 True，否則為 false。  |  Boolean  | 
|  CredentialsFetchDuration  |  擷取 API 呼叫簽署憑證的持續時間。  |  持續時間\$1  | 
| EndpointResolveDuration | 解析 API 呼叫所用端點的持續時間。 | 持續時間\$1 | 
|  MarshallingDuration  |  將 SDK 請求封送至 HTTP 請求的持續時間。  |  持續時間\$1  | 
|  OperationName  |  要叫用之服務操作的名稱。  |  String  | 
|  RetryCount  |  開發套件在執行請求時執行的重試次數。0 表示請求第一次運作，而且未嘗試任何重試。 如需設定重試行為的詳細資訊，請參閱 [重試策略](retry-strategy.md#retry-strategies)。  |  Integer  | 
|  ServiceId  |  服務的唯一 ID。  |  String  | 
|  ServiceEndpoint  |  服務的端點。  |  URI  | 
|  TokenFetchDuration  | 擷取 API 呼叫簽署憑證的持續時間。 | 持續時間\$1 | 

\$1[java.time.Duration](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/Duration.html)。

## 每次請求嘗試收集的指標
<a name="metrics-perattempt"></a>

在收到回應之前，每個 API 呼叫可能需要多次嘗試。每次嘗試都會收集這些指標。

### 核心指標
<a name="metrics-perattempt-core"></a>


| 指標名稱 | 說明 | Type | 
| --- | --- | --- | 
|  AwsExtendedRequestId  |  服務請求的延伸請求 ID。  |  String  | 
|  AwsRequestId  |  服務請求的請求 ID。  |  String  | 
|  BackoffDelayDuration  |  開發套件在此 API 呼叫嘗試之前等待的持續時間。此值是以用戶端上的 `[https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/retries/api/BackoffStrategy.html](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/retries/api/BackoffStrategy.html)` 集為基礎。如需詳細資訊，請參閱本指南中的[重試策略](retry-strategy.md#retry-strategies)一節。  |  持續時間\$1  | 
| ErrorType |  呼叫嘗試發生的錯誤類型。 以下是可能的值： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/sdk-for-java/latest/developer-guide/metrics-list.html)  | String | 
| ReadThroughput |  用戶端的讀取輸送量，定義為 `NumberOfResponseBytesRead / (TTLB - TTFB)`。此值以每秒位元組為單位。 請注意，此指標只會測量從 `ResponseTransformer`或 中讀取的位元組`AsyncResponseTransformer`。在轉換器外部讀取的資料，例如回應串流因轉換器而傳回時，不會包含在計算中。  | Double | 
| WriteThroughput |  用戶端的寫入輸送量，定義為 `RequestBytesWritten / (LastByteWrittenTime - FirstByteWrittenTime)`。此值以每秒位元組為單位。 此指標會測量 SDK 向 HTTP 用戶端提供請求內文的速率。它不包括連線設定、TLS 交握時間和伺服器處理時間。只有具有串流內文的請求，例如 S3 PutObject，才會報告此指標。 請注意，此指標不會考慮 HTTP 用戶端層中的緩衝。如果 HTTP 用戶端在傳送之前緩衝資料，實際的網路傳輸速率可能會較低。此指標代表網路輸送量的上限。  | Double | 
|  ServiceCallDuration  |  連線到服務 （或從連線集區取得連線）、傳送序列化請求和接收初始回應 （例如 HTTP 狀態碼和標頭） 的持續時間。這不包括從服務讀取整個回應的時間。  |  持續時間\$1  | 
|  SigningDuration  |  簽署 HTTP 請求的持續時間。  |  持續時間\$1  | 
| TimeToFirstByte | 從傳送 HTTP 請求 （包括取得連線） 到 服務，以及接收回應中第一個位元組標頭的持續時間。 | 持續時間\$1 | 
| TimeToLastByte |  從傳送 HTTP 請求 （包括取得連線） 到 服務，以及接收回應最後一個位元組的持續時間。 請注意，對於傳回串流回應APIs，此指標會跨越 `ResponseTransformer`或 `AsyncResponseTransformer`完成之前的時間。  | 持續時間\$1 | 
|  UnmarshallingDuration  |  取消封送 HTTP 回應至 SDK 回應的持續時間。 注意：對於串流操作，這不包括讀取回應承載的時間。  |  持續時間\$1  | 

\$1[java.time.Duration](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/Duration.html)。

### HTTP 指標
<a name="metrics-perattempt-http"></a>


| 指標名稱 | 說明 | Type | 需要 HTTP 用戶端\$1 | 
| --- | --- | --- | --- | 
|  AvailableConcurrency  |  HTTP 用戶端支援的額外並行請求數量，無需建立與目標伺服器的新連線。 對於 HTTP/1 操作，這等於使用 服務建立的閒置 TCP 連線數。對於 HTTP/2 操作，這等於閒置串流的數量。 注意：此值因 HTTP 用戶端實作而異： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/sdk-for-java/latest/developer-guide/metrics-list.html) 此值的範圍為個別 HTTP 用戶端執行個體，並排除來自相同 JVM 中其他 HTTP 用戶端的並行。  |  Integer  | Apache、Netty、CRT | 
|  ConcurrencyAcquireDuration  |  從連線集區取得頻道的持續時間。 對於 HTTP/1 操作，頻道等於 TCP 連線。對於 HTTP/2 操作，頻道等於 HTTP/2 串流頻道。 取得新頻道可能包括下列時間： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/sdk-for-java/latest/developer-guide/metrics-list.html)  |  持續時間\$1  |  Apache、Netty、CRT  | 
|  HttpClientName  |  用於請求的 HTTP 名稱。  |  String  |  Apache、Netty、CRT  | 
|  HttpStatusCode  |  HTTP 回應的狀態碼。  |  Integer  |  任何  | 
|  LeasedConcurrency  |  HTTP 用戶端目前執行的請求數量。 對於 HTTP/1 操作，這等於與服務的作用中 TCP 連線數 （閒置連線除外）。對於 HTTP/2 操作，這等於服務作用中 HTTP 串流的數量 （閒置串流容量除外）。 注意：此值因 HTTP 用戶端實作而異： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/sdk-for-java/latest/developer-guide/metrics-list.html) 此值的範圍為個別 HTTP 用戶端執行個體，並排除來自相同 JVM 中其他 HTTP 用戶端的並行。  |  Integer  |  Apache、Netty、CRT  | 
|  LocalStreamWindowSize  |  執行此請求之串流的本機 HTTP/2 視窗大小，以位元組為單位。  |  Integer  |  Netty  | 
|  MaxConcurrency  |  HTTP 用戶端支援的並行請求數目上限。 對於 HTTP/1 操作，這等於 HTTP 用戶端可以集區的最大 TCP 連線數。對於 HTTP/2 操作，這等於 HTTP 用戶端可以集區的最大串流數量。 注意：此值因 HTTP 用戶端實作而異： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/sdk-for-java/latest/developer-guide/metrics-list.html) 此值的範圍為個別 HTTP 用戶端執行個體，並排除來自相同 JVM 中其他 HTTP 用戶端的並行。  |  Integer  |  Apache、Netty、CRT  | 
|  PendingConcurrencyAcquires  |  等待來自 HTTP 用戶端並行的請求數量。 對於 HTTP/1 操作，這等於等待 TCP 連線從連線集區建立或傳回的請求數目。對於 HTTP/2 操作，這等於從連線集區等待新串流 （可能為新的 HTTP/2 連線） 的請求數量。 注意：此值因 HTTP 用戶端實作而異： [\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/sdk-for-java/latest/developer-guide/metrics-list.html) 此值的範圍為個別 HTTP 用戶端執行個體，並排除來自相同 JVM 中其他 HTTP 用戶端的並行。  |  Integer  |  Apache、Netty、CRT  | 
|  RemoteStreamWindowSize  |  執行此請求之串流的遠端 HTTP/2 視窗大小，以位元組為單位。  |  Integer  |  Netty  | 

\$1[java.time.Duration](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/time/Duration.html)。

資料欄中使用的術語表示：
+ Apache：以 Apache 為基礎的 HTTP 用戶端 (`[ApacheHttpClient](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/apache/ApacheHttpClient.html)`)
+ Netty：以 Netty 為基礎的 HTTP 用戶端 (`[NettyNioAsyncHttpClient](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/nio/netty/NettyNioAsyncHttpClient.html)`)
+ CRT：以 AWS CRT 為基礎的 HTTP 用戶端 (`[AwsCrtAsyncHttpClient](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/crt/AwsCrtAsyncHttpClient.html)`)
+ 任何：指標資料的集合不依賴於 HTTP 用戶端；這包括 URLConnection 型 HTTP 用戶端 (`[UrlConnectionHttpClient](https://sdk.amazonaws.com/java/api/latest/software/amazon/awssdk/http/urlconnection/UrlConnectionHttpClient.html)`)