

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

# 在 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. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 如有需要，請變更 AWS 區域。從導覽列中，選取 AWS 資源所在的區域。

1. 在導覽窗格中，選擇 **指標**。

1. 在 **All Metrics (所有指標)** 標籤中，選擇 **API Gateway**。

1.  若要依階段檢視指標，請選擇 **By Stage (依階段)** 面板。然後，選取您的 API 和指標名稱。

1. 若要依特定 API 檢視指標，請選擇 **By Api Name (依 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
   ```