

# 在 CloudWatch 控制台中查看 API Gateway 指标
<a name="metrics_dimensions_view_in_cloud_watch"></a>

指标的分组首先依据服务命名空间，然后依据每个命名空间内的各种维度组合。要查看 API 的方法级指标，请开启详细指标。有关更多信息，请参阅 [修改阶段设置](set-up-stages.md#how-to-stage-settings)。

**使用 CloudWatch 控制台查看 API Gateway 指标**

1. 通过以下网址打开 CloudWatch 控制台：[https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/)。

1. 如果需要，更改 AWS 区域。从导航栏中，选择 AWS 资源所在的区域。

1. 在导航窗格中，选择**指标**。

1. 在**全部指标**选项卡上，选择 **API Gateway**。

1.  要按阶段查看指标，请选择**按阶段**面板。然后，选择您的 API 和指标名称。

1. 要按特定 API 查看指标，请选择**按 Api 名称**面板。然后，选择您的 API 和指标名称。

**使用AWS CLI 查看指标**

1. 使用以下 [list-metrics](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/list-metrics.html) 命令列出指标：

   ```
   aws cloudwatch list-metrics --namespace "AWS/ApiGateway"
   ```

   创建指标后，请等待最多 15 分钟让指标显示出来。要更快地查看指标统计信息，请使用 [get-metric-data](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/update-domain-name.html) 或 [get-metric-statistics](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/update-domain-name.html)。

1. 使用以下 [get-metrics-statistics](https://docs.aws.amazon.com/cli/latest/reference/cloudwatch/get-metric-statistics.html) 命令，以 5 分钟为间隔，查看一段时间内的平均值：

   ```
   aws cloudwatch get-metric-statistics --namespace AWS/ApiGateway --metric-name Count --start-time 2011-10-03T23:00:00Z --end-time 2017-10-05T23:00:00Z --period 300 --statistics Average
   ```