

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 目标跟踪
<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，请将每行末尾的反斜杠 (\$1) Unix 行继续符替换为脱字号 (^)。

## 设置目标跟踪
<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. 要验证可扩展目标的注册情况，请使用以下 AWS CLI 命令：

   ```
   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)`函数 where is the met `m1` rics。请务必测试您的配置，以确保其行为符合预期。有关更多选项，请参阅[使用指标数学创建目标跟踪策略](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
   ```