

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

# 目標追蹤
<a name="targettracking"></a>

透過目標追蹤，您可以根據用量調整端點佈建以符合容量需求。推論單位數量會自動調整，以便使用容量落在佈建容量的目標百分比內。您可以使用目標追蹤來因應文件分類端點和實體辨識器端點的暫時使用激增。如需詳細資訊，請參閱 [Application Auto Scaling 的目標追蹤擴展政策](https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-target-tracking.html)。

**注意**  
下列範例已針對 Unix、Linux 和 macOS 格式化。用於 Windows 時，請以插入號 (^) 取代每一行結尾處的 Unix 接續字元斜線 (\$1)。

## 設定目標追蹤
<a name="setup-target-tracking"></a>

若要設定端點的目標追蹤，您可以使用 AWS CLI 命令來註冊可擴展的目標，然後建立擴展政策。可擴展目標將推論單位定義為用來調整端點佈建的資源，而擴展政策則定義控制佈建容量自動擴展的指標。

**設定目標追蹤**

1. 登錄可擴展的目標。下列範例會註冊可擴展的目標，以調整端點佈建，最小容量為 1 個推論單位，最大容量為 2 個推論單位。

   對於文件分類端點，請使用下列 AWS CLI 命令：

   ```
   aws application-autoscaling register-scalable-target \
       --service-namespace comprehend \
       --resource-id arn:aws:comprehend:region:account-id:document-classifier-endpoint/name \
       --scalable-dimension comprehend:document-classifier-endpoint:DesiredInferenceUnits \
       --min-capacity 1 \
       --max-capacity 2
   ```

   對於實體辨識器端點，請使用下列 AWS CLI 命令：

   ```
   aws application-autoscaling register-scalable-target \
       --service-namespace comprehend \
       --resource-id arn:aws:comprehend:region:account-id:entity-recognizer-endpoint/name \
       --scalable-dimension comprehend:entity-recognizer-endpoint:DesiredInferenceUnits \
       --min-capacity 1 \
       --max-capacity 2
   ```

1. 若要驗證可擴展目標的註冊，請使用下列 CLI AWS 命令：

   ```
   aws application-autoscaling describe-scalable-targets \
       --service-namespace comprehend \
       --resource-id endpoint ARN
   ```

1. 建立擴展政策的目標追蹤組態，並將組態儲存在名為 的檔案中`config.json`。以下是文件分類端點的目標追蹤組態範例，該端點將 InferenceUtilization 指標保持在 70%。

   ```
   {
     "TargetValue": 70,
     "CustomizedMetricSpecification": {
       "MetricName": "InferenceUtilization",
       "Namespace": "MyNamespace",
       "Dimensions": [
         {
           "Name": "EndpointArn",
           "Value": "arn:aws:comprehend:region:account-id:document-classifier-endpoint/name"
         }
       ],
       "Statistic": "Sum",
       "Unit": "Percent"
     }
   }
   ```

   以下是實體辨識器端點的範例：

   ```
   {
     "TargetValue": 70,
     "CustomizedMetricSpecification": {
       "MetricName": "InferenceUtilization",
       "Namespace": "MyNamespace",
       "Dimensions": [
         {
           "Name": "EndpointArn",
           "Value": "arn:aws:comprehend:region:account-id:entity-recognizer-endpoint/name"
         }
       ],
       "Statistic": "Sum",
       "Unit": "Percent"
     }
   }
   ```

1. 建立擴展政策。下列範例會根據 `config.json` 檔案中定義的目標追蹤組態來建立擴展政策。

   對於文件分類端點，請使用下列 AWS CLI 命令：

   ```
   aws application-autoscaling put-scaling-policy \
       --service-namespace comprehend \
       --resource-id arn:aws:comprehend:region:account-id:document-classifier-endpoint/name \
       --scalable-dimension comprehend:document-classifier-endpoint:DesiredInferenceUnits \
       --policy-name TestPolicy \
       --policy-type TargetTrackingScaling \
       --target-tracking-scaling-policy-configuration file://config.json
   ```

   對於實體辨識器端點，請使用下列 AWS CLI 命令：

   ```
   aws application-autoscaling put-scaling-policy \
       --service-namespace comprehend \
       --resource-id arn:aws:comprehend:region:account-id:entity-recognizer-endpoint/name \
       --scalable-dimension comprehend:entity-recognizer-endpoint:DesiredInferenceUnits \
       --policy-name TestPolicy \
       --policy-type TargetTrackingScaling \
       --target-tracking-scaling-policy-configuration file://config.json
   ```

## 考量事項
<a name="considerations"></a>

搭配 Comprehend 端點使用目標追蹤時，適用下列考量：
+ 只會針對成功的請求發出端點指標。對於因內部伺服器錯誤或客戶錯誤而調節或失敗的請求，不會顯示指標。
+ 當資料點遺失時，備份 CloudWatch 警示狀態會變更為 `INSUFFICIENT_DATA `。發生這種情況時，Application Auto Scaling 無法擴展您的端點。
+ 指標數學有助於解決此限制。例如，若要在沒有回報指標時使用 0 的值，請使用 `FILL(m1,0)`函數，其中 `m1`是指標。請務必測試您的組態，以確保其如預期般運作。如需進一步選項，請參閱[使用指標數學建立目標追蹤政策](https://docs.aws.amazon.com/autoscaling/application/userguide/application-auto-scaling-target-tracking-metric-math.html)。

## 移除目標追蹤
<a name="remove-target-tracking"></a>

若要移除端點的目標追蹤，您可以使用 AWS CLI 命令刪除擴展政策，然後取消註冊可擴展的目標。

**移除目標追蹤**

1. 刪除擴展政策。下列範例會刪除指定的擴展政策。

   對於文件分類端點，請使用下列 AWS CLI 命令：

   ```
   aws application-autoscaling delete-scaling-policy \
       --service-namespace comprehend \
       --resource-id arn:aws:comprehend:region:account-id:document-classifier-endpoint/name \
       --scalable-dimension comprehend:document-classifier-endpoint:DesiredInferenceUnits \
       --policy-name TestPolicy \
   ```

   對於實體辨識器端點，請使用下列 AWS CLI 命令：

   ```
   aws application-autoscaling delete-scaling-policy \
       --service-namespace comprehend \
       --resource-id arn:aws:comprehend:region:account-id:entity-recognizer-endpoint/name \
       --scalable-dimension comprehend:entity-recognizer-endpoint:DesiredInferenceUnits \
       --policy-name TestPolicy
   ```

1. 取消註冊可擴展的目標。下列範例會取消註冊指定的可擴展目標。

   對於文件分類端點，請使用下列 AWS CLI 命令：

   ```
   aws application-autoscaling deregister-scalable-target \
       --service-namespace comprehend \
       --resource-id arn:aws:comprehend:region:account-id:document-classifier-endpoint/name \
       --scalable-dimension comprehend:document-classifier-endpoint:DesiredInferenceUnits
   ```

   對於實體辨識器端點，請使用下列 AWS CLI 命令：

   ```
   aws application-autoscaling deregister-scalable-target \
       --service-namespace comprehend \
       --resource-id arn:aws:comprehend:region:account-id:entity-recognizer-endpoint/name \
       --scalable-dimension comprehend:entity-recognizer-endpoint:DesiredInferenceUnits
   ```