

# 跟踪 Amazon ECS 可用区重新平衡
<a name="track-service-rebalancing"></a>

您可以在控制台中或通过调用 `describe-services` 来验证是否为服务启用了可用区重新平衡。以下示例可用于通过 CLI 查看状态。

响应将为 `ENABLED` 或 `DISABLED`。

```
aws ecs describe-services \
    --services service-name \
    --cluster cluster-name \
    --query services[0].availabilityZoneRebalancing
```

## 服务事件
<a name="service-info-events"></a>

Amazon ECS 会发送服务操作事件，以帮助您了解可用区重新平衡生命周期。


| 事件 | 场景 | Type | 了解详情 | 
| --- | --- | --- | --- | 
| SERVICE\$1REBALANCING\$1STARTED | Amazon ECS 会启动可用区重新平衡操作 | INFO | [服务（*service-name*）未与*可用区 1* 中的 *number-tasks* 个任务、*可用区 2* 中的 *number-tasks* 个任务和*可用区 3* 中的 *number-tasks* 个任务进行可用区平衡。正在进行可用区重新平衡。](service-rebalancing-event-messages-list.md#service-rebalancing-started) | 
| SERVICE\$1REBALANCING\$1COMPLETED | 可用区重新平衡操作完成 |  INFO | [服务（*service-name*）已与*可用区 1* 中的 *number-tasks* 个任务、*可用区 2* 中的 *number-tasks* 个任务和*可用区 3* 中的 *number-tasks* 个任务进行可用区平衡。](service-rebalancing-event-messages-list.md#service-rebalancing-completed) | 
| TASKS\$1STARTED | 在可用区重新平衡操作中，Amazon ECS 成功启动任务 | INFO | [*service-name* 已在*可用区*启动 *number-tasks* 个任务进行可用区重新平衡：*task-ids*。](service-rebalancing-event-messages-list.md#service-rebalancing-tasks-started) | 
| TASKS\$1STOPPED | 在可用区重新平衡操作中，Amazon ECS 成功停止任务 | INFO | [由于可用区重新平衡，*service-name* 已停止在*可用区*中运行的 *number-tasks* 个任务：*task-id*。](service-rebalancing-event-messages-list.md#service-rebalancing-tasks-stopped) | 
| SERVICE\$1TASK\$1PLACEMENT\$1FAILURE | 在可用区重新平衡操作中，Amazon ECS 启动任务失败 | ERROR | 对于 EC2，请参阅[服务（*‬service-name*‭）无法在*可用区*中下达任务，因为没有满足所有条件的容器实例。](service-rebalancing-event-messages-list.md#service-rebalancing-placement-failure-instance) 对于 Fargate，请参阅[服务（*service-name*）无法在*可用区*中下达任务。](service-rebalancing-event-messages-list.md#service-rebalancing-placement-failure) | 
| TASKSET\$1SCALE\$1IN\$1FAILURE\$1BY\$1TASK\$1PROTECTION | 由于正在使用任务保护，可用区重新平衡操作已被阻止。 | INFO | [服务（*service-name*）无法进行可用区重新平衡，因为 *task-set-name* 由于 *reason* 无法横向缩减。](service-rebalancing-event-messages-list.md#service-rebalancing-task-protection-failure) | 
| SERVICE\$1REBALANCING\$1STOPPED | 可用区重新平衡操作停止。Amazon ECS 会发送更多事件，当中会提供更多信息。 | INFO | [服务（*service-name*）已停止可用区重新平衡。](service-rebalancing-event-messages-list.md#service-rebalancing-operation-stopped) | 

## 任务状态更改事件
<a name="task-state-change-events"></a>

Amazon ECS 会为在重新平衡过程中启动的每项任务发送一个任务状态更改事件（`START`）。

Amazon ECS 会为在重新平衡过程中停止的每项任务发送一个任务状态更改事件（`STOPPED`）。原因将设置为 `Availability-zone rebalancing initiated by (deployment ecs-svc/deployment-id)`。

有关事件的更多信息，请参阅 [Amazon ECS 任务状态更改事件](ecs_task_events.md)。