

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

# 基礎設施監控
<a name="CloudWatch-Insights-Sections"></a>

本節中的主題介紹了 CloudWatch 功能，有助您取得對 AWS 資源的操作可見性。

**Topics**
+ [Container Insights](ContainerInsights.md)
+ [Lambda Insights](Lambda-Insights.md)
+ [CloudWatch Database Insights](Database-Insights.md)
+ [使用 Contributor Insights 來分析高基數資料](ContributorInsights.md)
+ [偵測常見的 CloudWatch Application Insights 應用程式問題](cloudwatch-application-insights.md)
+ [在 CloudWatch 主控台中使用資源運作狀態檢視](servicelens_resource_health.md)

# Container Insights
<a name="ContainerInsights"></a>

使用 CloudWatch Container Insights 來收集、彙整和摘要您容器化應用程式及微服務中的指標及日誌。Container Insights 適用於 Amazon EC2 上的 Amazon Elastic Container Service (Amazon ECS)、Amazon Elastic Kubernetes Service (Amazon EKS)、RedHat OpenShift on AWS (ROSA) 和 Kubernetes 平台Amazon EC2。Container Insights 支援從針對 Amazon ECS 和 Amazon EKS 部署 AWS Fargate 在 上的叢集收集指標。

CloudWatch 會自動收集 CPU、記憶體、磁碟和網路等許多資源的指標。Container Insights 還提供診斷資訊，例如容器重新啟動故障，協助您快速隔離和解決這些故障。您也可以為 Container Insights 收集的指標設定 CloudWatch 警示。

Container Insights 會使用[內嵌指標格式](CloudWatch_Embedded_Metric_Format.md)將資料收集為*效能日誌事件*。這些效能日誌事件是使用結構化的 JSON 結構描述的項目，而該結構描述可擷取高基數資料並大量地進行存放。CloudWatch 可透過這些資料，在叢集、節點、Pod、任務和服務層級建立彙整指標，作為 CloudWatch 指標。您可在 CloudWatch 自動儀表板取得 Container Insights 收集的指標，也可在 CloudWatch 主控台的**指標**區段進行檢視。指標要在容器任務執行一段時間後才會顯示。

當您部署 Container Insights 時，它會自動建立效能日誌事件的日誌群組。您不需要自行建立此日誌群組。

為協助您管理 Container Insights 成本，CloudWatch 不會自動從日誌資料建立所有可能的指標。不過，您可以使用 CloudWatch Logs Insights 來分析原始效能日誌事件，以檢視其他指標和其他精細程度層級。

使用 Container Insights 的原始版本，收集的指標和擷取的指標會按自訂指標計費。使用 Container Insights 搭配 Amazon EKS 的增強可觀測性，Container Insights 指標和日誌會按觀測，而不是存放或擷取的指標計費。如需 CloudWatch 定價的詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

**【預覽】** 對於 Amazon EKS，Container Insights with OpenTelemetry 提供額外的指標模式，該模式使用 OpenTelemetry Protocol (OTLP) 收集指標，並支援 PromQL 查詢。每個指標最多可新增 150 個標籤，包括 OpenTelemetry 語意慣例屬性，以及 Kubernetes Pod 和節點標籤。如需詳細資訊，請參閱[適用於 Amazon EKS 的 Container Insights 搭配 OpenTelemetry 指標](container-insights-otel-metrics.md)。

在 Amazon EKS、RedHatOpenshift on AWS和 Kubernetes 中，Container Insights 會使用 CloudWatch 代理程式的容器化版本來探索叢集中所有執行中的容器。然後，它會在效能堆疊的每一層上收集效能資料。

Container Insights 支援使用 AWS KMS key 加密其收集的日誌和指標。若要啟用此加密，您必須為接收 Container Insights 資料的日誌群組手動啟用 AWS KMS 加密。這會使 Container Insights 使用提供的 KMS 金鑰加密此資料。僅支援對稱金鑰。請勿使用非對稱 KMS 金鑰加密您的日誌群組。

如需詳細資訊，請參閱[使用 AWS KMS在 CloudWatch Logs 中加密日誌資料](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/encrypt-log-data-kms.html)。

## 支援平台
<a name="container-insights-platforms"></a>

Container Insights 適用於 Amazon EC2 執行個體上的 Amazon Elastic Container Service、Amazon Elastic Kubernetes Service AWS、RedHat OpenShift on 和 Kubernetes 平台。
+ 如為 Amazon ECS，Container Insights 會同時在 Linux 和 Windows Server 執行個體中收集叢集、任務和服務層級的指標。Container Insights 只能於 Linux 執行個體中收集執行個體層級的指標。網路指標適用於使用 `bridge` 網路模式和 `awsvpc` 網路模式的容器，但不適用於使用 `host` 網路模式的容器。
+ 如為 Amazon EC2 執行個體上的 Amazon Elastic Kubernetes Service 和 Kubernetes 平台，Linux 和 Windows 執行個體均支援 Container Insights。
+ **【預覽】** 具有 OpenTelemetry 指標的 Container Insights 可供 Amazon EKS 使用。如需詳細資訊，請參閱[適用於 Amazon EKS 的 Container Insights 搭配 OpenTelemetry 指標](container-insights-otel-metrics.md)。

# 適用於 Amazon ECS 的具有增強可觀測性的 Container Insights
<a name="container-insights-detailed-ecs-metrics"></a>

在 2024 年 12 月 2 日， AWS 發行了 Container Insights 並增強了 Amazon ECS 的可觀測性。此版本支援使用 Amazon EC2 與 Fargates 啟動類型的 Amazon ECS 叢集的增強可觀測性。在 Amazon ECS 上設定了具有增強可觀測性的 Container Insights 後，Container Insights 會自動收集您環境中從叢集層級到容器層級的詳細基礎設施遙測資料，並將這些關鍵效能資料顯示在精心設計的儀表板中，無需您進行繁重的可觀測性設定。如需如何設定具有增強可觀測性的 Container Insights 的詳細資訊，請參閱[在 Amazon ECS 上設定 Container Insights](deploy-container-insights-ECS-cluster.md)。

具有增強可觀測性的 Container Insights 可提供所有 Container Insights 指標，以及其他任務和容器指標。如需詳細資訊，請參閱[具有增強可觀測性指標的 Amazon ECS Container Insights](Container-Insights-enhanced-observability-metrics-ECS.md)。

具備增強型可觀測性的 Container Insights 同時支援 CloudWatch 跨帳戶可觀測性。您可以使用單一監控帳戶來監控和疑難排解單一區域中跨多個 AWS 帳戶的應用程式。如需詳細資訊，請參閱 [CloudWatch 跨帳戶觀察功能](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Unified-Cross-Account.html)。

# 適用於 Amazon EKS 的具備增強之可觀測性的 Container Insights
<a name="container-insights-detailed-metrics"></a>

2023 年 11 月 6 日，推出了新版 Container Insights。此版本支援執行於 Amazon EC2 的 Amazon EKS 叢集的增強型可觀測性，並且可從這些叢集中收集更詳細的指標。安裝之後，它會自動收集 Amazon EKS 叢集的詳細基礎設施遙測和容器日誌。然後，您可使用經策管且立即可用的儀表板，來深入了解應用程式和基礎設施遙測。

Container Insights 搭配 Amazon EKS 的增強可觀測性，可收集容器層級的精細運作狀態、效能和狀態指標，以及控制平面指標。如需有關收集的額外指標和維度的詳細資訊，請參閱 [具有增強可觀測性指標的 Amazon EKS 和 Kubernetes Container Insights](Container-Insights-metrics-enhanced-EKS.md)。

如果您在 2023 年 11 月 6 日之後，在 Amazon EC2 的 Amazon EKS 叢集上使用 CloudWatch 代理程式來安裝 Container Insights，您可使用 Container Insights 搭配 Amazon EKS 的增強可觀測性。否則，您可遵循 [在 CloudWatch 中針對 Amazon EKS 升級至具有增強可觀測性的 Container Insights](Container-Insights-upgrade-enhanced.md) 中的指示，將 Amazon EKS 叢集升級到此新版本。

Container Insights 支援 CloudWatch 跨帳戶可觀測性。您可以使用單一監控帳戶來監控和疑難排解單一區域中跨多個 AWS 帳戶的應用程式。如需詳細資訊，請參閱[CloudWatch 跨帳戶觀察功能](CloudWatch-Unified-Cross-Account.md)。

適用於 Amazon EKS 的具有增強可觀測性的 Container Insights 也支援 Windows 工作節點。

Fargate 不支援 Container Insights 搭配 Amazon EKS 的增強可觀測性。

**注意**  
您可導覽至 Container Insights 主控台，尋找是否有可升級為 Container Insights 搭配 Amazon EKS 的增強可觀測性的叢集。若要執行此操作，請在 CloudWatch 主控台的導覽窗格中依次選擇 **Insights**、**Container Insights**。在 Container Insights 主控台中，橫幅會通知您是否有任何可升級的 Amazon EKS 叢集，以及升級頁面的連結。

# 適用於 Amazon EKS 的 Container Insights 搭配 OpenTelemetry 指標
<a name="container-insights-otel-metrics"></a>

**預覽版**  
使用 OpenTelemetry 指標的 Container Insights 可讓您了解 Amazon EKS 叢集基礎設施的運作狀態。在美國東部 （維吉尼亞北部）、美國西部 （奧勒岡）、歐洲 （愛爾蘭）、亞太區域 （新加坡） 和亞太區域 （雪梨） 可免費公開預覽。

Amazon CloudWatch Observability EKS 附加元件會從 Amazon EKS 叢集收集開放原始碼指標，並使用 OpenTelemetry Protocol (OTLP) 以 30 秒精細程度將其傳送至 CloudWatch。這些指標使用原始來源的指標名稱，包括 cAdvisor、Prometheus Node Exporter、NVIDIA DCGM、Kube State Metrics 和 AWS Neuron Monitor。您可以在 CloudWatch Query Studio 中使用 PromQL 或透過 Prometheus 相容查詢 API 來查詢這些指標。

每個指標都會自動擴充最多 150 個標籤，包括 OpenTelemetry 語意慣例屬性，以及 Kubernetes Pod 和節點標籤。PromQL 會在查詢時間處理彙總，因此每個指標都會在每個資源發佈一次，而不是在多個彙總層級發佈。附加元件也會將 AWS Neuron 和 AWS Elastic Fabric Adapter 的加速器指標與使用它們的特定 Pod 和容器建立關聯，以提供無法單獨從指標來源取得的可見性。

若要在 Amazon EKS 叢集上啟用 OTel Container Insights，請透過 Amazon EKS 主控台或透過基礎設施做為程式碼安裝 Amazon CloudWatch 可觀測性 EKS 附加元件版本 `v6.0.1-eksbuild.1`或更新版本。

如需設定 OTel Container Insights 的詳細資訊，請參閱 [設定 Container Insights](deploy-container-insights.md)。

如需使用 PromQL 查詢這些指標的詳細資訊，請參閱 [PromQL 查詢](CloudWatch-PromQL-Querying.md)。

## OTel Container Insights 與 Container Insights 的比較方式 （增強版）
<a name="container-insights-otel-comparison"></a>

下表摘要說明 Container Insights （增強版） 和 OTel Container Insights 之間的差異。


| 功能 | Container Insights （增強版） | OTel Container Insights | 
| --- | --- | --- | 
| 指標名稱 | CloudWatch 格式指標 （例如 pod\$1cpu\$1utilization) | 開放原始碼原生 （例如 container\$1cpu\$1usage\$1seconds\$1total) | 
| 每個指標的標籤 | 每個指標 3–6 個預先定義的維度 | 最多 150 個標籤，包括所有 Kubernetes Pod 和節點標籤 | 
| 聚合 | 在多個層級預先彙總 （叢集、命名空間、工作負載、Pod) | 原始每個資源指標；使用 PromQL 在查詢時間彙總 | 
| 查詢語言 | CloudWatch 指標 API | PromQL (Prometheus 相容） | 
| 指標擷取 | EMF 格式的 CloudWatch Logs | OTLP 端點 | 

## 如何標記指標
<a name="container-insights-otel-labels"></a>

OTel Container Insights 收集的每個指標都包含三個來源的標籤。

遙測來源原生標籤  
來自原始指標來源的標籤 （例如，cAdvisor 提供標籤，例如 `pod`、 `namespace`和 `container`)。這些會保留為資料點屬性。

OpenTelemetry 資源屬性  
附加元件會遵循 [Kubernetes](https://opentelemetry.io/docs/specs/semconv/resource/k8s/)、[主機](https://opentelemetry.io/docs/specs/semconv/resource/host/)和[雲端](https://opentelemetry.io/docs/specs/semconv/resource/cloud/)的 OpenTelemetry 語意慣例附加資源屬性，例如 `k8s.pod.name`、`k8s.namespace.name`、`k8s.node.name`、 `host.name`和 `cloud.region`。這些屬性在所有指標來源之間都是一致的。

Kubernetes Pod 和節點標籤  
從 Kubernetes API 發現的所有 Pod 標籤和節點標籤都會附加為具有字首 `k8s.pod.label`和 的資源屬性`k8s.node.label`。

如需如何使用 PromQL 查詢這些屬性的詳細資訊，請參閱 [PromQL 查詢](CloudWatch-PromQL-Querying.md)。

## 支援的指標
<a name="container-insights-otel-supported-metrics"></a>

下表列出 OTel Container Insights 收集的指標來源和類別。


| 指標來源 | 指標類別 | 先決條件 | 
| --- | --- | --- | 
| cAdvisor | CPU 指標 | - | 
| cAdvisor | 記憶體指標 | - | 
| cAdvisor | 網路指標 | - | 
| cAdvisor | 磁碟和檔案系統指標 | - | 
| Prometheus Node Exporter | CPU 指標 | - | 
| Prometheus Node Exporter | 記憶體指標 | - | 
| Prometheus Node Exporter | 磁碟指標 | - | 
| Prometheus Node Exporter | 檔案系統指標 | - | 
| Prometheus Node Exporter | 網路指標 | - | 
| Prometheus Node Exporter | 系統指標 | - | 
| Prometheus Node Exporter | VMStat 指標 | - | 
| Prometheus Node Exporter | Netstat 和通訊端指標 | - | 
| NVIDIA DCGM | GPU 使用率和效能指標 | 必須安裝 [NVIDIA 裝置外掛程式](https://github.com/NVIDIA/k8s-device-plugin)和 [NVIDIA 容器工具組](https://github.com/NVIDIA/nvidia-container-toolkit)。 | 
| NVIDIA DCGM | GPU 記憶體指標 | 必須安裝 [NVIDIA 裝置外掛程式](https://github.com/NVIDIA/k8s-device-plugin)和 [NVIDIA 容器工具組](https://github.com/NVIDIA/nvidia-container-toolkit)。 | 
| NVIDIA DCGM | GPU 功率和熱度指標 | 必須安裝 [NVIDIA 裝置外掛程式](https://github.com/NVIDIA/k8s-device-plugin)和 [NVIDIA 容器工具組](https://github.com/NVIDIA/nvidia-container-toolkit)。 | 
| NVIDIA DCGM | GPU 限流指標 | 必須安裝 [NVIDIA 裝置外掛程式](https://github.com/NVIDIA/k8s-device-plugin)和 [NVIDIA 容器工具組](https://github.com/NVIDIA/nvidia-container-toolkit)。 | 
| NVIDIA DCGM | GPU 錯誤和可靠性指標 | 必須安裝 [NVIDIA 裝置外掛程式](https://github.com/NVIDIA/k8s-device-plugin)和 [NVIDIA 容器工具組](https://github.com/NVIDIA/nvidia-container-toolkit)。 | 
| NVIDIA DCGM | GPU NVLink 指標 | 必須安裝 [NVIDIA 裝置外掛程式](https://github.com/NVIDIA/k8s-device-plugin)和 [NVIDIA 容器工具組](https://github.com/NVIDIA/nvidia-container-toolkit)。 | 
| NVIDIA DCGM | GPU 資訊指標 | 必須安裝 [NVIDIA 裝置外掛程式](https://github.com/NVIDIA/k8s-device-plugin)和 [NVIDIA 容器工具組](https://github.com/NVIDIA/nvidia-container-toolkit)。 | 
| AWS Neuron 監視器 | NeuronCore 指標 | 必須安裝 [Neuron 驅動程式](https://awsdocs-neuron.readthedocs-hosted.com/en/latest/general/setup/neuron-setup/pytorch/neuronx/ubuntu/torch-neuronx-ubuntu22.html)和 [Neuron 裝置外掛程式](https://awsdocs-neuron.readthedocs-hosted.com/en/latest/containers/kubernetes-getting-started.html)。 | 
| AWS Neuron 監視器 | NeuronDevice 指標 | 必須安裝 [Neuron 驅動程式](https://awsdocs-neuron.readthedocs-hosted.com/en/latest/general/setup/neuron-setup/pytorch/neuronx/ubuntu/torch-neuronx-ubuntu22.html)和 [Neuron 裝置外掛程式](https://awsdocs-neuron.readthedocs-hosted.com/en/latest/containers/kubernetes-getting-started.html)。 | 
| AWS Neuron 監視器 | Neuron 系統指標 | 必須安裝 [Neuron 驅動程式](https://awsdocs-neuron.readthedocs-hosted.com/en/latest/general/setup/neuron-setup/pytorch/neuronx/ubuntu/torch-neuronx-ubuntu22.html)和 [Neuron 裝置外掛程式](https://awsdocs-neuron.readthedocs-hosted.com/en/latest/containers/kubernetes-getting-started.html)。 | 
| AWS Elastic Fabric 轉接器 | EFA 指標 | 必須安裝 [EFA 裝置外掛程式](https://github.com/aws/eks-charts/tree/master/stable/aws-efa-k8s-device-plugin)。 | 
| NVMe | NVMe SMART 指標 | - | 
| Kube 狀態指標 | Pod、節點、部署、DaemonSet、StatefulSet、ReplicaSet、Job、CronJob、Service、Namespace、PersistentVolume、PersistentVolumeClaim 指標 | - | 
| Kubernetes API 伺服器 | API 伺服器和等指標 | - | 

## CloudWatch 代理程式容器映像
<a name="container-insights-download-limit"></a>

Amazon 可在 Amazon Elastic 容器登錄檔上提供 CloudWatch 代理程式容器映像。如需詳細資訊，請參閱 Amazon ECR 上的 [cloudwatch-agent](https://gallery.ecr.aws/cloudwatch-agent/cloudwatch-agent)。

# 設定 Container Insights
<a name="deploy-container-insights"></a>

Amazon ECS、Amazon EKS 和 Kubernetes 的 Container Insights 設定程序是不同的。
+ [在 Amazon EKS 和 Kubernetes 上設定 Container Insights](deploy-container-insights-EKS.md)
+ [在 Amazon ECS 上設定 Container Insights](deploy-container-insights-ECS.md)

**Topics**
+ [在 Amazon ECS 上設定 Container Insights](deploy-container-insights-ECS.md)
+ [在 Amazon EKS 和 Kubernetes 上設定 Container Insights](deploy-container-insights-EKS.md)
+ [在 RedHat OpenShift on AWS (ROSA) 上設定 Container Insights](deploy-container-insights-RedHatOpenShift.md)

# 在 Amazon ECS 上設定 Container Insights
<a name="deploy-container-insights-ECS"></a>

您可以使用下列選項之一或兩個都用，啟用 Amazon ECS 叢集上的 Container Insights：
+ 使用 AWS 管理主控台 或 AWS CLI 開始收集叢集層級、任務層級和服務層級指標。
+ 將 CloudWatch 代理程式部署為常駐程式服務，開始收集 Amazon EC2 執行個體上託管之叢集的執行個體層級指標。

**Topics**
+ [在 Amazon ECS 上設定 Container Insights](deploy-container-insights-ECS-cluster.md)
+ [使用 AWS Distro for OpenTelemetry 在 Amazon ECS 上設定 Container Insights](deploy-container-insights-ECS-adot.md)
+ [部署 CloudWatch 代理程式以收集 Amazon ECS 上的 EC2 執行個體層級指標](deploy-container-insights-ECS-instancelevel.md)
+ [部署 AWS Distro for OpenTelemetry 以收集 Amazon ECS 叢集上的 EC2 執行個體層級指標](deploy-container-insights-ECS-OTEL.md)
+ [設定 FireLens 以將日誌傳送至 CloudWatch Logs](deploy-container-insights-ECS-logs.md)

# 在 Amazon ECS 上設定 Container Insights
<a name="deploy-container-insights-ECS-cluster"></a>

可使用 Amazon ECS 主控台或 AWS CLI，在新的或現有的 Amazon ECS 叢集上設定具有增強可觀測性的 Container Insights 或 Container Insights。Container Insights 會收集叢集、任務和服務層級的指標。具有增強可觀測性的 Container Insights 可提供額外的維度和指標，讓您深入了解容器層級的可見性。

如果在 Amazon EC2 執行個體上使用 Amazon ECS，請使用包含 Amazon ECS 代理程式 1.29 版或更新版本的 AMI 來啟動該執行個體。如需更新代理程式版本的相關資訊，請參閱[更新 Amazon ECS 容器代理程式](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-agent-update.html)。

**注意**  
如果您用於 Amazon ECS Container Insights 指標的客戶受管 AWS KMS 金鑰尚未設定為與 CloudWatch 搭配使用，您必須更新金鑰政策，以允許在 CloudWatch Logs 中加密日誌。您也必須將自己的 AWS KMS 金鑰與 中的日誌群組建立關聯`/aws/ecs/containerinsights/ClusterName/performance`。如需詳細資訊，請參閱[使用 AWS Key Management Service在 CloudWatch Logs 中加密日誌資料](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/encrypt-log-data-kms.html)。

我們建議您使用具有增強可觀測性的 Container Insights，而不是 Container Insights，因其可在容器環境中提供詳細的可見性，進而縮短解析的平均時間。

## 設定具有增強可觀測性的 Container Insights
<a name="set-container-insights-ECS-cluster-enhanced"></a>

可以使用 Amazon ECS 主控台或 AWS CLI來開啟具有增強可觀測性的 Container Insights。

------
#### [ AWS CLI ]

使用以下命令開啟具有增強可觀測性 Container Insights。

 將 `containerInsights` 帳戶設定設為 `enhanced`

```
aws ecs put-account-setting --name containerInsights --value enhanced
```

範例輸出

```
{
    "setting": {
        "name": "containerInsights",
        "value": "enhanced",
        "principalArn": "arn:aws:iam::123456789012:johndoe",
         "type": user
    }
}
```

**注意**  
根據預設，`put-account-setting` 僅適用於目前已驗證的使用者。若要為所有使用者和角色啟用帳戶範圍的設定，請使用根使用者，如下列範例所示。  

```
aws ecs put-account-setting --name containerInsights --value enhanced --principal-arn arn:aws:iam::accountID:root
```

設定此帳戶設定後，所有新叢集會自動使用具有增強可觀測性的 Container Insights。使用 `update-cluster-settings` 命令將具有增強可觀測性的 Container Insights 新增至現有叢集，或將目前使用 Container Insights 的叢集升級至具有增強可觀測性的 Container Insights。

```
aws ecs update-cluster-settings --cluster cluster-name --settings name=containerInsights,value=enhanced
```

------
#### [ Amazon ECS console ]

1. 開啟主控台，網址為 [https://console.aws.amazon.com/ecs/v2](https://console.aws.amazon.com/ecs/v2)。

1. 在頂部導覽列中，選取要檢視帳戶設定的區域。

1. 在導覽頁面中，選擇 **Account Settings** (帳戶設定)。

1. 選擇**更新**。

1. 若要使用具有增強可觀測性的 Container Insights，請選擇**具有增強可觀測性的 Container Insights**。

1. 選擇**儲存變更**。

1. 在確認畫面，選擇**確認**以儲存選項。

設定它之後，所有新叢集會自動使用具有增強可觀測性的 Container Insights。可將具有增強可觀測性的 Container Insights 新增至現有叢集，或將目前使用 Container Insights 的叢集更新為具有增強可觀測性的 Container Insights。如需詳細資訊，請參閱 *Amazon Elastic Container Service 開發人員指南*中的[更新 Amazon ECS 叢集](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/update-cluster-v2.html)。

------

## 設定 Container Insights
<a name="set-container-insights-ECS-cluster"></a>

可以使用 Amazon ECS 主控台或 AWS CLI開啟 Container Insights。

------
#### [ AWS CLI ]

若要使用 Container Insights，請將 `container Insights` 帳戶設定設為 `enabled`。使用下列命令來啟用 Container Insights。

```
aws ecs put-account-setting --name containerInsights --value enabled
```

範例輸出

```
{
    "setting": {
        "name": "container Insights",
        "value": "enabled",
        "principalArn": "arn:aws:iam::123456789012:johndoe",
         "type": user
    }
}
```

當您將 `container Insights` 帳戶設定設為 `enabled` 時，所有新叢集都會預設啟用 Container Insights。使用 `update-cluster-settings` 命令，將 Container Insights 新增至現有叢集。

```
aws ecs update-cluster-settings --cluster cluster-name --settings name=containerInsights,value=enabled
```

------
#### [ Amazon ECS console ]

1. 開啟主控台，網址為 [https://console.aws.amazon.com/ecs/v2](https://console.aws.amazon.com/ecs/v2)。

1. 在頂部導覽列中，選取要檢視帳戶設定的區域。

1. 在導覽頁面中，選擇 **Account Settings** (帳戶設定)。

1. 選擇**更新**。

1. 若要使用 Container Insights，請選擇 **Container Insights**。

1. 選擇**儲存變更**。

1. 在確認畫面，選擇**確認**以儲存選項。

設定它之後，所有新叢集會自動使用 Container Insights。更新現有叢集以新增 Container Insights。如需詳細資訊，請參閱 *Amazon Elastic Container Service 開發人員指南*中的[更新 Amazon ECS 叢集](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/update-cluster-v2.html)。

------

# 使用 AWS Distro for OpenTelemetry 在 Amazon ECS 上設定 Container Insights
<a name="deploy-container-insights-ECS-adot"></a>

如果您想要使用 AWS Distro for OpenTelemetry 在 Amazon ECS 叢集上設定 CloudWatch Container Insights，請使用本節。如需 AWS Distro for Open Telemetry 的詳細資訊，請參閱 [AWS Distro for OpenTelemetry](https://aws.amazon.com/otel/)。

這些步驟假設您已經有一個執行 Amazon ECS 的叢集。如需將 AWS Distro for Open Telemetry 與 Amazon ECS 搭配使用並為此設定 Amazon ECS 叢集的詳細資訊，請參閱在 [Amazon Elastic Container Service 中設定 AWS Distro for OpenTelemetry Collector](https://aws-otel.github.io/docs/setup/ecs)。

## 步驟 1：建立任務角色
<a name="deploy-container-insights-ECS-adot-CreateTaskRole"></a>

第一步是在 AWS OpenTelemetry Collector 將使用的叢集中建立任務角色。

**為 AWS Distro for OpenTelemetry 建立任務角色**

1. 前往 [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/) 開啟 IAM 主控台。

1. 在導覽窗格中，選擇 **Policies (政策)**，然後選擇 **Create policy (建立政策)**。

1. 選擇 **JSON** 標籤，並複製下列政策：

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Effect": "Allow",
               "Action": [
                   "logs:PutLogEvents",
                   "logs:CreateLogGroup",
                   "logs:CreateLogStream",
                   "logs:DescribeLogStreams",
                   "logs:DescribeLogGroups",
                   "ssm:GetParameters"
               ],
               "Resource": "*"
           }
       ]
   }
   ```

------

1. 選擇**檢閱政策**。

1. 對於名稱，輸入 **AWSDistroOpenTelemetryPolicy**，然後選擇 **Create policy** (建立政策)。

1. 在左側導覽窗格中，選擇 **Roles** (角色)，然後選擇 **Create role** (建立角色)。

1. 在服務清單中，選擇 **Elastic Container Service**。

1. 在頁面下方，選擇 **Elastic Container Service Task** (Elastic Container Service 任務)，然後選擇 **Next: Permissions** ((下一步：許可))。

1. 在政策清單中，搜尋 **AWSDistroOpenTelemetryPolicy**。

1. 選取 **AWSDistroOpenTelemetryPolicy** 旁的核取方塊。

1. 選擇 **Next: Tags** (下一步：標籤)，然後選擇 **Next: Review** (下一步：檢閱)。

1. 針對 **Role name** (角色名稱)，輸入 **AWSOpenTelemetryTaskRole**，然後選擇 **Create role** (建立角色)。

## 步驟 2：建立任務執行角色
<a name="deploy-container-insights-ECS-adot-CreateTaskExecutionRole"></a>

下一個步驟是為 AWS OpenTelemetry Collector 建立任務執行角色。

**為 AWS Distro for OpenTelemetry 建立任務執行角色**

1. 前往 [https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/) 開啟 IAM 主控台。

1. 在左側導覽窗格中，選擇 **Roles** (角色)，然後選擇 **Create role** (建立角色)。

1. 在服務清單中，選擇 **Elastic Container Service**。

1. 在頁面下方，選擇 **Elastic Container Service Task** (Elastic Container Service 任務)，然後選擇 **Next: Permissions** ((下一步：許可))。

1. 在政策清單中，搜尋 **AmazonECSTaskExecutionRolePolicy**，然後選取 **AmazonECSTaskExecutionRolePolicy** 旁的核取方塊。

1. 在政策清單中，搜尋 **CloudWatchLogsFullAccess**，然後選取 **CloudWatchLogsFullAccess** 旁的核取方塊。

1. 在政策清單中，搜尋 **AmazonSSMReadOnlyAccess**，然後選取 **AmazonSSMReadOnlyAccess** 旁的核取方塊。

1. 選擇 **Next: Tags** (下一步：標籤)，然後選擇 **Next: Review** (下一步：檢閱)。

1. 針對 **Role name** (角色名稱)，輸入 **AWSOpenTelemetryTaskExecutionRole**，然後選擇 **Create role** (建立角色)。

## 步驟 3：建立任務定義
<a name="deploy-container-insights-ECS-adot-CreateTaskDefinition"></a>

下一步是建立任務定義。

**為 AWS Distro for OpenTelemetry 建立任務定義**

1. 開啟主控台，網址為 [https://console.aws.amazon.com/ecs/v2](https://console.aws.amazon.com/ecs/v2)。

1. 在導覽窗格中，選擇 **Task Definitions** (任務定義)。

1. 選擇 **Create new task definition** (建立新任務定義)，以及 **Create new task definitionN** (建立新任務定義)。

1. 在**任務定義系列**中，請為任務定義指定唯一名稱。

1. 設定您的容器，然後選擇**下一步**。

1. 在**指標和日誌記錄**下，選取**使用指標集合**。

1. 選擇**下一步**。

1. 選擇**建立**。

如需搭配使用 AWS OpenTelemetry 收集器與 Amazon ECS 的詳細資訊，請參閱在 [Amazon Elastic Container Service 中設定 AWS Distro for OpenTelemetry 收集器](https://aws-otel.github.io/docs/setup/ecs)。

## 步驟 4：執行任務
<a name="deploy-container-insights-ECS-adot-CreateTaskDefinition"></a>

最後一個步驟是執行您建立的任務。

**執行 AWS Distro for OpenTelemetry 的任務**

1. 開啟主控台，網址為 [https://console.aws.amazon.com/ecs/v2](https://console.aws.amazon.com/ecs/v2)。

1. 在左側導覽窗格，選擇 **Task Definitions** (任務定義)，然後選取您剛建立的任務。

1. 選擇**動作**、**部署**、**執行任務**。

1. 選擇 **Deploy** (部署)、**Run task** (執行任務)。

1. 在**運算選項**區段中，從**現有叢集**中選擇叢集。

1. 選擇**建立**。

1. 接下來，您可以在 CloudWatch 主控台中檢查新的指標。

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在左側導覽窗格中，選擇 **Metrics (指標)**。

   您應該會看到 **ECS/ContainerInsights** 命名空間。選擇該命名空間，然後您應該會看到八個指標。

# 部署 CloudWatch 代理程式以收集 Amazon ECS 上的 EC2 執行個體層級指標
<a name="deploy-container-insights-ECS-instancelevel"></a>

若要部署 CloudWatch 代理程式以從 EC2 執行個體託管之 Amazon ECS 叢集中收集執行個體層級指標，請使用具有預設組態的 Quick Start 設定，或手動安裝代理以便能自訂代理。

這兩種方法都需要您至少有一個已部署了 EC2 啟動類型的 Amazon ECS 叢集，並要求 CloudWatch 代理程式容器可以存取 Amazon EC2 執行個體中繼資料服務 (IMDS)。如需有關 IMDS 的詳細資訊，請參閱[執行個體中繼資料與使用者資料](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html)。

這些方法也假設您 AWS CLI 已安裝 。此外，若要執行下列程序中的命令，您必須登入具有 **IAMFullAccess** 和 **AmazonECS\$1FullAccess** 政策的帳戶或角色。

**重要**  
在任務定義中定義 CloudWatch Agent 容器時，請設定 `essential: false`。這可防止整個 Amazon ECS 服務在 CloudWatch Agent 容器發生故障時停止。即使代理程式暫時無法使用，其他重要的應用程式容器仍會繼續執行。

**Topics**
+ [使用 快速設定 CloudFormation](#deploy-container-insights-ECS-instancelevel-quickstart)
+ [手動和自訂設定](#deploy-container-insights-ECS-instancelevel-manual)

## 使用 快速設定 CloudFormation
<a name="deploy-container-insights-ECS-instancelevel-quickstart"></a>

若要使用快速設定，請輸入下列命令以使用 CloudFormation 來安裝代理程式。將 *cluster-name* 和 *cluster-region* 替換成您 Amazon ECS 叢集的名稱和區域。

此命令會建立 IAM 角色 **CWAgentECSTaskRole** 和 **CWAgentECSExecutionRole**。如果您的帳戶中已存在這些角色，請在輸入命令時改用 `ParameterKey=CreateIAMRoles,ParameterValue=False`，而不是使用 `ParameterKey=CreateIAMRoles,ParameterValue=True`。否則命令會失敗。

```
ClusterName=cluster-name
Region=cluster-region
curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/daemon-service/cwagent-ecs-instance-metric/cloudformation-quickstart/cwagent-ecs-instance-metric-cfn.json
aws cloudformation create-stack --stack-name CWAgentECS-${ClusterName}-${Region} \
    --template-body file://cwagent-ecs-instance-metric-cfn.json \
    --parameters ParameterKey=ClusterName,ParameterValue=${ClusterName} \
                 ParameterKey=CreateIAMRoles,ParameterValue=True \
    --capabilities CAPABILITY_NAMED_IAM \
    --region ${Region}
```

**(替代) 使用您自己的 IAM 角色**

如果您想要使用自己自訂的 ECS 任務角色和 ECS 任務執行角色，不使用 **CWAgentECSTaskRole** 和 **CWAgentECSExecutionRole** 角色，請先確定要作為 ECS 任務角色使用的角色連接了 **CloudWatchAgentServerPolicy**。此外，亦請確定要作為 ECS 任務執行角色使用的角色同時連接了 **CloudWatchAgentServerPolicy** 和 **AmazonECSTaskExecutionRolePolicy** 政策。然後輸入下列命令。在命令中，以您自訂 ECS 任務角色的 ARN 取代 *task-role-arn*，以您自訂 ECS 任務執行角色的 ARN 取代 *execution-role-arn*。

```
ClusterName=cluster-name
Region=cluster-region
TaskRoleArn=task-role-arn
ExecutionRoleArn=execution-role-arn
curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/daemon-service/cwagent-ecs-instance-metric/cloudformation-quickstart/cwagent-ecs-instance-metric-cfn.json
aws cloudformation create-stack --stack-name CWAgentECS-${ClusterName}-${Region} \
    --template-body file://cwagent-ecs-instance-metric-cfn.json \
    --parameters ParameterKey=ClusterName,ParameterValue=${ClusterName} \
                 ParameterKey=TaskRoleArn,ParameterValue=${TaskRoleArn} \
                 ParameterKey=ExecutionRoleArn,ParameterValue=${ExecutionRoleArn} \
    --capabilities CAPABILITY_NAMED_IAM \
    --region ${Region}
```

**故障診斷快速設定**

若要檢查 CloudFormation 堆疊的狀態，請輸入下列命令。

```
ClusterName=cluster-name
Region=cluster-region
aws cloudformation describe-stacks --stack-name CWAgentECS-$ClusterName-$Region --region $Region
```

如果您看到的 `StackStatus` 不是 `CREATE_COMPLETE` 或 `CREATE_IN_PROGRESS`，請檢查堆疊事件以找出錯誤。輸入以下命令。

```
ClusterName=cluster-name
Region=cluster-region
aws cloudformation describe-stack-events --stack-name CWAgentECS-$ClusterName-$Region --region $Region
```

若要檢查 `cwagent` 常駐程式服務的狀態，請輸入以下命令。在輸出中，您應該會看到 `runningCount` 等於 `deployment` 區段的 `desiredCount`。如果不相等，請檢查輸出的 `failures` 區段。

```
ClusterName=cluster-name
Region=cluster-region
aws ecs describe-services --services cwagent-daemon-service --cluster $ClusterName --region $Region
```

您也可以使用 CloudWatch Logs 主控台檢查代理程式日誌。尋找 **/ecs/ecs-cwagent-daemon-service** 日誌群組。

**刪除 CloudWatch 代理程式的 CloudFormation 堆疊**

如果您需要刪除 CloudFormation 堆疊，請輸入下列命令。

```
ClusterName=cluster-name
Region=cluster-region
aws cloudformation delete-stack --stack-name CWAgentECS-${ClusterName}-${Region} --region ${Region}
```

## 手動和自訂設定
<a name="deploy-container-insights-ECS-instancelevel-manual"></a>

依本節的步驟手動部署 CloudWatch 代理，以從 EC2 執行個體託管的 Amazon ECS 叢集中收集執行個體層級指標。

### 必要的 IAM 角色和政策
<a name="deploy-container-insights-ECS-instancelevel-IAMRoles"></a>

需要兩個 IAM 角色。如果角色不存在，即必須建立角色。如需這些角色的詳細資訊，請參閱 [IAM 任務角色](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task-iam-roles.html)和 [Amazon ECS 任務執行角色](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/task_execution_IAM_role.html)。
+ *ECS 任務角色*，CloudWatch 代理程式用來發布指標的角色。如果此角色已經存在，您必須確定它連接了 `CloudWatchAgentServerPolicy` 政策。
+ *ECS 任務執行角色*，CloudWatch 代理用來啟動 Amazon ECS 代理程式的角色。如果此角色已經存在，您必須確定它連接了 `AmazonECSTaskExecutionRolePolicy` 和 `CloudWatchAgentServerPolicy` 政策。

如果您尚未擁有這些角色，您可以使用下列命令建立它們並連接必要的政策。第一個命令會建立 ECS 任務角色。

```
aws iam create-role --role-name CWAgentECSTaskRole \
    --assume-role-policy-document "{\"Version\": \"2012-10-17\",		 	 	 \"Statement\": [{\"Sid\": \"\",\"Effect\": \"Allow\",\"Principal\": {\"Service\": \"ecs-tasks.amazonaws.com\"},\"Action\": \"sts:AssumeRole\"}]}"
```

輸入上一個命令後，請記下命令輸出中作為 "TaskRoleArn" 的 `Arn` 值。稍後建立任務定義時需要使用此值。然後輸入下列命令以連接必要的政策。

```
aws iam attach-role-policy --policy-arn arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy \
    --role-name CWAgentECSTaskRole
```

下一個命令會建立 ECS 任務執行角色。

```
aws iam create-role --role-name CWAgentECSExecutionRole \
    --assume-role-policy-document "{\"Version\": \"2012-10-17\",		 	 	 \"Statement\": [{\"Sid\": \"\",\"Effect\": \"Allow\",\"Principal\": {\"Service\": \"ecs-tasks.amazonaws.com\"},\"Action\": \"sts:AssumeRole\"}]}"
```

輸入上一個命令後，請記下命令輸出中作為 "ExecutionRoleArn" 的 `Arn` 值。稍後建立任務定義時需要使用此值。然後輸入下列命令以連接必要的政策。

```
aws iam attach-role-policy --policy-arn arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy \
    --role-name CWAgentECSExecutionRole
          
aws iam attach-role-policy --policy-arn arn:aws:iam::aws:policy/service-role/AmazonECSTaskExecutionRolePolicy \
    --role-name CWAgentECSExecutionRole
```

### 建立任務定義並啟動常駐程式服務
<a name="deploy-container-insights-ECS-instancelevel-taskdefinition"></a>

建立任務定義並用它啟動 CloudWatch 代理程式作為常駐程式服務。若要建立任務定義，請輸入下列命令。在前幾行中，將預留位置更換為您部署的實際值。*logs-region* 是 CloudWatch Logs 所在的區域，*cluster-region* 則是您叢集所在的區域。*task-role-arn* 是您所用之 ECS 任務角色的 Arn，*execution-role-arn* 則是 ECS 任務執行角色的 Arn。

```
TaskRoleArn=task-role-arn
ExecutionRoleArn=execution-role-arn
AWSLogsRegion=logs-region
Region=cluster-region
curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/daemon-service/cwagent-ecs-instance-metric/cwagent-ecs-instance-metric.json \
    | sed "s|{{task-role-arn}}|${TaskRoleArn}|;s|{{execution-role-arn}}|${ExecutionRoleArn}|;s|{{awslogs-region}}|${AWSLogsRegion}|" \
    | xargs -0 aws ecs register-task-definition --region ${Region} --cli-input-json
```

然後執行下列命令以啟動協助程式服務。將 *cluster-name* 和 *cluster-region* 替換成您 Amazon ECS 叢集的名稱和區域。

**重要**  
在執行此命令之前，請先移除所有容量提供者策略。否則，該命令將無法運作。

```
ClusterName=cluster-name
Region=cluster-region
aws ecs create-service \
    --cluster ${ClusterName} \
    --service-name cwagent-daemon-service \
    --task-definition ecs-cwagent-daemon-service \
    --scheduling-strategy DAEMON \
    --region ${Region}
```

如果看到此錯誤訊息 `An error occurred (InvalidParameterException) when calling the CreateService operation: Creation of service was not idempotent`，即表示您已經建立名為 `cwagent-daemon-service` 的協助程式服務。您必須使用下列命令作為範例，先刪除該服務。

```
ClusterName=cluster-name
Region=cluster-region
aws ecs delete-service \
    --cluster ${ClusterName} \
    --service cwagent-daemon-service \
    --region ${Region} \
    --force
```

### (選用) 進階組態
<a name="deploy-container-insights-ECS-instancelevel-advanced"></a>

或者，您可以選擇使用 SSM 為 EC2 執行個體託管之 Amazon ECS 叢集中的 CloudWatch 代理程式，指定其他組態選項。選項如下：
+ `metrics_collection_interval` – CloudWatch 代理程式收集指標的頻率 (秒)。預設為 60。範圍介於 1–172,000 之間。
+ `endpoint_override` – (選用) 指定不同端點以傳送日誌。如果從 VPC 中的叢集發布，且想要在 VPC 端點記錄資料，建議您這麼做。

  `endpoint_override` 的值必須是 URL 字串。
+ `force_flush_interval` – 指定日誌在傳送到伺服器之前停留在記憶體緩衝區內的最長時間 (以秒為單位)。不論此欄位的設定如何，如果緩衝區中的日誌大小達到 1 MB，系統會立即將日誌傳送到伺服器。預設值為 5 秒。
+ `region` – 根據預設，代理會將指標發布至 Amazon ECS 容器執行個體所在的同一區域。若要覆寫此項目，您可在此指定不同的區域。例如 `"region" : "us-east-1"`

以下是自訂組態的範例：

```
{
    "agent": {
        "region": "us-east-1"
    },
    "logs": {
        "metrics_collected": {
            "ecs": {
                "metrics_collection_interval": 30
            }
        },
        "force_flush_interval": 5
    }
}
```

**若要在 Amazon ECS 容器中自訂 CloudWatch 代理程式組態**

1. 確定 **AmazonSSMReadOnlyAccess** 政策已連接至您的 Amazon ECS 任務執行角色。您可以輸入以下命令來執行此操作。此範例假設您的 Amazon ECS 任務執行角色是 CWAgentECSExecutionRole。如果使用不同的角色，請更換下列命令中的角色名稱。

   ```
   aws iam attach-role-policy --policy-arn arn:aws:iam::aws:policy/AmazonSSMReadOnlyAccess \
           --role-name CWAgentECSExecutionRole
   ```

1. 建立類似上述範例的自訂組態檔案。將此檔案命名為 `/tmp/ecs-cwagent-daemon-config.json`。

1. 執行下列命令，將此組態放入參數存放區。將 *cluster-region* 替換成您 Amazon ECS 叢集的區域。若要執行此命令，您必須登入具有 **AmazonSSMFullAccess** 政策的使用者或角色。

   ```
   Region=cluster-region
   aws ssm put-parameter \
       --name "ecs-cwagent-daemon-service" \
       --type "String" \
       --value "`cat /tmp/ecs-cwagent-daemon-config.json`" \
       --region $Region
   ```

1. 將任務定義檔案下載至本機檔案，例如 `/tmp/cwagent-ecs-instance-metric.json`

   ```
   curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/daemon-service/cwagent-ecs-instance-metric/cwagent-ecs-instance-metric.json -o /tmp/cwagent-ecs-instance-metric.json
   ```

1. 修改任務定義檔案。移除以下區段：

   ```
   "environment": [
                   {
                       "name": "USE_DEFAULT_CONFIG",
                       "value": "True"
                   }
               ],
   ```

   以下列內容取代該區段：

   ```
   "secrets": [
                   {
                       "name": "CW_CONFIG_CONTENT",
                       "valueFrom": "ecs-cwagent-daemon-service"
                   }
               ],
   ```

1. 依照下列步驟重新啟動代理作為協助程式服務：

   1. 執行下列命令。

      ```
      TaskRoleArn=task-role-arn
      ExecutionRoleArn=execution-role-arn
      AWSLogsRegion=logs-region
      Region=cluster-region
      cat /tmp/cwagent-ecs-instance-metric.json \
          | sed "s|{{task-role-arn}}|${TaskRoleArn}|;s|{{execution-role-arn}}|${ExecutionRoleArn}|;s|{{awslogs-region}}|${AWSLogsRegion}|" \
          | xargs -0 aws ecs register-task-definition --region ${Region} --cli-input-json
      ```

   1. 執行下列命令以啟動協助程式服務。將 *cluster-name* 和 *cluster-region* 替換成您 Amazon ECS 叢集的名稱和區域。

      ```
      ClusterName=cluster-name
      Region=cluster-region
      aws ecs create-service \
          --cluster ${ClusterName} \
          --service-name cwagent-daemon-service \
          --task-definition ecs-cwagent-daemon-service \
          --scheduling-strategy DAEMON \
          --region ${Region}
      ```

      如果看到此錯誤訊息 `An error occurred (InvalidParameterException) when calling the CreateService operation: Creation of service was not idempotent`，即表示您已經建立名為 `cwagent-daemon-service` 的協助程式服務。您必須使用下列命令作為範例，先刪除該服務。

      ```
      ClusterName=cluster-name
      Region=Region
      aws ecs delete-service \
          --cluster ${ClusterName} \
          --service cwagent-daemon-service \
          --region ${Region} \
          --force
      ```

# 部署 AWS Distro for OpenTelemetry 以收集 Amazon ECS 叢集上的 EC2 執行個體層級指標
<a name="deploy-container-insights-ECS-OTEL"></a>

使用本節中的步驟，使用 AWS Distro for OpenTelemetry 在 Amazon ECS 叢集上收集 EC2 執行個體層級指標。如需 AWS Distro for OpenTelemetry 的詳細資訊，請參閱 [AWS Distro for OpenTelemetry](https://aws.amazon.com/otel/)。

這些步驟假設您已經有一個執行 Amazon ECS 的叢集。必須使用 EC2 啟動類型來部署此叢集。如需將 AWS Distro for Open Telemetry 與 Amazon ECS 搭配使用並為此設定 Amazon ECS 叢集的詳細資訊，請參閱在 [Amazon Elastic Container Service for ECS EC2 執行個體層級指標中設定 AWS Distro for OpenTelemetry Collector](https://aws-otel.github.io/docs/setup/ecs#3-setup-the-aws-otel-collector-for-ecs-ec2-instance-metrics)。

**Topics**
+ [使用 快速設定 CloudFormation](#container-insights-ECS-OTEL-quicksetup)
+ [手動和自訂設定](#container-insights-ECS-OTEL-custom)

## 使用 快速設定 CloudFormation
<a name="container-insights-ECS-OTEL-quicksetup"></a>

下載 CloudFormation 範本檔案，以在 EC2 上安裝適用於 Amazon ECS 的 AWS Distro for OpenTelemetry 收集器。執行下列 curl 命令。

```
curl -O https://raw.githubusercontent.com/aws-observability/aws-otel-collector/main/deployment-template/ecs/aws-otel-ec2-instance-metrics-daemon-deployment-cfn.yaml
```

下載範本檔案後，將其開啟並將 *PATH\$1TO\$1CloudFormation\$1TEMPLATE* 替換為您儲存範本檔案的路徑。然後匯出下列參數並執行 CloudFormation 命令，如下列命令所示。
+ **Cluster\$1Name**– Amazon ECS 叢集名稱
+ **AWS\$1Region**– 將傳送資料的區域
+ **PATH\$1TO\$1CloudFormation\$1TEMPLATE** – 儲存 CloudFormation 範本檔案的路徑。
+ **command** – 若要讓 AWS Distro for OpenTelemetry 收集器收集 Amazon ECS on Amazon EC2 的執行個體層級指標，您必須`--config=/etc/ecs/otel-instance-metrics-config.yaml`為此參數指定 。

```
ClusterName=Cluster_Name
Region=AWS_Region
command=--config=/etc/ecs/otel-instance-metrics-config.yaml
aws cloudformation create-stack --stack-name AOCECS-${ClusterName}-${Region} \
--template-body file://PATH_TO_CloudFormation_TEMPLATE \
--parameters ParameterKey=ClusterName,ParameterValue=${ClusterName} \
ParameterKey=CreateIAMRoles,ParameterValue=True \
ParameterKey=command,ParameterValue=${command} \
--capabilities CAPABILITY_NAMED_IAM \
--region ${Region}
```

執行此命令後，請使用 Amazon ECS 主控台查看任務是否正在執行。

### 故障診斷快速設定
<a name="container-insights-ECS-OTEL-quicksetup-troubleshooting"></a>

若要檢查 CloudFormation 堆疊的狀態，請輸入下列命令。

```
ClusterName=cluster-name
Region=cluster-region
aws cloudformation describe-stack --stack-name AOCECS-$ClusterName-$Region --region $Region
```

如果 `StackStatus` 的值不是 `CREATE_COMPLETE` 或 `CREATE_IN_PROGRESS`，請檢查堆疊事件以找出錯誤。輸入以下命令。

```
ClusterName=cluster-name
Region=cluster-region
aws cloudformation describe-stack-events --stack-name AOCECS-$ClusterName-$Region --region $Region
```

若要檢查 `AOCECS` 常駐程式服務的狀態，請輸入以下命令。在輸出中，您應該會看到 `runningCount` 等於 deployment (部署) 區段的 `desiredCount`。如果不相等，請檢查輸出的 failures (失敗) 區段。

```
ClusterName=cluster-name
Region=cluster-region
aws ecs describe-services --services AOCECS-daemon-service --cluster $ClusterName --region $Region
```

您也可以使用 CloudWatch Logs 主控台檢查代理程式日誌。尋找 **/aws/ecs/containerinsights/\$1ClusterName\$1/performance** 日誌群組。

## 手動和自訂設定
<a name="container-insights-ECS-OTEL-custom"></a>

請依照本節中的步驟手動部署 AWS Distro for OpenTelemetry，以從託管於 Amazon EC2 執行個體的 Amazon ECS 叢集收集執行個體層級指標。

### 步驟 1：必要的角色和政策
<a name="container-insights-ECS-OTEL-custom-iam"></a>

需要兩個 IAM 角色。如果角色不存在，即必須建立角色。如需這些角色的詳細資訊，請參閱[建立 IAM 政策](https://aws-otel.github.io/docs/setup/ecs/create-iam-policy)和[建立 IAM 角色](https://aws-otel.github.io/docs/setup/ecs/create-iam-role)。

### 步驟 2：建立任務定義
<a name="container-insights-ECS-OTEL-custom-task"></a>

建立任務定義，並使用它來啟動 AWS Distro for OpenTelemetry 做為協助程式服務。

若要使用任務定義範本來建立任務定義，請遵循[使用 AWS OTel Collector 建立 EC2 執行個體的 ECS EC2 任務定義](https://aws-otel.github.io/docs/setup/ecs/task-definition-for-ecs-ec2-instance)中的指示。

若要使用 Amazon ECS 主控台建立任務定義，請遵循 [ Install AWS OTel Collector 中的指示，方法是透過 Amazon ECS EC2 執行個體指標的 AWS 主控台建立任務定義](https://aws-otel.github.io/docs/setup/ecs/create-task-definition-instance-console)。

### 步驟 3：啟動常駐程式服務
<a name="container-insights-ECS-OTEL-custom-launch"></a>

若要啟動 AWS Distro for OpenTelemetry 做為協助程式服務，請遵循[使用協助程式服務在 Amazon Elastic Container Service (Amazon ECS) 上執行任務](https://aws-otel.github.io/docs/setup/ecs/run-daemon-service)中的指示。

### (選用) 進階組態
<a name="container-insights-ECS-OTEL-custom-advancdeconfig"></a>

或者，您可以選擇使用 SSM 為 Amazon EC2 執行個體託管之 Amazon ECS 叢集中的 AWS Distro for OpenTelemetry，指定其他組態選項。如需有關建立組態檔案的詳細資訊，請參閱[自訂 OpenTelemetry 組態](https://aws-otel.github.io/docs/setup/ecs#5-custom-opentelemetry-configuration)。如需有關您在組態檔案中可使用之選項的詳細資訊，請參閱 [AWS Container Insights Receiver](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/receiver/awscontainerinsightreceiver/README.md)。

# 設定 FireLens 以將日誌傳送至 CloudWatch Logs
<a name="deploy-container-insights-ECS-logs"></a>

FireLens for Amazon ECS 可讓您使用任務定義參數，將日誌路由至 Amazon CloudWatch Logs，以儲存和分析日誌。FireLens 可與 [Fluent Bit](https://fluentbit.io/) 和 [Fluentd](https://www.fluentd.org/) 搭配使用。我們為 AWS Fluent Bit 映像提供 ，或者您可以使用自己的 Fluent Bit 或 Fluentd 映像。使用 AWS SDKs AWS CLI和 支援使用 FireLens 組態建立 Amazon ECS 任務定義 AWS 管理主控台。如需 CloudWatch Logs 的詳細資訊，請參閱[什麼是 CloudWatch Logs？](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html)。

使用 FireLens for Amazon ECS 時有一些關鍵考量事項。如需詳細資訊，請參閱[考量](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html#firelens-considerations)。

若要尋找 AWS 適用於 Fluent Bit 映像的 ，請參閱[使用 AWS 適用於 Fluent Bit 映像](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/firelens-using-fluentbit.html)。

若要建立使用 FireLens 組態的任務定義，請參閱[建立使用 FireLens 組態的任務定義](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/firelens-taskdef.html)。

**範例**

下列任務定義範例示範如何指定將日誌轉送至 CloudWatch Logs 日誌群組的日誌組態。如需詳細資訊，請參閱*《Amazon CloudWatch Logs 使用者指南》*中的[什麼是 Amazon CloudWatch Logs？](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/WhatIsCloudWatchLogs.html)。

在日誌組態選項中，指定日誌群組名稱及其所在的區域。若要讓 Fluent 位元代表您建立日誌群組，請指定 `"auto_create_group":"true"`。您也可以將任務 ID 指定為日誌串流字首，以幫助篩選。如需詳細資訊，請參閱 [適用於 CloudWatch Logs 的流利位元外掛程式](https://github.com/aws/amazon-cloudwatch-logs-for-fluent-bit/blob/mainline/README.md)。

```
{
	"family": "firelens-example-cloudwatch",
	"taskRoleArn": "arn:aws:iam::123456789012:role/ecs_task_iam_role",
	"containerDefinitions": [
		{
			"essential": true,
			"image": "906394416424.dkr.ecr.us-west-2.amazonaws.com/aws-for-fluent-bit:latest",
			"name": "log_router",
			"firelensConfiguration": {
				"type": "fluentbit"
			},
			"logConfiguration": {
				"logDriver": "awslogs",
				"options": {
					"awslogs-group": "firelens-container",
					"awslogs-region": "us-west-2",
					"awslogs-create-group": "true",
					"awslogs-stream-prefix": "firelens"
				}
			},
			"memoryReservation": 50
		 },
		 {
			 "essential": true,
			 "image": "nginx",
			 "name": "app",
			 "logConfiguration": {
				 "logDriver":"awsfirelens",
				 "options": {
					"Name": "cloudwatch_logs",
					"region": "us-west-2",
					"log_key": "log",
                                 "log_group_name": "/aws/ecs/containerinsights/my-cluster/application",
					"auto_create_group": "true",
					"log_stream_name": "my-task-id"
				}
			},
			"memoryReservation": 100
		}
	]
}
```

# 在 Amazon EKS 和 Kubernetes 上設定 Container Insights
<a name="deploy-container-insights-EKS"></a>

Amazon EKS 1.23 及更新版本支援 Container Insights。只有 1.24 及更新版本支援快速入門安裝方法。

在 Amazon EKS 或 Kubernetes 上設定 Container Insights 的整體程序如下：

1. 確認您已完成必要的事前準備。

1. 在叢集上設定 Amazon CloudWatch 可觀測性 EKS 附加元件、CloudWatch 代理程式或 AWS Distro for OpenTelemetry，以將指標傳送至 CloudWatch。
**注意**  
若要使用 Container Insights 搭配 Amazon EKS 的增強可觀測性，您必須使用 Amazon CloudWatch 可觀測性 EKS 附加元件或 CloudWatch 代理程式。如需有關此 Container Insights 版本的詳細資訊，請參閱 [適用於 Amazon EKS 的具備增強之可觀測性的 Container Insights](container-insights-detailed-metrics.md)。  
若要搭配 Fargate 使用 Container Insights，您必須使用 AWS Distro for OpenTelemetry。Fargate 不支援 Container Insights 搭配 Amazon EKS 的增強可觀測性。
**注意**  
Container Insights 現在支援 Amazon EKS 叢集中的 Windows 工作節點。Windows 也支援適用於 Amazon EKS 的具有增強可觀測性的 Container Insights。如需有關在 Windows 中啟用 Container Insights 的資訊，請參閱 [使用 CloudWatch 代理程式並啟用 Container Insights 增強可觀測性](Container-Insights-EKS-agent.md)。

   若要搭配 OpenTelemetry 指標使用 Container Insights，請安裝 Amazon CloudWatch Observability EKS 附加元件版本 `v6.0.1-eksbuild.1` 或更新版本。如需詳細資訊，請參閱[適用於 Amazon EKS 的 Container Insights 搭配 OpenTelemetry 指標](container-insights-otel-metrics.md)。

   設定 Fluent Bit 或 Fluentd，以將日誌傳送至 CloudWatch Logs。(如果您安裝 Amazon CloudWatch 可觀測性 EKS 附加元件，則預設會啟用。)

   如果您使用的是 CloudWatch 代理程式，您可以在 Quick Start 設定期間一次執行這些步驟，或是個別執行這些作業。

1. (選用) 設定 Amazon EKS 控制平面記錄。

1. (選用) 將 CloudWatch 代理程式設定為叢集上的 StatsD 端點來將 StatsD 指標傳送至 CloudWatch。

1. (選擇性) 啟用 App Mesh Envoy 存取日誌。

使用 Container Insights 的原始版本，收集的指標和擷取的指標會按自訂指標計費。使用 Container Insights 搭配 Amazon EKS 的增強可觀測性，Container Insights 指標和日誌會按觀測，而不是存放或擷取的指標計費。如需 CloudWatch 定價的詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

**Topics**
+ [在 CloudWatch 中驗證 Container Insights 的先決條件](Container-Insights-prerequisites.md)
+ [使用 CloudWatch 代理程式並啟用 Container Insights 增強可觀測性](Container-Insights-EKS-agent.md)
+ [使用 AWS Distro for OpenTelemetry](Container-Insights-EKS-otel.md)
+ [將日誌傳送至 CloudWatch Logs](Container-Insights-EKS-logs.md)
+ [在 Amazon EKS 和 Kubernetes 上更新或刪除 Container Insights](ContainerInsights-update-delete.md)

# 在 CloudWatch 中驗證 Container Insights 的先決條件
<a name="Container-Insights-prerequisites"></a>

在 Amazon EKS 或 Kubernetes 上安裝 Container Insights 前，請檢查下列各項：無論您使用 CloudWatch 代理程式或 AWS Distro for OpenTelemetry 在 Amazon EKS 叢集上設定 Container Insights，這些先決條件都適用。
+ 您擁有可運作的 Amazon EKS 或 Kubernetes 叢集，且其中包含在支援 Amazon EKS 和 Kubernetes Container Insights 的其中一個區域中連接的節點。如需支援區域的清單，請參閱 [Container Insights](ContainerInsights.md)。
+ 您已安裝和執行 `kubectl`。如需詳細資訊，請參閱*《Amazon EKS 使用者指南》*中的[安裝 `kubectl`](https://docs.aws.amazon.com/eks/latest/userguide/install-kubectl.html)。
+ 如果您使用的是在 上執行的 Kubernetes， AWS 而不是使用 Amazon EKS，則還需要下列先決條件：
  + 請確定 Kubernetes 叢集已啟用以角色為基礎的存取控制 (RBAC)。如需詳細資訊，請參閱 Kubernetes 參考中的[使用 RBAC 授權](https://kubernetes.io/docs/reference/access-authn-authz/rbac/)。
  + kubelet 已啟用 Webhook 授權模式。如需詳細資訊，請參閱 Kubernetes 參考中的 [Kubelet authentication/authorization](https://kubernetes.io/docs/reference/access-authn-authz/kubelet-authn-authz/)。

您也必須授與 IAM 許可，讓您的 Amazon EKS 工作節點能夠傳送指標和日誌到 CloudWatch。有兩種方式可以進行：
+ 將政策連接至工作節點的 IAM 角色。這適用於 Amazon EKS 叢集和其他 Kubernetes 叢集。
+ 針對叢集的服務帳戶使用 IAM 角色，並將政策連接至此角色。這僅適用於 Amazon EKS 叢集。

第一個選項會授與 CloudWatch 整個節點的許可，而使用服務帳戶的 IAM 角色只會提供 CloudWatch 適當的 daemonset pod 存取權。

**將政策連接至工作節點的 IAM 角色**

請依照下列步驟將政策連接至工作節點的 IAM 角色。這適用於 Amazon EKS 外部的 Amazon EKS 叢集和 Kubernetes 叢集。

**若要將必要的政策連接至工作節點的 IAM 角色**

1. 前往 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 選取其中一個工作節點執行個體，然後在描述中選擇 IAM 角色。

1. 在 IAM role (IAM 角色) 頁面上，選擇 **Attach policies** (連接政策)。

1. 在政策清單中，選取 **CloudWatchAgentServerPolicy** 旁的核取方塊。如有需要，請使用搜尋方塊來尋找此政策。

1. 選擇**連接政策**。

如果您是在 Amazon EKS 之外執行 Kubernetes 叢集，您可能還沒有將 IAM 角色連接到工作節點。如果不是，您必須依照之前步驟中的說明，先將 IAM 角色連接至該執行個體，然後再新增政策。如需有關將角色連接至執行個體的詳細資訊，請參閱*《Amazon EC2 使用者指南》*中的[將 IAM 角色連接至執行個體](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/iam-roles-for-amazon-ec2.html#attach-iam-role)。

若您是在 Amazon EKS 外部執行 Kubernetes 叢集，且您希望在指標中收集 EBS 磁碟區 ID，您必須將另一個政策新增到連接至執行個體的 IAM 角色。新增以下內容作為內嵌政策。如需詳細資訊，請參閱*《IAM 使用者指南》*中的[新增和移除 IAM 身分許可](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_manage-attach-detach.html)。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
        {
            "Action": [
                "ec2:DescribeVolumes"
            ],
            "Resource": "*",
            "Effect": "Allow"
        }
    ]
}
```

------

**使用 IAM 服務帳戶角色**

此方法僅適用於 Amazon EKS 叢集。

**若要使用 IAM 服務帳戶角色授與 CloudWatch 許可**

1. 如果您尚未這麼做，請為叢集上的服務帳戶啟用 IAM 角色。如需詳細資訊，請參閱[為叢集上的服務帳戶啟用 IAM 角色 ](https://docs.aws.amazon.com/eks/latest/userguide/enable-iam-roles-for-service-accounts.html)。

1. 若尚未就緒，請將服務帳戶設定為使用 IAM 角色。如需詳細資訊，請參閱[設定要擔任 IAM 角色的 Kubernetes 服務帳戶](https://docs.aws.amazon.com/eks/latest/userguide/associate-service-account-role.html)。

   當您建立角色時，除了將 **CloudWatchAgentServerPolicy** IAM 政策連接至您為該角色建立的政策之外，也請連接至該角色。此外，應該在 `amazon-cloudwatch` 命名空間中建立連結至此角色的相關聯 Kubernetes 服務帳戶，其中 CloudWatch 和 Fluent Bit 程式集將在接下來的步驟中部署

1. 如果您尚未這麼做，請將 IAM 角色與叢集中的服務帳戶建立關聯。如需詳細資訊，請參閱[設定要擔任 IAM 角色的 Kubernetes 服務帳戶](https://docs.aws.amazon.com/eks/latest/userguide/associate-service-account-role.html)。

# 使用 CloudWatch 代理程式並啟用 Container Insights 增強可觀測性
<a name="Container-Insights-EKS-agent"></a>

按照下列任一章節中的指示，使用 CloudWatch 代理程式，在 Amazon EKS 叢集或 Kubernetes 叢集上設定 Container Insights。只有 Amazon EKS 1.24 及更新版本支援快速入門指示。

**注意**  
您可遵循下列任何一節中的指示來安裝 Container Insights。您無需遵循所有三組指示。

**Topics**
+ [Amazon CloudWatch Observability EKS 附加元件快速入門](Container-Insights-setup-EKS-addon.md)
+ [Amazon EKS 和 Kubernetes 上 Container Insights 的 Quick Start 設定](Container-Insights-setup-EKS-quickstart.md)
+ [設定 CloudWatch 代理程式以收集叢集指標](Container-Insights-setup-metrics.md)

# Amazon CloudWatch Observability EKS 附加元件快速入門
<a name="Container-Insights-setup-EKS-addon"></a>

您可使用 Amazon EKS 附加元件，來安裝 Container Insights 搭配 Amazon EKS 的增強可觀測性。附加元件會安裝 CloudWatch 代理程式，以從叢集傳送基礎設施指標，並安裝 Fluent Bit 來傳送容器日誌，並啟用 CloudWatch [應用程式訊號](CloudWatch-Application-Monitoring-Sections.md) 來傳送應用程式效能遙測資料。

使用 Amazon EKS 附加元件 1.5.0 版或更新版本時，叢集中的 Linux 和 Windows 工作節點上都會啟用 Container Insights。Amazon EKS 中的 Windows 不支援 Application Signals。

若叢集執行於 Kubernetes 而非 Amazon EKS，則不支援 Amazon EKS 附加元件。

如需有關 Amazon CloudWatch 可觀測性 EKS 附加元件的詳細資訊，請參閱 [使用 Amazon CloudWatch Observability EKS 附加元件或 Helm Chart 安裝 CloudWatch 代理程式](install-CloudWatch-Observability-EKS-addon.md)。

如果您使用 3.1.0 或更高版本的附加元件，可以使用 EKS Pod 身分識別將必要的許可授與附加元件。EKS Pod 身分識別是建議的選項，並提供最低權限、憑證輪換和可稽核性等優點。此外，使用 EKS Pod 身分識別可讓您在建立叢集的過程中安裝 EKS 附加元件。

**安裝 Amazon CloudWatch Observability EKS 附加元件**

1. 請遵循 [EKS Pod 身分識別關聯](https://docs.aws.amazon.com/eks/latest/userguide/pod-id-association.html#pod-id-association-create/)步驟來建立 IAM 角色並設定 EKS Pod 身分識別代理程式。

1. 連接 IAM 政策，將必要許可授與您的角色。將 *my-role* 取代為上一步驟中的 IAM 角色名稱。

   ```
   aws iam attach-role-policy \
    --role-name my-role \
   --policy-arn=arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy
   ```

1. 輸入下列命令，使用您在上一個步驟中建立的 IAM 角色：

   ```
   aws eks create-addon \
   --addon-name amazon-cloudwatch-observability \
   --cluster-name my-cluster-name \
   --pod-identity-associations serviceAccount=cloudwatch-agent,roleArn=arn:aws:iam::111122223333:role/my-role
   ```

# Amazon EKS 和 Kubernetes 上 Container Insights 的 Quick Start 設定
<a name="Container-Insights-setup-EKS-quickstart"></a>

**重要**  
如果您要在 Amazon EKS 叢集上安裝 Container Insights，建議您使用 Amazon CloudWatch 可觀測性 EKS 附加元件進行安裝，而不是使用本節中的指示。此外，若要擷取加速運算網路，必須使用 Amazon CloudWatch Observability EKS 附加元件。如需詳細資訊和指示，請參閱[Amazon CloudWatch Observability EKS 附加元件快速入門](Container-Insights-setup-EKS-addon.md)。

若要完成設定容器洞見，您可以遵循本節中的 quick start 說明。如果您要在 Amazon EKS 叢集中進行安裝，並且在 2023 年 11 月 6 日或之後使用本節中的指示，則您可在叢集中安裝 Container Insights 搭配 Amazon EKS 的增強可觀測性。

**重要**  
在完成本節中的步驟前，您必須先驗證包括 IAM 許可在內的先決條件。如需詳細資訊，請參閱[在 CloudWatch 中驗證 Container Insights 的先決條件](Container-Insights-prerequisites.md)。

或者，您可以改為遵循下列兩節中的說明：[設定 CloudWatch 代理程式以收集叢集指標](Container-Insights-setup-metrics.md) 和 [將日誌傳送至 CloudWatch Logs](Container-Insights-EKS-logs.md)。這兩節提供更多 CloudWatch 代理程式搭配 Amazon EKS 及 Kubernetes 運作方式的組態詳細資訊，但需要您執行更多安裝步驟。

使用 Container Insights 的原始版本，收集的指標和擷取的指標會按自訂指標計費。使用 Container Insights 搭配 Amazon EKS 的增強可觀測性，Container Insights 指標和日誌會按觀測，而不是存放或擷取的指標計費。如需 CloudWatch 定價的詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

**注意**  
Amazon 現已推出 Fluent Bit 作為 Container Insights 的預設日誌解決方案，且效能大幅提升。我們建議您使用 Fluent Bit 而不是 Fluentd。

## CloudWatch 代理程式運算子和 Fluent Bit 的快速入門
<a name="Container-Insights-setup-EKS-quickstart-FluentBit"></a>

Fluent Bit 有兩種組態：最佳化版本和提供更類似於 Fluentd 體驗的版本。Quick Start 組態使用最佳化版本。如需 Fluentd 相容組態的詳細資訊，請參閱「[將 Fluent Bit 設定為 DaemonSet 以將日誌傳送至 CloudWatch Logs](Container-Insights-setup-logs-FluentBit.md)」。

CloudWatch 代理程式運算子是安裝到 Amazon EKS 叢集的額外容器。它以 Kubernetes 的 OpenTelemetry Operator 為藍本。運算子會管理叢集中 Kubernetes 資源的生命週期。它會在 Amazon EKS 叢集上安裝 CloudWatch Agent、DCGM Exporter (NVIDIA) 和 AWS Neuron Monitor，並進行管理。Fluent Bit 和適用於 Windows 的 CloudWatch 代理程式會直接安裝到 Amazon EKS 叢集，操作員無需進行管理。

對於更安全且功能更豐富的憑證授權機構解決方案，CloudWatch 代理程式運算子需要 cert-manager，這是 Kubernetes 中廣泛採用的 TLS 憑證管理解決方案。使用 cert-manager 可簡化獲取、續約、管理和使用這些憑證的程序。它可確保憑證有效且為最新版本，並在到期前嘗試在設定的時間內續約憑證。cert-manager 也協助從各種支援的來源發行憑證，包括 AWS Certificate Manager Private Certificate Authority。

**若要使用快速入門來部署 Container Insights**

1. 如果尚未在叢集中安裝 cert-manager，請進行安裝。如需詳細資訊，請參閱 [cert-manager 安裝](https://cert-manager.io/docs/installation/)。

1. 輸入下列命令來安裝自訂資源定義 (CRD)。

   ```
   curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/main/k8s-quickstart/cwagent-custom-resource-definitions.yaml | kubectl apply --server-side -f -
   ```

1. 輸入下列命令來安裝運算子。將 *my-cluster-name* 取代為 Amazon EKS 或 Kubernetes 叢集的名稱，將 *my-cluster-region* 取代為發布日誌的區域名稱。我們建議您使用部署叢集的相同區域，以降低 AWS 傳出資料傳輸成本。

   ```
   ClusterName=my-cluster-name
   RegionName=my-cluster-region
   curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/main/k8s-quickstart/cwagent-operator-rendered.yaml | sed 's/{{cluster_name}}/'${ClusterName}'/g;s/{{region_name}}/'${RegionName}'/g' | kubectl apply -f -
   ```

   例如，若要在名為 `MyCluster` 的叢集上部署 Container Insights，並將日誌和指標發布至美國西部 (奧勒岡)，請輸入以下命令。

   ```
   ClusterName='MyCluster'
   RegionName='us-west-2'
   curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/main/k8s-quickstart/cwagent-operator-rendered.yaml | sed 's/{{cluster_name}}/'${ClusterName}'/g;s/{{region_name}}/'${RegionName}'/g' | kubectl apply -f -
   ```

**從 Container Insights 中移轉**

如果已在 Amazon EKS 叢集中設定 Container Insights，並且想要移轉至適合 Amazon EKS 的具有增強可觀測性的 Container Insights，請參閱 [在 CloudWatch 中針對 Amazon EKS 升級至具有增強可觀測性的 Container Insights](Container-Insights-upgrade-enhanced.md)

**刪除容器洞見**

若您希望在使用快速入門設定後移除 Container Insights，請輸入以下命令。

```
ClusterName=my-cluster-name 
RegionName=my-cluster-region
curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/main/k8s-quickstart/cwagent-operator-rendered.yaml | sed 's/{{cluster_name}}/'${ClusterName}'/g;s/{{region_name}}/'${RegionName}'/g' | kubectl delete -f -
curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/main/k8s-quickstart/cwagent-custom-resource-definitions.yaml | kubectl delete -f -
```

# 設定 CloudWatch 代理程式以收集叢集指標
<a name="Container-Insights-setup-metrics"></a>

**重要**  
如果您要在 Amazon EKS 叢集上安裝 Container Insights，建議您使用 Amazon CloudWatch 可觀測性 EKS 附加元件進行安裝，而不是使用本節中的指示。如需詳細資訊和指示，請參閱[Amazon CloudWatch Observability EKS 附加元件快速入門](Container-Insights-setup-EKS-addon.md)。

若要設定容器洞見收集指標，您可以遵循 [Amazon EKS 和 Kubernetes 上 Container Insights 的 Quick Start 設定](Container-Insights-setup-EKS-quickstart.md) 中的步驟，或是遵循本節中的步驟。在下列步驟中，您會將 CloudWatch 代理程式設為能夠從叢集收集指標。

如果您要在 Amazon EKS 叢集中進行安裝，並且在 2023 年 11 月 6 日或之後使用本節中的指示，則您可在叢集中安裝 Container Insights 搭配 Amazon EKS 的增強可觀測性。

## 步驟 1：建立 CloudWatch 的命名空間
<a name="create-namespace-metrics"></a>

使用以下步驟，為 CloudWatch 建立名為 `amazon-cloudwatch` 的 Kubernetes 命名空間。如果您已建立此命名空間，則可以略過此步驟。

**若要建立 CloudWatch 的命名空間**
+ 輸入以下命令。

  ```
  kubectl apply -f https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/cloudwatch-namespace.yaml
  ```

## 步驟 2：在叢集中建立服務帳戶
<a name="create-service-account"></a>

如果還沒有服務帳戶，請使用以下其中一種方法，為 CloudWatch 代理程式建立一個。
+ 使用 `kubectl`
+ 使用 `kubeconfig` 檔案

### 使用 `kubectl` 進行身分驗證
<a name="use-kubectl"></a>

**若要使用 `kubectl` 為 CloudWatch 代理程式建立服務帳戶**
+ 輸入以下命令。

  ```
  kubectl apply -f https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/cwagent/cwagent-serviceaccount.yaml
  ```

如果您沒有遵循之前的步驟，但您已擁有可供要使用的 CloudWatch 代理程式使用的服務帳戶，您必須確認該帳戶具有下列規則。此外，在容器洞見安裝中的其他步驟，您必須使用該服務帳戶的名稱，而不是 `cloudwatch-agent`。

```
rules:
  - apiGroups: [""]
    resources: ["pods", "nodes", "endpoints"]
    verbs: ["list", "watch"]
  - apiGroups: [ "" ]
    resources: [ "services" ]
    verbs: [ "list", "watch" ]
  - apiGroups: ["apps"]
    resources: ["replicasets", "daemonsets", "deployments", "statefulsets"]
    verbs: ["list", "watch"]
  - apiGroups: ["batch"]
    resources: ["jobs"]
    verbs: ["list", "watch"]
  - apiGroups: [""]
    resources: ["nodes/proxy"]
    verbs: ["get"]
  - apiGroups: [""]
    resources: ["nodes/stats", "configmaps", "events"]
    verbs: ["create", "get"]
  - apiGroups: [""]
    resources: ["configmaps"]
    resourceNames: ["cwagent-clusterleader"]
    verbs: ["get","update"]
  - nonResourceURLs: ["/metrics"]
    verbs: ["get", "list", "watch"]
  - apiGroups: [ "discovery.k8s.io" ]
    resources: [ "endpointslices" ]
    verbs: [ "list", "watch", "get" ]
```

### 使用 `kubeconfig` 進行身分驗證
<a name="use-kubeconfig"></a>

或者，可以使用 `kubeconfig` 檔案進行身分驗證。此方法允許您透過直接在 CloudWatch 代理程式組態中指定 `kubeconfig` 路徑，跳過服務帳戶 b 的需求。它還允許您移除對 Kubernetes 控制平面 API 進行身分驗證的相依性，透過 kubeconfig 檔案管理身分驗證，簡化設定並可能提高安全性。

若要使用此方法，請更新您的 CloudWatch 代理程式組態檔案，以指定 `kubeconfig` 檔案的路徑，如下列範例所示。

```
{
  "logs": {
    "metrics_collected": {
      "kubernetes": {
        "cluster_name": "YOUR_CLUSTER_NAME",
        "enhanced_container_insights": false,
        "accelerated_compute_metrics": false,
        "tag_service": false,
        "kube_config_path": "/path/to/your/kubeconfig" 
        "host_ip": "HOSTIP"
      }
    }
  }
}
```

若要建立 `kubeconfig` 檔案，請使用 `system:masters` Kubernetes 角色為 `admin/{create_your_own_user}` 使用者建立憑證簽署請求 (CSR)。然後使用 Kubernetes 叢集的憑證授權機構 (CA) 進行簽署並建立 `kubeconfig` 檔案。

## 步驟 3：為 CloudWatch 代理程式建立 ConfigMap
<a name="create-configmap"></a>

使用下列步驟來為 CloudWatch 代理程式建立 ConfigMap。

**若要為 CloudWatch 代理程式建立 ConfigMap**

1. 透過執行下列命令，將 ConfigMap YAML 下載到 `kubectl` 用戶端主機：

   ```
   curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/cwagent/cwagent-configmap-enhanced.yaml
   ```

1. 編輯已下載的 YAML 檔案，如下所示：
   + **cluster\$1name** – 在 `kubernetes` 區段，將 `{{cluster_name}}` 取代為叢集的名稱。移除 `{{}}` 字元。或者，如果您使用的是 Amazon EKS 叢集，您可以刪除 `"cluster_name"` 欄位和值。如果您這麼做，CloudWatch 代理程式會透過 Amazon EC2 標籤偵測叢集名稱。

1. (選用) 根據您的監控要求對 ConfigMap 進行進一步變更，如下所示：
   + **metrics\$1collection\$1interval** – 在 `kubernetes` 區段，您可以指定代理程式收集指標的頻率。預設值為 60 秒。kubelet 中的預設 cadvisor 收集間隔是 15 秒，所以請不要將這個值設定為少於 15 秒。
   + **endpoint\$1override** 如果您想要覆寫預設端點，您可以在 `logs` 區段指定 CloudWatch Logs 端點。如果您透過 VPC 中的叢集進行發布，且您想要將資料送往 VPC 端點，建議您這麼做。
   + **force\$1flush\$1interval** 您可以在 `logs` 區段指定將日誌事件發布至 CloudWatch Logs 前，對日誌事件進行批次處理的間隔。預設為 5 秒。
   + **region** – 在預設情況下，代理程式會將指標發布至工作節點所在的區域。若要覆寫這個值，您可以在 `agent` 區段新增 `region` 欄位：例如，`"region":"us-west-2"`。
   + **statsd** 區段 – 如果您希望 CloudWatch Logs 代理程式在叢集的每個工作節點中以 StatsD 接聽程式的身分執行，您可以將 `statsd` 區段新增至 `metrics` 區段，如以下範例所示。如需此區段其他 StatsD 選項的資訊，請參閱 [使用 StatsD 擷取自訂指標](CloudWatch-Agent-custom-metrics-statsd.md)。

     ```
     "metrics": {
       "metrics_collected": {
         "statsd": {
           "service_address":":8125"
         }
       }
     }
     ```

     JSON 區段的完整範例如下。如果使用 `kubeconfig` 檔案進行身分驗證，請新增 `kube_config_path` 參數來指定 kubeconfig 檔案的路徑。

     ```
     {
         "agent": {
             "region": "us-east-1"
         },
         "logs": {
             "metrics_collected": {
                 "kubernetes": {
                     "cluster_name": "MyCluster",
                     "metrics_collection_interval": 60,
                     "kube_config_path": "/path/to/your/kubeconfig" //if using kubeconfig for authentication
                 }
             },
             "force_flush_interval": 5,
             "endpoint_override": "logs.us-east-1.amazonaws.com"
         },
         "metrics": {
             "metrics_collected": {
                 "statsd": {
                     "service_address": ":8125"
                 }
             }
         }
     }
     ```

1. 透過執行以下命令在叢集中建立 ConfigMap。

   ```
   kubectl apply -f cwagent-configmap-enhanced.yaml
   ```

## 步驟 4：將 CloudWatch 代理程式部署為 DaemonSet
<a name="deploy-agent-yaml"></a>

若要完成 CloudWatch 代理程式的安裝並開始收集容器指標，請使用下列步驟。

**若要將 CloudWatch 代理程式部署為 DaemonSet**

1. 
   + 如果您不希望在叢集上使用 StatsD，請輸入以下命令。

     ```
     kubectl apply -f https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/cwagent/cwagent-daemonset.yaml
     ```
   + 若您希望使用 StatsD，請遵循下列步驟：

     1. 透過執行以下命令，將 DaemonSet YAML 下載到 `kubectl` 用戶端主機。

        ```
        curl -O  https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/cwagent/cwagent-daemonset.yaml
        ```

     1. 取消 `cwagent-daemonset.yaml` 檔案中 `port` 區段的註解，如下所示：

        ```
        ports:
          - containerPort: 8125
            hostPort: 8125
            protocol: UDP
        ```

     1. 透過執行以下命令在叢集中部署 CloudWatch 代理程式。

        ```
        kubectl apply -f cwagent-daemonset.yaml
        ```

     1. 透過執行以下命令在叢集中的 Windows 節點上部署 CloudWatch 代理程式。Windows 上的 CloudWatch 代理程式不支援 StatsD 接聽程式。

        ```
        kubectl apply -f cwagent-daemonset-windows.yaml
        ```

1. 透過執行下列命令確認已部署代理程式。

   ```
   kubectl get pods -n amazon-cloudwatch
   ```

完成後，CloudWatch 代理程式會建立名為 `/aws/containerinsights/Cluster_Name/performance` 的日誌群組，並將效能日誌事件傳送到這個日誌群組。如果您也將代理程式設定為 StatsD 接聽程式，此代理程式也會使用應用程式 pod 排定所在的節點 IP 地址，來接聽連接埠 8125 上的 StatsD 指標。

### 疑難排解
<a name="ContainerInsights-deploy-troubleshooting"></a>

如果代理程式未正確部署，請嘗試下列項目：
+ 執行以下命令來取得 Pod 清單。

  ```
  kubectl get pods -n amazon-cloudwatch
  ```
+ 執行以下命令和檢查輸出底部的事件。

  ```
  kubectl describe pod pod-name -n amazon-cloudwatch
  ```
+ 執行以下命令來檢查日誌。

  ```
  kubectl logs pod-name  -n amazon-cloudwatch
  ```

# 使用 AWS Distro for OpenTelemetry
<a name="Container-Insights-EKS-otel"></a>

您可以設定 Container Insights，以使用 AWS Distro for OpenTelemetry 收集器來收集 Amazon EKS 叢集中的指標。如需 AWS Distro for OpenTelemetry 的詳細資訊，請參閱 [AWS Distro for OpenTelemetry](https://aws.amazon.com/otel/)。

**重要**  
如果您使用 AWS Distro for OpenTelemetry 安裝 ，則會安裝 Container Insights，但不會取得具有 Amazon EKS 增強可觀測性的 Container Insights。您不會在 Container Insights 搭配 Amazon EKS 的增強可觀測性中收集支援的詳細指標。

Container Insights 的設定方式取決於叢集是託管在 Amazon EC2 執行個體還是 AWS Fargate上。

## 託管於 Amazon EC2 的 Amazon EKS 叢集
<a name="Container-Insights-EKS-otel-EC2"></a>

如果您尚未這樣做，請確定您已滿足包含必要 IAM 角色在內的先決條件。如需詳細資訊，請參閱[在 CloudWatch 中驗證 Container Insights 的先決條件](Container-Insights-prerequisites.md)。

Amazon 提供了 Helm Chart，您可以使用此功能來設定監控 Amazon EC2 上的 Amazon Elastic Kubernetes Service。此監控會將 AWS Distro for OpenTelemetry (ADOT) 收集器用於指標，並將 Fluent Bit 用於日誌。因此，Helm Chart 對於在 Amazon EC2 上使用 Amazon EKS 並希望收集指標和日誌以傳送到 CloudWatch Container Insights 的客戶非常有用。如需此 Helm Chart 的詳細資訊，請參閱[用於將 EC2 上的 EKS 指標和日誌傳送到 Amazon CloudWatch Container Insights 的 ADOT Helm Chart](https://github.com/aws-observability/aws-otel-helm-charts/tree/main/charts/adot-exporter-for-eks-on-ec2)。

或者，您也可以使用本節其他部分中的說明。

首先，輸入下列命令，將 AWS Distro for OpenTelemetry 收集器部署為 DaemonSet。

```
curl https://raw.githubusercontent.com/aws-observability/aws-otel-collector/main/deployment-template/eks/otel-container-insights-infra.yaml |
kubectl apply -f -
```

若要確認收集器正在執行中，請輸入下列命令。

```
kubectl get pods -l name=aws-otel-eks-ci -n aws-otel-eks
```

如果此命令的輸出中包括多個處於 `Running` 狀態的 pod，則收集器正在執行並從叢集收集指標。收集器會建立名為 `aws/containerinsights/cluster-name/performance` 的日誌群組，並將效能日誌事件傳送給它。

如需如何在 CloudWatch 中查看 Container Insights 指標的詳細資訊，請參閱 [檢視 Container Insights 指標](Container-Insights-view-metrics.md)。

AWS 也提供此案例的 GitHub 文件。如果您想要自訂 Container Insights 發布的指標和日誌，請參閱 [https://aws-otel.github.io/docs/getting-started/container-insights/eks-infra](https://aws-otel.github.io/docs/getting-started/container-insights/eks-infra)。

## 託管於 Fargate 的 Amazon EKS 叢集
<a name="Container-Insights-EKS-otel-Fargate"></a>

如需如何設定和部署 ADOT 收集器以從部署到 Fargate 上 Amazon EKS 叢集的工作負載收集系統指標，並將其傳送至 CloudWatch Container Insights 的說明，請參閱 AWS Distro for OpenTelemetry 文件中的 [Container Insights EKS Fargate](https://aws-otel.github.io/docs/getting-started/container-insights/eks-fargate)。

# 將日誌傳送至 CloudWatch Logs
<a name="Container-Insights-EKS-logs"></a>

若要將日誌從容器傳送至 Amazon CloudWatch Logs，您可以使用 Fluent Bit。如需詳細資訊，請參閱 [Fluent Bit](https://fluentbit.io/)。

**注意**  
截至 2025 年 2 月 10 日， AWS 已棄用對 FluentD 做為 CloudWatch Logs 日誌轉送者的支援。建議您使用 Fluent Bit，這是輕量且資源高效的替代方案。現有的 FluentD 部署將繼續運作。將日誌記錄管道移轉至 Fluent Bit，以確保持續支援和最佳效能。  
Container Insights 先前也支援使用 FluentD 從您的容器中傳送日誌。FluentD 已被棄用，現在 Container Insights 不支援。請改用 Fluent Bit。

**Topics**
+ [將 Fluent Bit 設定為 DaemonSet 以將日誌傳送至 CloudWatch Logs](Container-Insights-setup-logs-FluentBit.md)
+ [(選用) 設定 Amazon EKS 控制平面記錄。](Container-Insights-setup-control-plane-logging.md)
+ [(選用) 針對大型叢集啟用 Use\$1Kubelet 功能](ContainerInsights-use-kubelet.md)

# 將 Fluent Bit 設定為 DaemonSet 以將日誌傳送至 CloudWatch Logs
<a name="Container-Insights-setup-logs-FluentBit"></a>

下列各節可協助您部署 Fluent Bit，以將日誌從容器傳送至 CloudWatch Logs。

**Topics**
+ [設定 Fluent Bit](#Container-Insights-FluentBit-setup)
+ [多行日誌支援](#ContainerInsights-fluentbit-multiline)
+ [(選用) 減少 FluentD 的日誌量](#ContainerInsights-fluentbit-volume)
+ [疑難排解](#Container-Insights-FluentBit-troubleshoot)
+ [儀表板](#Container-Insights-FluentBit-dashboard)

## 設定 Fluent Bit
<a name="Container-Insights-FluentBit-setup"></a>

若要設定 Fluent Bit 以從您的容器收集日誌，您可以遵循 [Amazon EKS 和 Kubernetes 上 Container Insights 的 Quick Start 設定](Container-Insights-setup-EKS-quickstart.md) 中的步驟，或是遵循本節中的步驟。

無論使用何種方法，連接至叢集節點的 IAM 角色皆必須具有足夠的權限。如需有關執行 Amazon EKS 叢集所需許可的詳細資訊，請參閱*《Amazon EKS 使用者指南》*中的 [Amazon EKS IAM 政策、角色和許可](https://docs.aws.amazon.com/eks/latest/userguide/IAM_policies.html)。

在下列步驟中，您可以將 Fluent Bit 設為 DaemonSet 來將日誌傳送到 CloudWatch Logs。完成此步驟時，Fluent Bit 會建立下列日誌群組 (若尚未存在的話)。

**重要**  
如果您已在 Container Insights 中設定了 Fluentd，且 Fluentd DaemonSet 未如預期般執行 (如果您使用 `containerd` 執行期，則可能出現這種情況)，您必須先將其解除安裝，才能安裝 Fluent Bit，防止 Fluent Bit 處理 Fluentd 錯誤日誌訊息。否則，您必須在成功安裝 Fluent Bit 之後立即解除安裝 Fluentd。在安裝 Fluent Bit 後解除安裝 Fluentd，可確保在此移轉過程中記錄的唯一性。只需 Fluent Bit 或 Fluentd 其一即可將日誌傳送到 CloudWatch Logs。


| 日誌群組名稱 | 日誌來源 | 
| --- | --- | 
|  `/aws/containerinsights/Cluster_Name/application`  |  `/var/log/containers` 中所有日誌檔  | 
|  `/aws/containerinsights/Cluster_Name/host`  |  來自 `/var/log/dmesg`、`/var/log/secure` 以及 `/var/log/messages` 的日誌  | 
|  `/aws/containerinsights/Cluster_Name/dataplane`  |  `/var/log/journal` 中適用於 `kubelet.service`、`kubeproxy.service` 和 `docker.service` 的日誌。  | 

**若要安裝 Fluent Bit 以將日誌從容器傳送至 CloudWatch Logs**

1. 如果您還沒有名為 `amazon-cloudwatch` 的命名空間，請輸入下列命令建立一個：

   ```
   kubectl apply -f https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/cloudwatch-namespace.yaml
   ```

1. 執行下列命令以建立為 `cluster-info` 的 ConfigMap，並提供叢集名稱和要傳送日誌到其中的區域。將 *cluster-name* 和 *cluster-region* 替換成您叢集的名稱和區域。

   ```
   ClusterName=cluster-name
   RegionName=cluster-region
   FluentBitHttpPort='2020'
   FluentBitReadFromHead='Off'
   [[ ${FluentBitReadFromHead} = 'On' ]] && FluentBitReadFromTail='Off'|| FluentBitReadFromTail='On'
   [[ -z ${FluentBitHttpPort} ]] && FluentBitHttpServer='Off' || FluentBitHttpServer='On'
   kubectl create configmap fluent-bit-cluster-info \
   --from-literal=cluster.name=${ClusterName} \
   --from-literal=http.server=${FluentBitHttpServer} \
   --from-literal=http.port=${FluentBitHttpPort} \
   --from-literal=read.head=${FluentBitReadFromHead} \
   --from-literal=read.tail=${FluentBitReadFromTail} \
   --from-literal=logs.region=${RegionName} -n amazon-cloudwatch
   ```

   在這個命令中， 用於監控外掛程式指標的 `FluentBitHttpServer` 預設為開啟。若要將其關閉，請將命令中的第三行變更為 `FluentBitHttpPort=''` (空字串)。

   此外，依預設，Fluent Bit 從尾部讀取日誌檔案，並將僅擷取部署後的新日誌。如果您想要相反結果，請設定 `FluentBitReadFromHead='On'`，它將收集檔案系統中的所有日誌。

1. 透過執行以下其中一個命令，下載 Fluent Bit daemonset 並將其部署到叢集。
   + 如果想要為 Linux 計算機最佳化 Fluent Bit 組態，請執行此命令。

     ```
     kubectl apply -f https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/fluent-bit/fluent-bit.yaml
     ```
   + 如果想要為 Linux 計算機最佳化 Fluent Bit 組態，請執行此命令。

     ```
     kubectl apply -f https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/fluent-bit/fluent-bit-windows.yaml
     ```
   + 如果使用 Linux 計算機，並想要更類似於 Fluentd 的 Fluent Bit 組態，請執行此命令。

     ```
     kubectl apply -f https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/fluent-bit/fluent-bit-compatible.yaml
     ```
**重要**  
依預設，Fluent Bit daemonset 組態會將日誌層級設定為 INFO，這可能會導致 CloudWatch Logs 擷取成本較高。如果您想要減少日誌擷取量和成本，可以將日誌層級變更為 ERROR。  
如需如何減少日誌量的詳細資訊，請參閱 [(選用) 減少 FluentD 的日誌量](#ContainerInsights-fluentbit-volume)。

1. 透過輸入以下命令來驗證部署。每個節點應有一個名為 **fluent-bit-\$1** 的 pod。

   ```
   kubectl get pods -n amazon-cloudwatch
   ```

上述步驟在叢集中建立下列資源：
+ 在 `amazon-cloudwatch` 命名空間中名為 `Fluent-Bit` 的服務帳戶。此服務帳戶會用來執行 Fluent Bit daemonSet。如需詳細資訊，請參閱 Kubernetes 參考中的[管理服務帳戶](https://kubernetes.io/docs/reference/access-authn-authz/service-accounts-admin/)。
+ 在 `amazon-cloudwatch` 命名空間中名為的 `Fluent-Bit-role` 叢集角色。此叢集角色會在 pod 日誌上將 `get`、`list` 和 `watch` 許可授予給 `Fluent-Bit` 服務帳戶。如需詳細資訊，請參閱 Kubernetes 參考中的 [API 概觀](https://kubernetes.io/docs/reference/access-authn-authz/rbac/#api-overview/)。
+ `amazon-cloudwatch` 命名空間中名為 `Fluent-Bit-config` 的 ConfigMap。此 ConfigMap 包含 Fluent Bit 使用的組態。如需詳細資訊，請參閱 Kubernetes 任務文件中的[將 Pod 設定為使用 ConfigMap](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/)。

如果您想要驗證您的 Fluent Bit 設定，請遵循下列步驟。

**驗證 Fluent Bit 設定**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇 **Log groups** (日誌群組)。

1. 請確定您位於部署 Fluent Bit 的區域。

1. 檢查區域中的日誌群組清單。請查看下列事項：
   + `/aws/containerinsights/Cluster_Name/application`
   + `/aws/containerinsights/Cluster_Name/host`
   + `/aws/containerinsights/Cluster_Name/dataplane`

1. 導覽至其中一個記錄群組，然後勾選日誌串流的 **Last Event Time** (上次事件時間)。如果它相對於您部署 Fluent Bit 的時間更近，則設定已受驗證。

   建立 `/dataplane` 日誌群組時可能會略微存在延遲。這是正常的，因為只有在 Fluent Bit 開始為該日誌組傳送日誌時，才會建立這些日誌群組。

## 多行日誌支援
<a name="ContainerInsights-fluentbit-multiline"></a>

如需如何搭配多行日誌使用 Fluent Bit 的詳細資訊，請參閱 Fluent Bit 文件的下列章節：
+ [Multiline Parsing](https://docs.fluentbit.io/manual/administration/configuring-fluent-bit/multiline-parsing)
+ [Multiline and Containers (v1.8)](https://docs.fluentbit.io/manual/pipeline/inputs/tail#multiline-and-containers-v1.8)
+ [Multiline Core (v1.8)](https://docs.fluentbit.io/manual/pipeline/inputs/tail#multiline-core-v1.8)
+ [Always use multiline in the tail input](https://github.com/aws/aws-for-fluent-bit/blob/mainline/troubleshooting/debugging.md#always-use-multiline-the-tail-input)

## (選用) 減少 FluentD 的日誌量
<a name="ContainerInsights-fluentbit-volume"></a>

根據預設，我們會將 Fluent Bit 應用程式日誌和 Kubernetes 中繼資料傳送到 CloudWatch。若您希望減少傳送到 CloudWatch 的資料量，您可以停止其中一個，或同時停止這兩個資料來源傳送到 CloudWatch。如果已遵循此頁面上的步驟來設定 Fluent Bit，請從先前執行的 kubectl `apply` 命令下載 Kubernetes 資訊清單 YAML 檔案，並使用變更進行修改，然後可以重新套用至叢集。或者，如果您使用的是 Amazon CloudWatch Observability EKS 附加元件或 Helm Chart，請參閱 [(選用) 額外組態](install-CloudWatch-Observability-EKS-addon.md#install-CloudWatch-Observability-EKS-addon-configuration) 以取得有關使用附加元件進階組態或 Helm Chart 來管理 Fluent Bit 組態的資訊。

若要停止 Fluent Bit 應用程式日誌，請從 `Fluent Bit configuration` 檔案移除以下區段。

```
[INPUT]
        Name                tail
        Tag                 application.*
        Path                /var/log/containers/fluent-bit*
        Parser              docker
        DB                  /fluent-bit/state/flb_log.db
        Mem_Buf_Limit       5MB
        Skip_Long_Lines     On
        Refresh_Interval    10
```

若要移除 Kubernetes 中繼資料，使其不會附加到傳送至 CloudWatch 的日誌事件，請將下列篩選條件新增到 Fluent Bit 組態的 `application-log.conf` 區段。將 *<Metadata\$11>* 和類似欄位取代為實際中繼資料識別符。

```
application-log.conf: |
    [FILTER]
        Name                nest
        Match               application.*
        Operation           lift
        Nested_under        kubernetes
        Add_prefix          Kube.

    [FILTER]
        Name                modify
        Match               application.*
        Remove              Kube.<Metadata_1>
        Remove              Kube.<Metadata_2>
        Remove              Kube.<Metadata_3>
    
    [FILTER]
        Name                nest
        Match               application.*
        Operation           nest
        Wildcard            Kube.*
        Nested_under        kubernetes
        Remove_prefix       Kube.
```

## 疑難排解
<a name="Container-Insights-FluentBit-troubleshoot"></a>

如果您沒有看到這些日誌群組，且在正確的區域中尋找，請檢查日誌是否有 Fluent Bit daemonSet pod 以尋找錯誤。

執行以下命令並確保狀態為 `Running`。

```
kubectl get pods -n amazon-cloudwatch
```

如果日誌有與 IAM 許可相關的錯誤，請確認 IAM 角色是否已連接到叢集節點。如需有關執行 Amazon EKS 叢集所需許可的詳細資訊，請參閱*《Amazon EKS 使用者指南》*中的 [Amazon EKS IAM 政策、角色和許可](https://docs.aws.amazon.com/eks/latest/userguide/IAM_policies.html)。

如果 pod 狀態為 `CreateContainerConfigError`，透過執行以下命令以取得確切的錯誤。

```
kubectl describe pod pod_name -n amazon-cloudwatch
```

## 儀表板
<a name="Container-Insights-FluentBit-dashboard"></a>

您可以建立一個儀表板來監控每個正在執行的外掛程式的指標。您可以查看輸入和輸出位元組、記錄處理速率以及輸出錯誤和重試/失敗率的資料。若要檢視這些指標，您需要安裝具有適用於 Amazon EKS 和 Kubernetes 叢集的 Prometheus 指標集合的 CloudWatch 代理程式。如需如何設定儀表板的詳細資訊，請參閱 [在 Amazon EKS 和 Kubernetes 叢集上安裝具有 Prometheus 指標集合的 CloudWatch 代理程式。在 Amazon EKS 和 Kubernetes 叢集上安裝具有 Prometheus 指標集合的 CloudWatch 代理程式。](ContainerInsights-Prometheus-Setup.md)。

**注意**  
您必須先設定 Prometheus 指標的 Container Insights，才能設定此儀表板。如需詳細資訊，請參閱[Container Insights Prometheus 指標監控](ContainerInsights-Prometheus.md)。

**若要建立 Fluent Bit Prometheus 指標的儀表板**

1. 建立環境變數，取代下列幾行中右側的數值，以符合您的部署。

   ```
   DASHBOARD_NAME=your_cw_dashboard_name
   REGION_NAME=your_metric_region_such_as_us-west-1
   CLUSTER_NAME=your_kubernetes_cluster_name
   ```

1. 執行以下命令建立儀表板。

   ```
   curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/sample_cloudwatch_dashboards/fluent-bit/cw_dashboard_fluent_bit.json \
   | sed "s/{{YOUR_AWS_REGION}}/${REGION_NAME}/g" \
   | sed "s/{{YOUR_CLUSTER_NAME}}/${CLUSTER_NAME}/g" \
   | xargs -0 aws cloudwatch put-dashboard --dashboard-name ${DASHBOARD_NAME} --dashboard-body
   ```

# (選用) 設定 Amazon EKS 控制平面記錄。
<a name="Container-Insights-setup-control-plane-logging"></a>

如果您使用的是 Amazon EKS，您可以選擇啟用 Amazon EKS 控制平面記錄，以從 Amazon EKS 控制平面將稽核和診斷日誌直接提供至 CloudWatch Logs。如需詳細資訊，請參閱 [Amazon EKS 控制平面記錄](https://docs.aws.amazon.com/eks/latest/userguide/control-plane-logs.html)。

# (選用) 針對大型叢集啟用 Use\$1Kubelet 功能
<a name="ContainerInsights-use-kubelet"></a>

根據預設，系統會在外掛程式中停用 Use\$1Kubelet 功能。啟用此功能可減少 API 伺服器的流量，並減輕 API 伺服器的瓶頸問題。建議您針對大型叢集啟用此功能。

若要啟用 Use\$1Kubelet，請先將節點和節點/代理許可新增至 clusterRole 組態。

```
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: fluent-bit-role
rules:
  - nonResourceURLs:
      - /metrics
    verbs:
      - get
  - apiGroups: [""]
    resources:
      - namespaces
      - pods
      - pods/logs
      - nodes
      - nodes/proxy
    verbs: ["get", "list", "watch"]
```

在 DaemonSet 組態中，此功能需要存取主機網路。`amazon/aws-for-fluent-bit` 的映像版本應該是 2.12.0 或更高版本，或者流暢位元映像版本應該是 1.7.2 或更高版本。

```
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: fluent-bit
  namespace: amazon-cloudwatch
  labels:
    k8s-app: fluent-bit
    version: v1
    kubernetes.io/cluster-service: "true"
spec:
  selector:
    matchLabels:
      k8s-app: fluent-bit
  template:
    metadata:
      labels:
        k8s-app: fluent-bit
        version: v1
        kubernetes.io/cluster-service: "true"
    spec:
      containers:
      - name: fluent-bit
        image: amazon/aws-for-fluent-bit:2.19.0
        imagePullPolicy: Always
        env:
            - name: AWS_REGION
              valueFrom:
                configMapKeyRef:
                  name: fluent-bit-cluster-info
                  key: logs.region
            - name: CLUSTER_NAME
              valueFrom:
                configMapKeyRef:
                  name: fluent-bit-cluster-info
                  key: cluster.name
            - name: HTTP_SERVER
              valueFrom:
                configMapKeyRef:
                  name: fluent-bit-cluster-info
                  key: http.server
            - name: HTTP_PORT
              valueFrom:
                configMapKeyRef:
                  name: fluent-bit-cluster-info
                  key: http.port
            - name: READ_FROM_HEAD
              valueFrom:
                configMapKeyRef:
                  name: fluent-bit-cluster-info
                  key: read.head
            - name: READ_FROM_TAIL
              valueFrom:
                configMapKeyRef:
                  name: fluent-bit-cluster-info
                  key: read.tail
            - name: HOST_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: HOSTNAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.name      
            - name: CI_VERSION
              value: "k8s/1.3.8"
        resources:
            limits:
              memory: 200Mi
            requests:
              cpu: 500m
              memory: 100Mi
        volumeMounts:
        # Please don't change below read-only permissions
        - name: fluentbitstate
          mountPath: /var/fluent-bit/state
        - name: varlog
          mountPath: /var/log
          readOnly: true
        - name: varlibdockercontainers
          mountPath: /var/lib/docker/containers
          readOnly: true
        - name: fluent-bit-config
          mountPath: /fluent-bit/etc/
        - name: runlogjournal
          mountPath: /run/log/journal
          readOnly: true
        - name: dmesg
          mountPath: /var/log/dmesg
          readOnly: true
      terminationGracePeriodSeconds: 10
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
      volumes:
      - name: fluentbitstate
        hostPath:
          path: /var/fluent-bit/state
      - name: varlog
        hostPath:
          path: /var/log
      - name: varlibdockercontainers
        hostPath:
          path: /var/lib/docker/containers
      - name: fluent-bit-config
        configMap:
          name: fluent-bit-config
      - name: runlogjournal
        hostPath:
          path: /run/log/journal
      - name: dmesg
        hostPath:
          path: /var/log/dmesg
      serviceAccountName: fluent-bit
      tolerations:
      - key: node-role.kubernetes.io/master
        operator: Exists
        effect: NoSchedule
      - operator: "Exists"
        effect: "NoExecute"
      - operator: "Exists"
        effect: "NoSchedule"
```

Kubernetes 外掛程式組態應該類似如下：

```
[FILTER]
        Name                kubernetes
        Match               application.*
        Kube_URL            https://kubernetes.default.svc:443
        Kube_Tag_Prefix     application.var.log.containers.
        Merge_Log           On
        Merge_Log_Key       log_processed
        K8S-Logging.Parser  On
        K8S-Logging.Exclude Off
        Labels              Off
        Annotations         Off
        Use_Kubelet         On
        Kubelet_Port        10250 
        Buffer_Size         0
```

# 在 Amazon EKS 和 Kubernetes 上更新或刪除 Container Insights
<a name="ContainerInsights-update-delete"></a>

使用這些區段中的步驟來更新您的 CloudWatch 代理程式容器映像，或是從 Amazon EKS 或 Kubernetes 叢集移除 Container Insights。

**Topics**
+ [在 CloudWatch 中針對 Amazon EKS 升級至具有增強可觀測性的 Container Insights](Container-Insights-upgrade-enhanced.md)
+ [更新 CloudWatch 代理程式容器映像](ContainerInsights-update-image.md)
+ [刪除 Container Insights 的 CloudWatch 代理程式和 Fluent Bit](ContainerInsights-delete-agent.md)

# 在 CloudWatch 中針對 Amazon EKS 升級至具有增強可觀測性的 Container Insights
<a name="Container-Insights-upgrade-enhanced"></a>

**重要**  
如果要在 Amazon EKS 叢集上升級或安裝 Container Insights，建議使用 Amazon CloudWatch Observability EKS 附加元件進行安裝，而不是使用本節中的指示。此外，若要擷取加速運算指標，必須使用 Amazon CloudWatch Observability EKS 附加元件。如需詳細資訊和指示，請參閱[Amazon CloudWatch Observability EKS 附加元件快速入門](Container-Insights-setup-EKS-addon.md)。

Container Insights 搭配 Amazon EKS 的增強可觀測性是最新版 Container Insights。它會從執行於 Amazon EKS 的叢集收集詳細的指標，並提供經策管且立即可用的儀表板，以深入了解應用程式和基礎設施遙測。如需有關此 Container Insights 版本的詳細資訊，請參閱 [適用於 Amazon EKS 的具備增強之可觀測性的 Container Insights](container-insights-detailed-metrics.md)。

如果您已在 Amazon EKS 叢集安裝原始版 Container Insights，並且您想要使用增強可觀測性將其升級至較新版本，請遵循本節中的指示進行操作。

**重要**  
在完成本節中的步驟前，您必須先驗證包括 cert-manager 在內的先決條件。如需詳細資訊，請參閱[CloudWatch 代理程式運算子和 Fluent Bit 的快速入門](Container-Insights-setup-EKS-quickstart.md#Container-Insights-setup-EKS-quickstart-FluentBit)。

**將 Amazon EKS 叢集升級至 Container Insights 搭配 Amazon EKS 的增強可觀測性**

1. 輸入以下命令，安裝 CloudWatch 代理程式運算子。將 *my-cluster-name* 取代為 Amazon EKS 或 Kubernetes 叢集的名稱，將 *my-cluster-region* 取代為發布日誌的區域名稱。我們建議您使用部署叢集的相同區域，以降低 AWS 傳出資料傳輸成本。

   ```
   ClusterName=my-cluster-name
   RegionName=my-cluster-region
   curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/main/k8s-quickstart/cwagent-operator-rendered.yaml | sed 's/{{cluster_name}}/'${ClusterName}'/g;s/{{region_name}}/'${RegionName}'/g' | kubectl apply -f -
   ```

   如果發現資源衝突所造成的故障，可能是因為您已在叢集上安裝 CloudWatch 代理程式和 Fluent Bit 及其相關聯的元件，例如 ServiceAccount、ClusterRole 和 ClusterRoleBinding。當 CloudWatch 代理程式運算子嘗試安裝 CloudWatch 代理程式及其相關元件時，如果偵測到內容有任何變更，則預設情況下，安裝或更新會失敗，以避免覆寫叢集上資源的狀態。建議您刪除先前安裝在叢集上具有 Container Insights 設定的任何現有 CloudWatch 代理程式，然後安裝 CloudWatch 代理程式運算子。

1. (選用) 若要套用現有的自訂 Fluent Bit 組態，必須更新與 Fluent Bit 常駐程式集相關聯的 configmap。CloudWatch 代理程式運算子可提供 Fluent Bit 的預設組態，您可以視需要覆寫或修改預設組態。若要套用自訂組態，請遵循下列步驟。

   1. 輸入下列命令，開啟現有組態。

      ```
      kubectl edit cm fluent-bit-config -n amazon-cloudwatch
      ```

   1. 在檔案中進行變更，然後輸入 `:wq` 以儲存檔案並結束編輯模式。

   1. 輸入下列命令，重新啟動 Fluent Bit。

      ```
      kubectl rollout restart ds fluent-bit -n amazon-cloudwatch
      ```

# 更新 CloudWatch 代理程式容器映像
<a name="ContainerInsights-update-image"></a>

**重要**  
如果要在 Amazon EKS 叢集上升級或安裝 Container Insights，建議使用 Amazon CloudWatch Observability EKS 附加元件進行安裝，而不是使用本節中的指示。此外，若要擷取加速運算指標，必須使用 Amazon CloudWatch Observability EKS 附加元件或 CloudWatch 代理程式運算子。如需詳細資訊和指示，請參閱[Amazon CloudWatch Observability EKS 附加元件快速入門](Container-Insights-setup-EKS-addon.md)。

若您需要將您的容器映像更新至最新的版本，請使用本節中的步驟。

**更新您的容器映像**

1. 輸入下列命令，確認 `amazoncloudwatchagent` Customer Resource Definition (CRD) 是否已存在。

   ```
   kubectl get crds amazoncloudwatchagents.cloudwatch.aws.amazon.com -n amazon-cloudwatch
   ```

   如果此命令傳回缺少 CRD 的錯誤，則對於配置有 CloudWatch 代理程式運算子的 Amazon EKS 而言，叢集沒有具有增強可觀測性的 Container Insights。在這種情況下，請參閱 [在 CloudWatch 中針對 Amazon EKS 升級至具有增強可觀測性的 Container Insights](Container-Insights-upgrade-enhanced.md)。

1. 輸入以下命令，套用最新的 `cwagent-version.yaml` 檔案。

   ```
   curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/main/k8s-quickstart/cwagent-version.yaml | kubectl apply -f -
   ```

# 刪除 Container Insights 的 CloudWatch 代理程式和 Fluent Bit
<a name="ContainerInsights-delete-agent"></a>

如果您使用適用於 Amazon EKS 的 CloudWatch 可觀測性附加元件來安裝 Container Insights，您可輸入下列命令來刪除 Container Insights 和 CloudWatch 代理程式：

**注意**  
Amazon EKS 附加元件現在支援 Windows 工作者節點上的 Container Insights。如果刪除 Amazon EKS 附加元件，則也會刪除適用於 Windows 的 Container Insights。

```
aws eks delete-addon —cluster-name my-cluster —addon-name amazon-cloudwatch-observability
```

否則，若要刪除與 CloudWatch 代理程式和 Fluent Bit 相關的所有資源，請輸入以下命令。在此命令中，*My\$1Cluster\$1Name* 是 Amazon EKS 或 Kubernetes 叢集的名稱，*My\$1Region* 則是發布日誌的區域名稱。

```
ClusterName=My_Cluster_Name
RegionName=My-Region
curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/main/k8s-quickstart/cwagent-operator-rendered.yaml | sed 's/{{cluster_name}}/'${ClusterName}'/g;s/{{region_name}}/'${RegionName}'/g' | kubectl delete -f -
curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/main/k8s-quickstart/cwagent-custom-resource-definitions.yaml | kubectl delete -f -
```

# 在 RedHat OpenShift on AWS (ROSA) 上設定 Container Insights
<a name="deploy-container-insights-RedHatOpenShift"></a>

具有增強可觀測性的 CloudWatch Container Insights 支援 RedHat OpenShift on AWS (ROSA)。此版本支援 ROSA 叢集的增強可觀測性。安裝 CloudWatch 代理程式運算子 Helm Chart 之後，Container Insights 會自動收集環境中從叢集層級到容器層級的詳細基礎設施遙測資料。然後，它會在精心策劃的儀表板中顯示此效能資料，消除可觀測性設定中的繁重工作。

**注意**  
對於適用於 OpenShift on AWS (ROSA) 的 RedHat，當您使用 Helm Chart 安裝 CloudWatch 代理程式運算子時，CloudWatch 代理程式預設為啟用，以從針對 Application Signals 檢測的應用程式接收指標和追蹤。如果您想要選擇性地傳遞自訂組態規則，可以使用 Helm Chart 傳入自訂代理程式組態，如 [(選用) 額外組態](install-CloudWatch-Observability-EKS-addon.md#install-CloudWatch-Observability-EKS-addon-configuration) 中的 (選用) [其他組態] 中所述。

**在 RedHat OpenShift on AWS (ROSA) 叢集上安裝具有增強可觀測性的 Container Insights**

1. 如有必要，請安裝 Helm。如需詳細資訊，請參閱 Helm 文件中的[快速入門指南](https://helm.sh/docs/intro/quickstart/)。

1. 輸入以下命令，安裝 CloudWatch 代理程式運算子。將 *my-cluster-name* 替換為您的叢集名稱，並將 *my-cluster-region* 替換為叢集執行所在的區域。

   ```
   helm repo add aws-observability https://aws-observability.github.io/helm-charts
   helm repo update aws-observability
   helm install --wait --create-namespace \
       --namespace amazon-cloudwatch amazon-cloudwatch-observability \
       aws-observability/amazon-cloudwatch-observability \
       --set clusterName=my-cluster-name \
       --set region=my-cluster-region \
       --set k8sMode=ROSA
   ```

1. 遵循 [使用 Amazon CloudWatch Observability EKS 附加元件或 Helm Chart 安裝 CloudWatch 代理程式](install-CloudWatch-Observability-EKS-addon.md) 中選項 1、選項 2 或選項 3 中的步驟，設定代理程式運算子的授權。

# 檢視 Container Insights 指標
<a name="Container-Insights-view-metrics"></a>

在設定好 Container Insights 且它正在收集指標之後，您可以在 CloudWatch 主控台上檢視這些指標。

若要讓 Container Insights 指標顯示在儀表板上 , 您必須完成 Container Insights 設定。如需詳細資訊，請參閱[設定 Container Insights](deploy-container-insights.md)。

此程序會說明如何檢視 Container Insights 從收集的日誌資料自動產生的指標。本節的其餘部分將說明如何進一步深入探索您的資料，並使用 CloudWatch Logs Insights 來查看更多精細程度層級的指標。

**檢視容器洞見指標**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇 **Insights**，然後選擇 **Container Insights**。

1. 使用靠近頂端的下拉式方塊來選取要檢視的資源類型，以及特定資源。

您可以對 Container Insights 收集的任何指標設定 CloudWatch 警示。如需詳細資訊，請參閱[使用 Amazon CloudWatch 警示](CloudWatch_Alarms.md)

**注意**  
如果您已設定 CloudWatch Application Insights 來監控您的容器化應用程式，Application Insights 儀表板會出現在 Container Insights 儀表板下方。如果您尚未啟用 Application Insights，您可以選擇 Container Insights 儀表板中效能檢視下方的 **Auto-configure Application Insights** (自動設定 Application Insights)。  
如需 Application Insights 和容器化應用程式的詳細資訊，請參閱 [啟用 Application Insights 進行 Amazon ECS 和 Amazon EKS 資源監控](appinsights-setting-up-console.md#appinsights-container-insights)。

## 檢視頂端貢獻因子
<a name="Container-Insights-view-metrics-topn"></a>

對於容器深入解析效能監視中的某些檢視，您也可以查看記憶體或 CPU 或最近使用中的資源的前幾名參與者。如果您在頁面頂端附近的下拉式方塊中選取下列任何一個儀表板，則可使用此選項：
+ ECS 服務
+ ECS 任務
+ EKS 命名空間
+ EKS 服務
+ EKS Pod

當您檢視其中一種資源類型時，頁面底部會顯示一個最初依 CPU 用量排序的表格。您可以將其變更為按記憶體用量或最近活動排序。若要查看表格中其中一列的詳細資訊，您可以選取該列旁邊的核取方塊，然後選擇 **Actions** (動作)，並選擇 **Actions** (動作) 選單中的其中一個選項。

## 使用 CloudWatch Logs Insights 來檢視 Container Insights 資料
<a name="Container-Insights-CloudWatch-Logs-Insights"></a>

Container Insights 會使用[內嵌指標格式](CloudWatch_Embedded_Metric_Format.md)的效能日誌事件收集指標。這些記錄會存放在 CloudWatch Logs 中。CloudWatch 會從您可以在 CloudWatch 主控台中檢視的日誌自動產生多個指標。您也可以對使用 CloudWatch Logs Insights 查詢收集的效能資料進行更深入的分析。

如需使用 CloudWatch Logs Insights 的詳細資訊，請參閱[使用 CloudWatch Logs Insights 分析日誌資料](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html)。如需您可以在查詢中使用的日誌欄位詳細資訊，請參閱 [Amazon EKS 和 Kubernetes 的 Container Insights 效能日誌事件](Container-Insights-reference-performance-logs-EKS.md)。

**若要使用 CloudWatch Logs Insights 來查詢容器指標資料**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇**日誌**，然後選擇 **Logs Insights**。

   靠近螢幕頂端是查詢編輯器。當您第一次開啟 CloudWatch Logs 時，此方塊包含一個會傳回 20 個最新日誌事件的預設查詢。

1. 在查詢編輯器上方的方塊中，選取要查詢的其中一個容器洞見日誌群組。若要讓以下範例查詢運作，日誌群組名稱必須以 **performance (效能)** 為結尾。

   選取日誌群組時，CloudWatch Logs Insights 會自動偵測日誌群組中資料內的欄位，並在右側窗格的 **Discovered fields** (已探索欄位) 中顯示。它也會顯示一段時間內此日誌群組中日誌事件的長條圖。此長條圖會顯示日誌群組中符合您查詢和時間範圍的事件分佈，而不只是表格中顯示的事件。

1. 在查詢編輯器中，將預設查詢取代為以下查詢，然後選擇 **Run query (執行查詢)**。

   ```
   STATS avg(node_cpu_utilization) as avg_node_cpu_utilization by NodeName
   | SORT avg_node_cpu_utilization DESC
   ```

   此查詢顯示的節點清單會依平均節點 CPU 使用率排序。

1. 若要嘗試另一個範例，請將查詢取代為另一個查詢，並選擇 **Run query (執行查詢)**。此頁面稍後會列出更多範例查詢。

   ```
   STATS avg(number_of_container_restarts) as avg_number_of_container_restarts by PodName
   | SORT avg_number_of_container_restarts DESC
   ```

   此查詢顯示的 pod 清單會依重新啟動的平均容器數量來排序。

1. 如果您想要嘗試另一個查詢，您可以在螢幕右側使用清單中的包含欄位。如需查詢語法的詳細資訊，請參閱 [CloudWatch Logs Insights 查詢語法](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CWL_QuerySyntax.html)。

**查看您的資源清單**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇 **Resources** (資源)。

1. 預設檢視是 Container Insights 所監視的資源清單，以及您已在這些資源上設定的警示。若要查看資源的視覺化地圖，請選擇 **Map view (地圖檢視)**。

1. 從地圖檢視中，您可以將指標暫停在地圖中的任何資源上，以查看有關該資源的基本指標。您可以選擇任何資源來查看關於該資源的更詳細圖形。

## 使用案例：查看 Amazon ECS 容器中的任務層級指標
<a name="Container-Insights-CloudWatch-Logs-Insights-example"></a>

下列範例說明如何使用 CloudWatch Logs Insights，深入了解您的 Container Insights 日誌。如需更多範例，請參閱部落格[推出適用於 Amazon ECS 的 Amazon CloudWatch Container Insights](https://aws.amazon.com/blogs/mt/introducing-container-insights-for-amazon-ecs/)。

 Container Insights 不會在精細程度的任務層級自動產生指標。下列查詢會顯示 CPU 和記憶體用量的任務層級指標。

```
stats avg(CpuUtilized) as CPU, avg(MemoryUtilized) as Mem by TaskId, ContainerName
| sort Mem, CPU desc
```

## Container Insights 的其他範例查詢
<a name="Container-Insights-sample-queries"></a>

**您的 Pod 清單，依照容器重新啟動的平均次數進行排序**

```
STATS avg(number_of_container_restarts) as avg_number_of_container_restarts by PodName
| SORT avg_number_of_container_restarts DESC
```

**請求的 Pod 與正在執行的 Pod**

```
fields @timestamp, @message 
| sort @timestamp desc 
| filter Type="Pod" 
| stats min(pod_number_of_containers) as requested, min(pod_number_of_running_containers) as running, ceil(avg(pod_number_of_containers-pod_number_of_running_containers)) as pods_missing by kubernetes.pod_name 
| sort pods_missing desc
```

**叢集節點故障的計數**

```
stats avg(cluster_failed_node_count) as CountOfNodeFailures 
| filter Type="Cluster" 
| sort @timestamp desc
```

**應用程式日誌錯誤 (依容器名稱)**

```
stats count() as countoferrors by kubernetes.container_name 
| filter stream="stderr" 
| sort countoferrors desc
```

# Container Insights 收集的指標
<a name="Container-Insights-metrics"></a>

Container Insights 會為 Amazon ECS 和 AWS Fargate Amazon ECS 收集一組指標，並為 Amazon EKS、 AWS Fargate Amazon EKS、RedHat OpenShift on AWS (ROSA) 和 Kubernetes 收集另一組指標。

指標要在容器任務執行一段時間後才會顯示。

**Topics**
+ [具有增強可觀測性指標的 Amazon ECS Container Insights](Container-Insights-enhanced-observability-metrics-ECS.md)
+ [Amazon ECS Container Insights 指標](Container-Insights-metrics-ECS.md)
+ [具有增強可觀測性指標的 Amazon EKS 和 Kubernetes Container Insights](Container-Insights-metrics-enhanced-EKS.md)
+ [Amazon EKS 和 Kubernetes Container Insights 指標](Container-Insights-metrics-EKS.md)
+ [Container Insights 效能日誌參考](Container-Insights-reference.md)
+ [Container Insights Prometheus 指標監控](ContainerInsights-Prometheus.md)
+ [與 Application Insights 整合](container-insights-appinsights.md)
+ [在 Container Insights 中檢視 Amazon ECS 生命週期事件](container-insights-ECS-lifecycle-events.md)
+ [針對容器洞見進行故障診斷](ContainerInsights-troubleshooting.md)
+ [建置您自己的 CloudWatch 代理程式 Docker 影像](ContainerInsights-build-docker-image.md)
+ [在容器中部署其他 CloudWatch 代理程式功能](ContainerInsights-other-agent-features.md)

# 具有增強可觀測性指標的 Amazon ECS Container Insights
<a name="Container-Insights-enhanced-observability-metrics-ECS"></a>

具有增強可觀測性的 Container Insights 透過提供以下內容，可以更深入地了解容器化工作負載：
+ 任務和容器層級的更高指標精細度
+ 提高監控和疑難排解功能
+ 與 CloudWatch Logs 整合，適用於：
  + 將指標異常與日誌項目建立關聯
  + 執行更快的根本原因分析
  + 縮短複雜容器問題的解決時間

**使用案例**

Container Insights 具有增強的可觀測性，可擴展標準 Container Insights 的功能。它可啟用下列使用案例：
+ **任務層級疑難排解**：確定任務層級的效能瓶頸。分析任務層級指標，並將其與預留資源進行比較，以確定任務是否有足夠的處理容量 
+ **容器層級資源最佳化**：追蹤保留層級的使用率，以識別資源受限或過度佈建的容器 
+ **容器運作狀態評估**：監控重新啟動計數和狀態轉換，以偵測需要干預的不穩定容器 
+ **應用程式效能監控**：追蹤應用程式如何互相通訊，監控資源使用模式，以及最佳化資料儲存效能
+ **操作監控**：監控部署、追蹤藍色或綠色部署的任務集，並透過服務指標維護平台運作狀態

如需 Amazon ECS 指標的詳細資訊，請參閱 [Amazon ECS 服務使用率指標使用案例](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service_utilization-metrics-explanation.html)，以及具有增強可觀測性的 Container Insights 的資訊 ([具有增強可觀測性指標的 Amazon ECS Container Insights](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Container-Insights-enhanced-observability-metrics-ECS.html))。

Container Insights 也會透過在所有任務中平均資料，顯示叢集、服務和精靈整體統計資料。這可提供服務和協助程式運作狀態的更高層級檢視，協助環境監控和容量規劃。

**注意**  
Amazon ECS 受管協助程式指標使用與服務指標相同的`ECS/ContainerInsights`命名空間和`ServiceName`維度。對於協助程式指標，`ServiceName`維度值使用 格式 `daemon:daemon-name`。例如，名為 的協助程式`my-daemon`的`ServiceName`維度值為 `daemon:my-daemon`。下表中包含`ServiceName`維度的所有指標也適用於 Managed Daemons。

下表列出具有增強可觀測性的 Container Insights 為 Amazon ECS 收集的指標和維度。這些指標會在 `ECS/ContainerInsights` 命名空間中。如需詳細資訊，請參閱[指標](cloudwatch_concepts.md#Metric)。

如果沒有在主控台中看到任何 Container Insights 指標，請確定您已完成具有增強可觀測性的 Container Insights 的設定。在完整設定具有增強可觀測性的 Container Insights 之前，指標都不會出現。如需詳細資訊，請參閱[設定具有增強可觀測性的 Container Insights](deploy-container-insights-ECS-cluster.md#set-container-insights-ECS-cluster-enhanced)。

下列是所有啟動類型可用的指標。


| 指標名稱 | 維度 | Description | 
| --- | --- | --- | 
|  `ContainerInstanceCount`  |  `ClusterName`  |  執行 Amazon ECS 代理程式並與叢集註冊的 EC2 執行個體數量。 只會針對在叢集中執行 Amazon ECS 任務的容器執行個體來收集此指標。對於沒有任何 Amazon ECS 任務的空容器執行個體，不會收集此指標。 單位：計數  | 
|  `ContainerCpuUtilized`  |  `ClusterName` `ContainerName`, `TaskId`, `ServiceName`, `ClusterName` `ContainerName`, `TaskDefinitionFamily`, `ClusterName`, `TaskId` `TaskDefinitionFamily`, `ClusterName`, `ContainerName` `ServiceName`, `ClusterName`, `ContainerName`  |  資源中容器所使用的 CPU 單位，由您正在使用的維度設定所指定。 也適用於 Managed Daemons。 單位：無  | 
|  `ContainerCpuReserved`  |  `ClusterName` `ContainerName`, `TaskId`, `ServiceName`, `ClusterName` `ContainerName`, `TaskDefinitionFamily`, `ClusterName`, `TaskId` `TaskDefinitionFamily`, `ClusterName`, `ContainerName` `ServiceName`, `ClusterName`, `ContainerName`  |  資源中容器所預留的 CPU 單位，由您正在使用的維度設定所指定。根據任務定義中定義的 CPU 預留來收集此指標，例如在任務或所有容器層級。如果在任務定義中未定義，則會使用執行個體 CPU 預留。 也適用於 Managed Daemons。 單位：無  | 
|  `ContainerCpuUtilization`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`   | 資源中容器所使用的 CPU 單位的總百分比，由您正在使用的維度設定所指定。 單位：百分比 | 
|  `ContainerMemoryUtilized`  |  `ClusterName` `ContainerName`, `TaskId`, `ServiceName`, `ClusterName` `ContainerName`, `TaskDefinitionFamily`, `ClusterName`, `TaskId` `TaskDefinitionFamily`, `ClusterName`, `ContainerName` `ServiceName`, `ClusterName`, `ContainerName`  |  資源中容器正在使用的記憶體，由您正在使用的維度設定所指定。 也適用於 Managed Daemons。 單位：MB  | 
|  `ContainerMemoryReserved`  |  `ClusterName` `ContainerName`, `TaskId`, `ServiceName`, `ClusterName` `ContainerName`, `TaskDefinitionFamily`, `ClusterName`, `TaskId` `TaskDefinitionFamily`, `ClusterName`, `ContainerName` `ServiceName`, `ClusterName`, `ContainerName`  |  資源中容器所預留的記憶體，由您正在使用的維度設定所指定。 根據任務定義中定義的記憶體預留來收集此指標，例如在任務或所有容器層級。如果在任務定義中未定義，則會使用執行個體記憶體預留。 也適用於 Managed Daemons。 單位：MB  | 
|  `ContainerMemoryUtilization`  |  `ClusterName` `ContainerName`, `TaskId`, `ServiceName`, `ClusterName` `ContainerName`, `TaskDefinitionFamily`, `ClusterName`, `TaskId` `TaskDefinitionFamily`, `ClusterName`, `ContainerName` `ServiceName`, `ClusterName`, `ContainerName`  | 資源中容器正在使用的記憶體總百分比，由您正在使用的維度設定所指定。 也適用於 Managed Daemons。 單位：百分比 | 
|  `ContainerNetworkRxBytes`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`  |  容器收到的位元組數，由您正在使用的維度所指定。從 Docker 執行期獲取此指標。 此指標僅適用於使用 `awsvpc` 或 `bridge` 網路模式的任務中的容器。 也適用於 Managed Daemons。 單位：位元組/秒  | 
|  `ContainerNetworkTxBytes`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`  |  容器傳輸的位元組數，由您正在使用的維度所指定。從 Docker 執行期獲取此指標。 此指標僅適用於使用 `awsvpc` 或 `bridge` 網路模式的任務中的容器。 也適用於 Managed Daemons。 單位：位元組/秒  | 
|  `ContainerStorageReadBytes`  |  `ClusterName` `ClusterName`, `ServiceName`, `ContainerName` `ClusterName`, `TaskDefinitionFamily`, `ContainerName` `ClusterName`, `ServiceName`, `TaskId`, `ContainerName` `ClusterName`, `TaskDefinitionFamily`, `TaskId`, `ContainerName`  |  資源中從容器儲存裝置讀取的位元組數，該資源由您正在使用的維度所指定。這不包括儲存裝置的讀取位元組。從 Docker 執行期獲取此指標。 也適用於 Managed Daemons。 單位：位元組  | 
|  `ContainerStorageWriteBytes`  |  `ClusterName` `ClusterName`, `ServiceName`, `ContainerName` `ClusterName`, `TaskDefinitionFamily`, `ContainerName` `ClusterName`, `ServiceName`, `TaskId`, `ContainerName` `ClusterName`, `TaskDefinitionFamily`, `TaskId`, `ContainerName`  |  容器中寫入儲存裝置的位元組數，該資源由您正在使用的維度所指定。從 Docker 執行期獲取此指標。 也適用於 Managed Daemons。 單位：位元組  | 
|  `CpuUtilized`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`   |  資源中任務所使用的 CPU 單位，由您正在使用的維度設定所指定。 也適用於 Managed Daemons。 單位：無  | 
|  `CpuReserved`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`  |  資源中任務所預留的 CPU 單位，由您正在使用的維度設定所指定。根據任務定義中定義的 CPU 預留來收集此指標，例如在任務或所有容器層級。如果在任務定義中未定義，則會使用執行個體 CPU 預留。 也適用於 Managed Daemons。 單位：無  | 
|  `DeploymentCount`  |  `ServiceName`, `ClusterName`  |  在 Amazon ECS 服務中部署的數量。 單位：計數  | 
|  `DesiredTaskCount`  |  `ServiceName`, `ClusterName`  |  Amazon ECS 服務所需的任務數。 單位：計數  | 
|  `EBSFilesystemSize`  |  `ClusterName` ,`TaskDefinitionFamily`, `VolumeName` `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName`  |  分配給您正在使用之維度所指定資源的 Amazon EBS 檔案系統儲存總量，以 GB 為單位。 此指標僅適用於在 Fargate 上使用平台版本 `1.4.0` 執行的 Amazon ECS 基礎設施上執行的任務，或使用容器代理程式版本 `1.79.0` 或更新版本的 Amazon EC2 執行個體。 也適用於 Managed Daemons。 單位：千兆位元組 (GB)  | 
|  `EBSFilesystemUtilized`  |  `ClusterName` ,`TaskDefinitionFamily`, `VolumeName` `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName`  |  您正在使用之維度所指定資源的 Amazon EBS 檔案系統儲存總量，以 GB 為單位。 此指標僅適用於在 Fargate 上使用平台版本 `1.4.0` 執行的 Amazon ECS 基礎設施上執行的任務，或使用容器代理程式版本 `1.79.0` 或更新版本的 Amazon EC2 執行個體。 對於在 Fargate 上執行的任務，Fargate 會在只有 Fargate 使用的磁碟上預留空間。Fargate 使用的空間不會產生相關費用，但您可以使用 `df` 等工具檢視此額外儲存空間。 也適用於 Managed Daemons。 單位：千兆位元組 (GB)  | 
|  `TaskEBSFilesystemUtilization`  |  `TaskDefinitionFamily`, `ClusterName` `ClusterName`, `ServiceName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `TaskDefinitionFamily`, `ClusterName`, `TaskId`  |  所使用的維度所指定任務正在使用的 Amazon EBS 檔案系統儲存體百分比。 此指標僅適用於在 Fargate 上使用平台版本 `1.4.0` 執行的 Amazon ECS 基礎設施上執行的任務，或使用容器代理程式版本 `1.79.0` 或更新版本的 Amazon EC2 執行個體。 也適用於 Managed Daemons。 單位：百分比  | 
|  EphemeralStorageReserved [1](#ci-enhanced-metrics-ecs-storage-fargate-note)  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`  |  資源中從暫時性儲存裝置中所預留的位元組數，該資源由您正在使用的維度所指定。暫時性儲存裝置會用於容器根檔案系統，以及容器映像和任務定義中定義的任何綁定掛載主機磁碟區。在執行中的任務中，無法變更暫時性儲存裝置的數量。 此指標僅適用於在 Fargate Linux 平台版本 1.4.0 或更新版本上執行的任務。 也適用於 Managed Daemons。 單位：千兆位元組 (GB)  | 
|  EphemeralStorageUtilized [1](Container-Insights-metrics-ECS.md#ci-metrics-ecs-storage-fargate-note)  |  `ClusterName` `ClusterName`, `TaskDefinitionFamily` `ClusterName`, `ServiceName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`  |  資源中從暫時性儲存裝置中使用的位元組數，該資源由您正在使用的維度所指定。暫時性儲存裝置會用於容器根檔案系統，以及容器映像和任務定義中定義的任何綁定掛載主機磁碟區。在執行中的任務中，無法變更暫時性儲存裝置的數量。 此指標僅適用於在 Fargate Linux 平台版本 1.4.0 或更新版本上執行的任務。 也適用於 Managed Daemons。 單位：千兆位元組 (GB)  | 
|  `MemoryUtilized`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`  |  資源中任務正在使用的記憶體，由您正在使用的維度設定所指定。 也適用於 Managed Daemons。 單位：MB  | 
|  `MemoryReserved`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`  |  資源中任務所預留的記憶體，由您正在使用的維度設定所指定。 根據任務定義中定義的記憶體預留來收集此指標，例如在任務或所有容器層級。如果在任務定義中未定義，則會使用執行個體記憶體預留。 也適用於 Managed Daemons。 單位：MB  | 
|  `NetworkRxBytes`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`  |  資源收到的位元組數，由您正在使用的維度所指定。從 Docker 執行期獲取此指標。 此指標僅適用於使用 `awsvpc` 或 `bridge` 網路模式的任務中的容器。 也適用於 Managed Daemons。 單位：位元組/秒  | 
|  `NetworkTxBytes`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`  |  資源傳輸的位元組數，由您正在使用的維度所指定。從 Docker 執行期獲取此指標。 此指標僅適用於使用 `awsvpc` 或 `bridge` 網路模式的任務中的容器。 也適用於 Managed Daemons。 單位：位元組/秒  | 
|  `PendingTaskCount`  |  `ServiceName`, `ClusterName`  |  目前處於 `PENDING` 狀態的任務數。 單位：計數  | 
|  `RunningTaskCount`  |  `ServiceName`, `ClusterName`  |  目前處於 `RUNNING` 狀態的任務數。 單位：計數  | 
|  `RestartCount`  |  `ClusterName` `ClusterName`, `ServiceName` `ClusterName`, `TaskDefinitionFamily` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId` `ClusterName`, `ServiceName`, `ContainerName` `ClusterName`, `ServiceName`, `TaskId`, `ContainerName` `TaskDefinitionFamily`, `ClusterName`, `ContainerName` `TaskDefinitionFamily`, `ClusterName`, `TaskId`, `ContainerName`  |  Amazon ECS 任務中的容器重新啟動的次數。 只會針對已啟用重新啟動政策的容器收集此指標。 也適用於 Managed Daemons。 單位：計數  | 
|  `UnHealthyContainerHealthStatus`  |  `ClusterName` `ClusterName`, `ServiceName`, `ContainerName` `ClusterName`, `TaskDefinitionFamily`, `ContainerName` `ClusterName`, `ServiceName`, `TaskId`, `ContainerName` `ClusterName`, `TaskDefinitionFamily`, `TaskId`, `ContainerName`  |  根據容器運作狀態檢查狀態的不良容器數量。當容器的運作狀態檢查傳回運作狀態不佳的狀態時，容器會被視為運作狀態不佳。 此指標只會針對已在任務定義中設定運作狀態檢查的容器收集。 當容器運作狀態為 時，指標值為 1`UNHEALTHY`，當運作狀態為 時，指標值為 0`HEALTHY`。 單位：計數  | 
|  `ServiceCount`  |  `ClusterName`  |  叢集中的服務數量。 單位：計數  | 
|  `StorageReadBytes`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`  |  資源中從執行個體儲存裝置讀取的位元組數，該資源由您正在使用的維度所指定。這不包括儲存裝置的讀取位元組。從 Docker 執行期獲取此指標。 也適用於 Managed Daemons。 單位：位元組  | 
|  `StorageWriteBytes`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`  |  資源中寫入儲存裝置的位元組數，該資源由您正在使用的維度所指定。從 Docker 執行期獲取此指標。 也適用於 Managed Daemons。 單位：位元組  | 
|  `TaskCount`  |  `ClusterName`  |  叢集中執行的任務數。 單位：計數  | 
|  `TaskCpuUtilization`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`   |  任務使用的 CPU 單位總百分比。 也適用於 Managed Daemons。 單位：百分比  | 
|  `TaskEphemeralStorageUtilization`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`   |  任務正在使用的暫時性儲存體的總百分比。 也適用於 Managed Daemons。 單位：百分比  | 
|  `TaskMemoryUtilization`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName` `ClusterName`, `ServiceName`, `TaskId` `ClusterName`, `TaskDefinitionFamily`, `TaskId`   |  任務正在使用的記憶體總百分比。 也適用於 Managed Daemons。 單位：百分比  | 
|  `TaskSetCount`  |  `ServiceName`, `ClusterName`  |  服務中的任務集數。 單位：計數  | 

**注意**  
此 `EphemeralStorageReserved` 與 `EphemeralStorageUtilized` 指標僅適用於在 Fargate Linux 平台版本 1.4.0 或更新版本上執行的任務。  
Fargate 會在磁盤上保留空間。此空間僅由 Fargate 使用。我們不會向您收費。它不會顯示在這些指標中。但是，您可以在其他工具 (例如 `df`) 中看到此額外儲存空間。

當您完成 [部署 CloudWatch 代理程式以收集 Amazon ECS 上的 EC2 執行個體層級指標](deploy-container-insights-ECS-instancelevel.md) 中的步驟並使用 EC2 啟動類型時，即可使用下列指標。


| 指標名稱 | 維度 | Description | 
| --- | --- | --- | 
|  `instance_cpu_limit`  |  `ClusterName`  |  可指派至此叢集中單一 EC2 執行個體的 CPU 單位數量上限。 單位：無  | 
|  `instance_cpu_reserved_capacity`  |  `ClusterName` `InstanceId`, `ContainerInstanceId`, `ClusterName`  |  目前保留在叢集中單一 EC2 執行個體上的 CPU 百分比。 單位：百分比  | 
|  `instance_cpu_usage_total`  |  `ClusterName`  |  叢集中單一 EC2 執行個體正在使用的 CPU 單位數目。 單位：無  | 
|  `instance_cpu_utilization`  |  `ClusterName` `InstanceId`, `ContainerInstanceId`, `ClusterName`  |  叢集中單一 EC2 執行個體正在使用的 CPU 單位總百分比。 單位：百分比  | 
|  `instance_filesystem_utilization`  |  `ClusterName` `InstanceId`, `ContainerInstanceId`, `ClusterName`  |  叢集中單一 EC2 執行個體正在使用的檔案系統容量總百分比。 單位：百分比  | 
|  `instance_memory_limit`  |  `ClusterName`  |  可指派至此叢集中單一 EC2 執行個體的記憶體數量上限 (以位元組為單位)。 單位：位元組  | 
|  `instance_memory_reserved_capacity`  |  `ClusterName` `InstanceId`, `ContainerInstanceId`, `ClusterName`  |  目前保留在叢集中單一 EC2 執行個體上的記憶體百分比。 單位：百分比  | 
|  `instance_memory_utilization`  |  `ClusterName` `InstanceId`, `ContainerInstanceId`, `ClusterName`  |  叢集中單一 EC2 執行個體正在使用的記憶體總百分比。  如果將 Java ZGC 垃圾收集器用於您的應用程式，則此指標可能不準確。  單位：百分比  | 
|  `instance_memory_working_set`  |  `ClusterName`  |  叢集中單一 EC2 執行個體正在使用的記憶體數量 (以位元組為單位)。  如果將 Java ZGC 垃圾收集器用於您的應用程式，則此指標可能不準確。  單位：位元組  | 
|  `instance_network_total_bytes`  |  `ClusterName`  |  叢集中單一 EC2 執行個體上透過網路傳輸和接收的每秒位元組總數。 單位：位元組/秒  | 
|  `instance_number_of_running_tasks`  |  `ClusterName`  |  叢集中單一 EC2 執行個體上執行的任務數目。 單位：計數  | 

# Amazon ECS Container Insights 指標
<a name="Container-Insights-metrics-ECS"></a>

Container Insights 指標可提供額外的網路、儲存和暫時性儲存指標。這些指標可提供比標準 Amazon ECS 指標更多的資訊。Container Insights 可與 CloudWatch Logs 整合。可以建立指標變更與日誌項目的關聯，以便更輕鬆地進行疑難排解。Container Insights 也會透過在所有任務中平均資料，顯示叢集、服務和精靈整體統計資料。這可提供服務和協助程式運作狀態的更高層級檢視，協助環境監控和容量規劃。

**使用案例**
+ **問題識別和疑難排解**：透過分析任務狀態轉換模式來追蹤失敗的部署，從而快速確定故障點。透過全面檢查任務啟動序列和初始化行為來診斷組態問題
+ **叢集和服務層級運作狀態評估**：顯示叢集的平均任務效能。這種方法可調節異常值，以提供更穩定的叢集和服務運作狀態檢視。使用這些洞見進行一般服務監控，因為極端值可能會產生誤導 
+ **服務可用性問題**：透過監控執行中的任務計數指標來偵測部署失敗。將服務事件日誌與效能指標建立關聯，以了解基礎設施影響。追蹤任務重新啟動模式，以確定不穩定的服務或基礎設施問題
+ **平均負載的容量規劃**：它有助於根據典型任務行為模式確定資源需求，提供一致的指標以支援有效的長期規劃，並減少短期尖峰對容量決策的影響
+ **提供其他指標**：收集付費指標中無法使用的其他網路、儲存和暫時性儲存指標

如需 Amazon ECS 指標的詳細資訊，請參閱 [Amazon ECS 服務使用率指標使用案例](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/service_utilization-metrics-explanation.html)，以及具有增強可觀測性的 Container Insights 的資訊 ([具有增強可觀測性指標的 Amazon ECS Container Insights](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Container-Insights-enhanced-observability-metrics-ECS.html))。

**注意**  
Amazon ECS 受管協助程式指標使用與服務指標相同的`ECS/ContainerInsights`命名空間和`ServiceName`維度。對於協助程式指標，`ServiceName`維度值使用格式 `daemon:daemon-name`。例如，名為 的協助程式`my-daemon`的`ServiceName`維度值為 `daemon:my-daemon`。下表中包含`ServiceName`維度的所有指標也適用於 Managed Daemons。

下表列出 Container Insights 為 Amazon ECS 收集的指標和維度。這些指標會在 `ECS/ContainerInsights` 命名空間中。如需詳細資訊，請參閱[指標](cloudwatch_concepts.md#Metric)。

如果您沒有在主控台中看到任何容器洞見指標，請確定您已完成容器洞見的設定。在完整設定容器洞見前指標都不會出現。如需詳細資訊，請參閱[設定 Container Insights](deploy-container-insights.md)。

當您完成 [在 Amazon ECS 上設定 Container Insights](deploy-container-insights-ECS-cluster.md) 中的步驟後即可使用下列指標。


| 指標名稱 | 維度 | Description | 
| --- | --- | --- | 
|  `ContainerInstanceCount`  |  `ClusterName`  |  執行 Amazon ECS 代理程式並與叢集註冊的 EC2 執行個體數量。 只會針對在叢集中執行 Amazon ECS 任務的容器執行個體來收集此指標。對於沒有任何 Amazon ECS 任務的空容器執行個體，不會收集此指標。 單位：計數  | 
|  `CpuUtilized`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName`  |  資源中任務所使用的 CPU 單位，由您正在使用的維度設定所指定。 也適用於 Managed Daemons。 單位：無  | 
|  `CpuReserved`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName`  |  資源中任務所預留的 CPU 單位，由您正在使用的維度設定所指定。 根據任務定義中定義的 CPU 預留來收集此指標，例如在任務或所有容器層級。如果在任務定義中未定義，則會使用執行個體 CPU 預留。 也適用於 Managed Daemons。 單位：無  | 
|  `DeploymentCount`  |  `ServiceName`, `ClusterName`  |  在 Amazon ECS 服務中部署的數量。 單位：計數  | 
|  `DesiredTaskCount`  |  `ServiceName`, `ClusterName`  |  Amazon ECS 服務所需的任務數。 單位：計數  | 
|  `EBSFilesystemSize`  |  `VolumeName`, `TaskDefinitionFamily`, `ClusterName` `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName`  |  分配給您正在使用之維度所指定資源的 Amazon EBS 檔案系統儲存總量，以 GB 為單位。 此指標僅適用於在 Fargate 上使用平台版本 `1.4.0` 執行的 Amazon ECS 基礎設施上執行的任務，或使用容器代理程式版本 `1.79.0` 或更新版本的 Amazon EC2 執行個體。 也適用於 Managed Daemons。 單位：千兆位元組 (GB)  | 
|  `EBSFilesystemUtilized`  |  `VolumeName`, `TaskDefinitionFamily`, `ClusterName` `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName`  |  您正在使用之維度所指定資源的 Amazon EBS 檔案系統儲存總量，以 GB 為單位。 此指標僅適用於在 Fargate 上使用平台版本 `1.4.0` 執行的 Amazon ECS 基礎設施上執行的任務，或使用容器代理程式版本 `1.79.0` 或更新版本的 Amazon EC2 執行個體。 對於在 Fargate 上執行的任務，Fargate 會在只有 Fargate 使用的磁碟上預留空間。Fargate 使用的空間不會產生相關費用，但您可以使用 `df` 等工具檢視此額外儲存空間。 也適用於 Managed Daemons。 單位：千兆位元組 (GB)  | 
|  EphemeralStorageReserved [1](#ci-metrics-ecs-storage-fargate-note)  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName`  |  資源中從暫時性儲存裝置中所預留的位元組數，該資源由您正在使用的維度所指定。暫時性儲存裝置會用於容器根檔案系統，以及容器映像和任務定義中定義的任何綁定掛載主機磁碟區。在執行中的任務中，無法變更暫時性儲存裝置的數量。 此指標僅適用於在 Fargate Linux 平台版本 1.4.0 或更新版本上執行的任務。 也適用於 Managed Daemons。 單位：千兆位元組 (GB)  | 
|  EphemeralStorageUtilized [1](#ci-metrics-ecs-storage-fargate-note)  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName`  |  資源中從暫時性儲存裝置中使用的位元組數，該資源由您正在使用的維度所指定。暫時性儲存裝置會用於容器根檔案系統，以及容器映像和任務定義中定義的任何綁定掛載主機磁碟區。在執行中的任務中，無法變更暫時性儲存裝置的數量。 此指標僅適用於在 Fargate Linux 平台版本 1.4.0 或更新版本上執行的任務。 也適用於 Managed Daemons。 單位：千兆位元組 (GB)  | 
|  `InstanceOSFilesystemUtilization`  |  `CapacityProviderName`, `ClusterName`, `ContainerInstanceId`, `EC2InstanceId` `ClusterName`  |  用於作業系統磁碟區的總磁碟空間百分比。  | 
|  `InstanceDataFilesystemUtilization`  |  `CapacityProviderName`, `ClusterName`, `ContainerInstanceId`, `EC2InstanceId` `ClusterName`  |  用於資料磁碟區的總磁碟空間百分比。  | 
|  `MemoryUtilized`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName`  |  資源中任務正在使用的記憶體，由您正在使用的維度設定所指定。  如果將 Java ZGC 垃圾收集器用於您的應用程式，則此指標可能不準確。 雖然 `MemoryUtilized` 和 `MemoryReserved` 標記為「MB」，但實際單位為 MiB。  也適用於 Managed Daemons。 單位：MB  | 
|  `MemoryReserved`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName`  |  資源中任務所預留的記憶體，由您正在使用的維度設定所指定。根據任務定義中定義的記憶體預留來收集此指標，例如在任務或所有容器層級。如果在任務定義中未定義，則會使用執行個體記憶體預留。 也適用於 Managed Daemons。 單位：MB  雖然 `MemoryUtilized` 和 `MemoryReserved` 標記為「MB」，但實際單位為 MiB。   | 
|  `NetworkRxBytes`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName`  |  資源收到的位元組數，由您正在使用的維度所指定。從 Docker 執行期獲取此指標。 此指標僅適用於使用 `awsvpc` 或 `bridge` 網路模式的任務中的容器。 也適用於 Managed Daemons。 單位：位元組/秒  | 
|  `NetworkTxBytes`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName`  |  資源傳輸的位元組數，由您正在使用的維度所指定。從 Docker 執行期獲取此指標。 此指標僅適用於使用 `awsvpc` 或 `bridge` 網路模式的任務中的容器。 也適用於 Managed Daemons。 單位：位元組/秒  | 
|  `PendingTaskCount`  |  `ServiceName`, `ClusterName`  |  目前處於 `PENDING` 狀態的任務數。 單位：計數  | 
|  `RunningTaskCount`  |  `ServiceName`, `ClusterName`  |  目前處於 `RUNNING` 狀態的任務數。 單位：計數  | 
|  `RestartCount`  |  `ClusterName` `ClusterName`, `ServiceName` `ClusterName`, `TaskDefinitionFamily`  |  Amazon ECS 任務中的容器重新啟動的次數。 只會針對已啟用重新啟動政策的容器收集此指標。 也適用於 Managed Daemons。 單位：計數  | 
|  `ServiceCount`  |  `ClusterName`  |  叢集中的服務數量。 單位：計數  | 
|  `StorageReadBytes`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName`  |  資源中從執行個體儲存裝置讀取的位元組數，該資源由您正在使用的維度所指定。這不包括儲存裝置的讀取位元組。從 Docker 執行期獲取此指標。 也適用於 Managed Daemons。 單位：位元組  | 
|  `StorageWriteBytes`  |  `TaskDefinitionFamily`, `ClusterName` `ServiceName`, `ClusterName` `ClusterName`  |  資源中寫入儲存裝置的位元組數，該資源由您正在使用的維度所指定。從 Docker 執行期獲取此指標。 也適用於 Managed Daemons。 單位：位元組  | 
|  `TaskCount`  |  `ClusterName`  |  叢集中執行的任務數。 單位：計數  | 
|  `TaskSetCount`  |  `ServiceName`, `ClusterName`  |  服務中的任務集數。 單位：計數  | 

**注意**  
此 `EphemeralStorageReserved` 與 `EphemeralStorageUtilized` 指標僅適用於在 Fargate Linux 平台版本 1.4.0 或更新版本上執行的任務。  
Fargate 會在磁盤上保留空間。此空間僅由 Fargate 使用。我們不會向您收費。它不會顯示在這些指標中。但是，您可以在其他工具 (例如 `df`) 中看到此額外儲存空間。

當您完成 [部署 CloudWatch 代理程式以收集 Amazon ECS 上的 EC2 執行個體層級指標](deploy-container-insights-ECS-instancelevel.md) 中的步驟後即可使用下列指標


| 指標名稱 | 維度 | Description | 
| --- | --- | --- | 
|  `instance_cpu_limit`  |  `ClusterName`  |  可指派至此叢集中單一 EC2 執行個體的 CPU 單位數量上限。 單位：無  | 
|  `instance_cpu_reserved_capacity`  |  `ClusterName` `InstanceId`, `ContainerInstanceId`, `ClusterName`  |  目前保留在叢集中單一 EC2 執行個體上的 CPU 百分比。 單位：百分比  | 
|  `instance_cpu_usage_total`  |  `ClusterName`  |  叢集中單一 EC2 執行個體正在使用的 CPU 單位數目。 單位：無  | 
|  `instance_cpu_utilization`  |  `ClusterName` `InstanceId`, `ContainerInstanceId`, `ClusterName`  |  叢集中單一 EC2 執行個體正在使用的 CPU 單位總百分比。 單位：百分比  | 
|  `instance_filesystem_utilization`  |  `ClusterName` `InstanceId`, `ContainerInstanceId`, `ClusterName`  |  叢集中單一 EC2 執行個體正在使用的檔案系統容量總百分比。 單位：百分比  | 
|  `instance_memory_limit`  |  `ClusterName`  |  可指派至此叢集中單一 EC2 執行個體的記憶體數量上限 (以位元組為單位)。 單位：位元組  | 
|  `instance_memory_reserved_capacity`  |  `ClusterName` `InstanceId`, `ContainerInstanceId`, `ClusterName`  |  目前保留在叢集中單一 EC2 執行個體上的記憶體百分比。 單位：百分比  | 
|  `instance_memory_utilization`  |  `ClusterName` `InstanceId`, `ContainerInstanceId`, `ClusterName`  |  叢集中單一 EC2 執行個體正在使用的記憶體總百分比。  如果將 Java ZGC 垃圾收集器用於您的應用程式，則此指標可能不準確。  單位：百分比  | 
|  `instance_memory_working_set`  |  `ClusterName`  |  叢集中單一 EC2 執行個體正在使用的記憶體數量 (以位元組為單位)。  如果將 Java ZGC 垃圾收集器用於您的應用程式，則此指標可能不準確。  單位：位元組  | 
|  `instance_network_total_bytes`  |  `ClusterName`  |  叢集中單一 EC2 執行個體上透過網路傳輸和接收的每秒位元組總數。 單位：位元組/秒  | 
|  `instance_number_of_running_tasks`  |  `ClusterName`  |  叢集中單一 EC2 執行個體上執行的任務數目。 單位：計數  | 

# 具有增強可觀測性指標的 Amazon EKS 和 Kubernetes Container Insights
<a name="Container-Insights-metrics-enhanced-EKS"></a>

下表列出具有增強可觀測性的 Container Insights 為 Amazon EKS 和 Kubernetes 收集的指標和維度。這些指標會在 `ContainerInsights` 命名空間中。如需詳細資訊，請參閱[指標](cloudwatch_concepts.md#Metric)。

如果沒有在主控台中看到任何具有增強可觀測性的 Container Insights 指標，請確定您已完成具有增強可觀測性的 Container Insights 的設定。在完整設定具有增強可觀測性的 Container Insights 之前，指標都不會出現。如需詳細資訊，請參閱[設定 Container Insights](deploy-container-insights.md)。

如果使用 1.5.0 版或更新版本的 Amazon EKS 附加元件或 1.300035.0 版的 CloudWatch 代理程式，則會針對 Linux 和 Windows 節點收集下表列出的大多數指標。請參閱資料表的**指標名稱**欄，查看哪些指標不是針對 Windows 收集的。

使用在叢集和服務層級提供彙總指標的舊版 Container Insights，這些指標作為自訂指標計費。使用 Container Insights 搭配 Amazon EKS 的增強可觀測性，Container Insights 指標會按觀測，而不是存放或擷取的指標計費。如需 CloudWatch 定價的詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

**注意**  
在 Windows 中，不會為主機程序容器收集網路指標，例如 `pod_network_rx_bytes` 和 `pod_network_tx_bytes`。  
在 RedHat OpenShift on AWS (ROSA) 叢集 上，`node_diskio_io_service_bytes_total`不會收集 `node_diskio_io_serviced_total`和 等磁碟指標。


| 指標名稱 | 維度 | Description | 
| --- | --- | --- | 
|  `cluster_failed_node_count`  |  `ClusterName`  |  叢集中失敗的工作者節點數量。如果節點受困於任何*節點條件*，則會將其判定為失敗。如需詳細資訊，請參閱 Kubernetes 文件中的[條件](https://kubernetes.io/docs/concepts/architecture/nodes/#condition)。  | 
|  `cluster_node_count`  |  `ClusterName`  |  叢集中的工作者節點總數。  | 
|  `namespace_number_of_running_pods`  |  `Namespace` `ClusterName` `ClusterName`  |  資源中每個命名空間執行的 pod 數量，該資源由您正在使用的維度所指定。  | 
|  `node_cpu_limit`  |  `ClusterName`  `ClusterName`, `InstanceId`, `NodeName`   |  可指派至此叢集中單一節點的 CPU 單位數量上限。  | 
|  `node_cpu_reserved_capacity`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  為節點元件 (例如 kubelet、kube-proxy 和 Docker) 預留的 CPU 單位百分比。 公式：`node_cpu_request / node_cpu_limit`  `node_cpu_request` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `node_cpu_usage_total`  |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`  |  叢集中節點上正在使用的 CPU 單位數量。  | 
|  `node_cpu_utilization`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  叢集中節點上正在使用的 CPU 單位百分比總數。 公式：`node_cpu_usage_total / node_cpu_limit`  | 
|  `node_filesystem_utilization`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  叢集中節點上正在使用的檔案系統容量百分比總數。 公式：`node_filesystem_usage / node_filesystem_capacity`  `node_filesystem_usage` 和 `node_filesystem_capacity` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `node_memory_limit`  |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`   |  可指派至此叢集中單一節點的記憶體數量上限 (以位元組為單位)。  | 
|  `node_filesystem_inodes`  在 Windows 中不可用。  |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`   |  節點上的 inode 總數 (已使用和未使用)。  | 
|  `node_filesystem_inodes_free` 在 Windows 中不可用。  |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`   |  節點上未使用的 inode 數目。  | 
|  `node_gpu_limit` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`  |  節點上可用的 GPU 總數。  | 
|  `node_gpu_usage_total` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`  |  節點上執行中 Pod 正在使用的 GPU 數量。  | 
|  `node_gpu_reserved_capacity` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`  | 
|  `node_memory_reserved_capacity`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  目前在叢集中節點上使用的記憶體百分比。 公式：`node_memory_request / node_memory_limit`  `node_memory_request` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `node_memory_utilization`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  節點目前使用的記憶體百分比。這是節點記憶體使用量除以節點記憶體限制的百分比。 公式：`node_memory_working_set / node_memory_limit`。  | 
|  `node_memory_working_set`  |  `ClusterName`  `ClusterName`, `InstanceId`, `NodeName`   |  叢集中運作中一組節點中正在使用的記憶體數量 (以位元組為單位)。  | 
|  `node_network_total_bytes`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  叢集中每個節點每秒透過網路傳輸和接收的位元組總數。 公式：`node_network_rx_bytes + node_network_tx_bytes`  `node_network_rx_bytes` 和 `node_network_tx_bytes` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `node_number_of_running_containers`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  叢集中每個節點執行中的容器數。  | 
|  `node_number_of_running_pods`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  叢集中每個節點執行中的 pod 數。  | 
|  `node_status_allocatable_pods`   |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`   |  可根據節點的可配置資源指派其 Pod 數目，其定義為在計算系統常駐程式保留項目和硬式移出閾值之後節點容量的剩餘部分。  | 
|  `node_status_capacity_pods`  |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`   |  可根據節點容量指派給節點的 Pod 數目。  | 
|  `node_status_condition_ready`   |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`   |  指示 Amazon EC2 節點的節點狀態條件 `Ready` 是否為 True。  | 
|  `node_status_condition_memory_pressure`   |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`   |  表示節點狀態條件 `MemoryPressure` 是否為 True。  | 
|  `node_status_condition_pid_pressure`   |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`   |  表示節點狀態條件 `PIDPressure` 是否為 True。  | 
|  `node_status_condition_disk_pressure`   |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`   |  表示節點狀態條件 `OutOfDisk` 是否為 True。  | 
|  `node_status_condition_unknown`   |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`   |  表示是否有任何節點狀態條件為「未知」。  | 
|  `node_interface_network_rx_dropped`  |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`   |  節點上網路介面接收並隨後捨棄的封包數目。  | 
|  `node_interface_network_tx_dropped`  |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`   |  節點上的網路介面傳輸但捨棄的封包數目。  | 
|  `node_diskio_io_service_bytes_total`  它不適用於 Windows 或 ROSA 叢集。  |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`   |  節點上所有 I/O 操作傳送的位元組總數。  | 
|  `node_diskio_io_serviced_total` 它不適用於 Windows 或 ROSA 叢集。  |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`   |  節點上的 I/O 操作總數。  | 
|  `pod_cpu_reserved_capacity`  |  `PodName`, `Namespace`, `ClusterName` `ClusterName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  `ClusterName`, `Namespace`, `Service`   |  叢集中每個 pod 預留的 CPU 容量。 公式：`pod_cpu_request / node_cpu_limit`  `pod_cpu_request` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `pod_cpu_utilization`  |  `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName` `Service`, `Namespace`, `ClusterName` `ClusterName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`   |  Pod 使用的 CPU 單位百分比。 公式：`pod_cpu_usage_total / node_cpu_limit`  | 
|  `pod_cpu_utilization_over_pod_limit`  |  `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName` `Service`, `Namespace`, `ClusterName` `ClusterName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`   |  Pod 正在使用的 CPU 單位百分比，此百分比與 Pod 限制相對。 公式：`pod_cpu_usage_total / pod_cpu_limit`  | 
|  `pod_memory_reserved_capacity`  |  `PodName`, `Namespace`, `ClusterName` `ClusterName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  `ClusterName`, `Namespace`, `Service`   |  為 Pod 保留的記憶體百分比。 公式：`pod_memory_request / node_memory_limit`  `pod_memory_request` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `pod_memory_utilization`  |  `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName` `Service`, `Namespace`, `ClusterName` `ClusterName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`   |  Pod 目前使用的記憶體百分比。 公式：`pod_memory_working_set / node_memory_limit`  | 
|  `pod_memory_utilization_over_pod_limit`  |  `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName` `Service`, `Namespace`, `ClusterName` `ClusterName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`   |  Pod 正在使用的記憶體百分比，此百分比與 Pod 限制相對。如果 Pod 中有任何容器未定義記憶體限制，這個指標將不會顯示。 公式：`pod_memory_working_set / pod_memory_limit`  | 
|  `pod_network_rx_bytes`  |  `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName` `Service`, `Namespace`, `ClusterName` `ClusterName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`   |  Pod 透過網路每秒接收的位元組數。 公式：`sum(pod_interface_network_rx_bytes)`  `pod_interface_network_rx_bytes` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `pod_network_tx_bytes`  |  `PodName`, `Namespace`, `ClusterName` `Namespace,` `ClusterName` `Service`, `Namespace`, `ClusterName` `ClusterName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`   |  Pod 透過網路每秒傳輸的位元組數。 公式：`sum(pod_interface_network_tx_bytes)`  `pod_interface_network_tx_bytes` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `pod_cpu_request`   |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  Pod 的 CPU 請求。 公式：`sum(container_cpu_request)`  `pod_cpu_request` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `pod_memory_request`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  Pod 的記憶體請求。 公式：`sum(container_memory_request)`  `pod_memory_request` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `pod_cpu_limit`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  Pod 中的容器定義的 CPU 限制。如果 Pod 中有任何容器未定義 CPU 限制，這個指標將不會顯示。 公式：`sum(container_cpu_limit)`  `pod_cpu_limit` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `pod_memory_limit`   |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  Pod 中的容器定義的記憶體限制。如果 Pod 中有任何容器未定義記憶體限制，這個指標將不會顯示。 公式：`sum(container_memory_limit)`  `pod_cpu_limit` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `pod_status_failed`   |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  表示 Pod 中的所有容器都已終止，且至少有一個容器已經以非零狀態終止，或已由系統終止。  | 
|  `pod_status_ready`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  表示 Pod 中的所有容器都已就緒，且已達到條件 `ContainerReady`。  | 
|  `pod_status_running`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  表示 Pod 中的所有容器都在執行中。  | 
|  `pod_status_scheduled`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  表示 Pod 已排程至節點。  | 
|  `pod_status_unknown`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  表示無法取得 Pod 的狀態。  | 
|  `pod_status_pending`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  表示叢集已接受 Pod，但有一個或多個容器尚未準備就緒。  | 
|  `pod_status_succeeded`   |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  表示 Pod 中的所有容器都已成功終止，而且不會重新啟動。  | 
|  `pod_number_of_containers`   |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  報告 Pod 規格中定義的容器數目。  | 
|  `pod_number_of_running_containers`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  報告 Pod 中目前處於 `Running` 狀態的容器數目。  | 
|  `pod_container_status_terminated`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  報告 Pod 中處於 `Terminated` 狀態的容器數目。  | 
|  `pod_container_status_running`   |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  報告 Pod 中處於 `Running` 狀態的容器數目。  | 
|  `pod_container_status_waiting`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  報告 Pod 中處於 `Waiting` 狀態的容器數目。  | 
|  `pod_container_status_waiting_reason_crash_loop_back_off`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  報告 Pod 中因 `CrashLoopBackOff` 錯誤而待定的容器數量，其中容器會重複無法啟動。  | 
|  `pod_container_status_waiting_reason_create_container_config_error`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  報告 Pod 中因為 `CreateContainerConfigError` 原因而待定的容器數目。這是因為建立容器組態時發生錯誤。  | 
|  `pod_container_status_waiting_reason_create_container_error`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  報告 Pod 中因建立容器時發生錯誤 `CreateContainerError` 而待定的容器數量。  | 
|  `pod_container_status_waiting_reason_image_pull_error`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  報告 Pod 中因 `ErrImagePull`、`ImagePullBackOff` 或 `InvalidImageName` 而待定的容器數量。這些情況是因為提取容器映像時發生錯誤。  | 
|  `pod_container_status_waiting_reason_start_error`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  報告 Pod 中因啟動容器時發生錯誤 `StartError` 而待定的容器數量。  | 
|  `pod_container_status_terminated_reason_oom_killed`   |  `ContainerName`, `FullPodName`, `PodName`, `Namespace`, `ClusterName` `ContainerName`, `PodName`, `Namespace`, `ClusterName` `ClusterName`  |  指示因超過記憶體限制而終止 Pod。只有在發生此問題時，才會顯示此指標。  | 
|  `pod_interface_network_rx_dropped`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  Pod 上網路介面接收並隨後捨棄的封包數目。  | 
|  `pod_interface_network_tx_dropped`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  |  針對 Pod 傳輸但捨棄的封包數目。  | 
| `pod_memory_working_set` |  `ClusterName` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  | Pod 目前正在使用的記憶體 (以位元組為單位)。 | 
| `pod_cpu_usage_total` |  `ClusterName` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName`  | Pod 使用的 CPU 單位數。 | 
|  `container_cpu_utilization`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName`, `ContainerName` `PodName`, `Namespace`, `ClusterName`, `ContainerName`, `FullPodName`  |  容器使用的 CPU 單位百分比。 公式：`container_cpu_usage_total / node_cpu_limit`  `container_cpu_utilization` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `container_cpu_utilization_over_container_limit`   |  `ClusterName` `PodName`, `Namespace`, `ClusterName`, `ContainerName` `PodName`, `Namespace`, `ClusterName`, `ContainerName`, `FullPodName`  |  相對於容器限制，容器正在使用的 CPU 單位百分比。如果容器未定義 CPU 限制，這個指標將不會顯示。 公式：`container_cpu_usage_total / container_cpu_limit`  `container_cpu_utilization_over_container_limit` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `container_memory_utilization`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName`, `ContainerName` `PodName`, `Namespace`, `ClusterName`, `ContainerName`, `FullPodName`  |  容器使用的記憶體單位百分比。 公式：`container_memory_working_set / node_memory_limit`  `container_memory_utilization` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `container_memory_utilization_over_container_limit`    |  `ClusterName` `PodName`, `Namespace`, `ClusterName`, `ContainerName` `PodName`, `Namespace`, `ClusterName`, `ContainerName`, `FullPodName`  |  相對於容器限制，容器正在使用的記憶體單位百分比。如果容器未定義記憶體限制，這個指標將不會顯示。 公式：`container_memory_working_set / container_memory_limit`  `container_memory_utilization_over_container_limit` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `container_memory_failures_total`  在 Windows 中不可用。  |  `ClusterName` `PodName`, `Namespace`, `ClusterName`, `ContainerName` `PodName`, `Namespace`, `ClusterName`, `ContainerName`, `FullPodName`  |  容器經歷的記憶體配置失敗次數。  | 
|  `pod_number_of_container_restarts`  |  PodName、`Namespace`、`ClusterName`  |  Pod 中重新啟動的容器總數。  | 
|  `service_number_of_running_pods`  |  服務、`Namespace`、`ClusterName` `ClusterName`  |  叢集中執行服務的 Pod 數量。  | 
|  `replicas_desired`   |  `ClusterName` `PodName`, `Namespace`, `ClusterName`  |  工作負載規格中定義的工作負載所需 Pod 數目。  | 
|  `replicas_ready`   |  `ClusterName` `PodName`, `Namespace`, `ClusterName`  |  已達到就緒狀態的工作負載 Pod 數目。  | 
|  `status_replicas_available`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName`  |  可供工作負載使用的 Pod 數目。當 Pod 準備好用於工作負載規格中定義的 `minReadySeconds` 時可供使用。  | 
|  `status_replicas_unavailable`  |  `ClusterName` `PodName`, `Namespace`, `ClusterName`  |  工作負載無法使用的 Pod 數目。當 Pod 準備好用於工作負載規格中定義的 `minReadySeconds` 時可供使用。如果 Pod 不符合此條件，則無法使用。  | 
|  `apiserver_storage_objects`  |  `ClusterName` `ClusterName`, `resource`  |  上次檢查時存放在 etcd 中的物件數目。  | 
|  `apiserver_storage_db_total_size_in_bytes`  |  `ClusterName` `ClusterName`, `endpoint`  |  實體配置的儲存資料庫檔案總大小 (以位元組為單位)。此指標為實驗性質，並且可能會在 Kubernetes 的未來版本中變更。 單位：位元組 有意義的統計資料：總和、平均值、最小值、最大值  | 
|  `apiserver_request_total`  |  `ClusterName` `ClusterName`, `code`, `verb`  |  向 Kubernetes API 伺服器發出的 API 請求總數。  | 
|  `apiserver_request_duration_seconds`  |  `ClusterName` `ClusterName`, `verb`  |  向 Kubernetes API 伺服器發出的 API 請求的回應延遲。  | 
|  `apiserver_admission_controller_admission_duration_seconds`  |  `ClusterName` `ClusterName`, `operation`  |  許可控制器延遲 (以秒為單位)。許可控制器是攔截向 Kubernetes API 伺服器發出請求的程式碼。  | 
|  `rest_client_request_duration_seconds`   |  `ClusterName` `ClusterName`, `operation`  |  用戶端呼叫 Kubernetes API 伺服器時遇到的回應延遲。此指標為實驗性質，並且可能會在 Kubernetes 的未來版本中變更。  | 
|  `rest_client_requests_total`   |  `ClusterName` `ClusterName`, `code`, `method`  |  用戶端向 Kubernetes API 伺服器發出的 API 請求總數。此指標為實驗性質，並且可能會在 Kubernetes 的未來版本中變更。  | 
|  `etcd_request_duration_seconds`   |  `ClusterName` `ClusterName`, `operation`  |  對 Etcd 的 API 呼叫的回應延遲。此指標為實驗性質，並且可能會在 Kubernetes 的未來版本中變更。  | 
|  `apiserver_storage_size_bytes`   |  `ClusterName` `ClusterName`, `endpoint`  |  實體配置的儲存資料庫檔案大小 (以位元組為單位)。此指標為實驗性質，並且可能會在 Kubernetes 的未來版本中變更。  | 
|  `apiserver_longrunning_requests`  |  `ClusterName` `ClusterName`, `resource`  |  向 Kubernetes API 伺服器發出的長時間執行的作用中請求數目。  | 
|  `apiserver_current_inflight_requests`  |  `ClusterName` `ClusterName`, `request_kind`  |  Kubernetes API 伺服器正在處理的請求數目。  | 
|  `apiserver_admission_webhook_admission_duration_seconds`  |  `ClusterName` `ClusterName`, `name`  |  許可 Webhook 延遲 (以秒為單位)。許可 Webhook 是接收許可請求並對其執行某些操作的 HTTP 回呼。  | 
|  `apiserver_admission_step_admission_duration_seconds`   |  `ClusterName` `ClusterName`, `operation`  |  許可子步驟延遲 (以秒為單位)。  | 
|  `apiserver_requested_deprecated_apis`   |  `ClusterName` `ClusterName`, `group`  |  在 Kubernetes API 伺服器上發出的取代 API 的請求數目。  | 
|  `apiserver_request_total_5xx`  |  `ClusterName` `ClusterName`, `code`, `verb`  |  向 Kubernetes API 伺服器發出的請求數目，該請求使用 5XX HTTP 回應碼做出回應。  | 
|  `apiserver_storage_list_duration_seconds`   |  `ClusterName` `ClusterName`, `resource`  |  Etc 列示物件的回應延遲。此指標為實驗性質，並且可能會在 Kubernetes 的未來版本中變更。  | 
|  `apiserver_flowcontrol_request_concurrency_limit`   |  `ClusterName` `ClusterName`, `priority_level`  |  目前在 API Priority and Fairness 子系統中執行請求所使用的執行緒數目。  | 
|  `apiserver_flowcontrol_rejected_requests_total`   |  `ClusterName` `ClusterName`, `reason`  |  API 優先順序與公平性子系統拒絕的請求數目。此指標為實驗性質，並且可能會在 Kubernetes 的未來版本中變更。  | 
|  `apiserver_current_inqueue_requests`   |  `ClusterName` `ClusterName`, `request_kind`  |  Kubernetes API 伺服器排入佇列的請求數目。此指標為實驗性質，並且可能會在 Kubernetes 的未來版本中變更。  | 

## NVIDIA GPU 指標
<a name="Container-Insights-metrics-EKS-GPU"></a>

從 CloudWatch 代理程式的 `1.300034.0` 版本開始，適用於 Amazon EKS 的具有增強可觀測性的 Container Insights 預設會從 EKS 工作負載收集 NVIDIA GPU 指標。必須使用 CloudWatch Observability EKS 附加元件版本 `v1.3.0-eksbuild.1` 或更新版本來安裝 CloudWatch 代理程式。如需詳細資訊，請參閱[使用 Amazon CloudWatch Observability EKS 附加元件或 Helm Chart 安裝 CloudWatch 代理程式](install-CloudWatch-Observability-EKS-addon.md)。收集的 NVIDIA GPU 指標會列在本節的資料表中。

若要讓 Container Insights 收集 NVIDIA GPU 指標，必須滿足下列先決條件：
+ 必須搭配使用適用於 Amazon EKS 的具有增強可觀測性的 Container Insights 與 Amazon CloudWatch Observability EKS 附加元件版本 `v1.3.0-eksbuild.1` 或更新版本。
+ [適用於 Kubernetes 的 NVIDIA 裝置外掛程式](https://github.com/NVIDIA/k8s-device-plugin)必須安裝在叢集中。
+ [NVIDIA 容器工具組](https://github.com/NVIDIA/nvidia-container-toolkit)必須安裝在叢集的節點上。例如，Amazon EKS 最佳化加速 AMI 是用必要的元件建置而成。

可以選擇不收集 NVIDIA GPU 指標，方法是將 CloudWatch 代理程式組態檔案中的 `accelerated_compute_metrics` 選項設定為 `false`。如需詳細資訊和選擇退出組態範例，請參閱 [(選用) 額外組態](install-CloudWatch-Observability-EKS-addon.md#install-CloudWatch-Observability-EKS-addon-configuration)。


| 指標名稱 | 維度 | Description | 
| --- | --- | --- | 
|  `container_gpu_memory_total` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `GpuDevice`  |  配置給容器之 GPU 上的影格緩衝區總大小 (以位元組為單位)。  | 
|  `container_gpu_memory_used` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `GpuDevice`  |  配置給容器之 GPU 上使用的影格緩衝區位元組數目。  | 
|  `container_gpu_memory_utilization` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `GpuDevice`  |  配置給容器之 GPU 上使用的影格緩衝區百分比。  | 
|  `container_gpu_power_draw` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `GpuDevice`  |  配置給容器之 GPU 的用電量 (瓦)。  | 
|  `container_gpu_temperature` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `GpuDevice`  |  配置給容器之 GPU 的溫度 (攝氏度)。  | 
|  `container_gpu_utilization` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `GpuDevice`  |  配置給容器之 GPU 的使用率百分比。  | 
|  `container_gpu_tensor_core_utilization` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `GpuDevice`  |  配置給容器之 GPU 上的張量核心 （張量核心） 的百分比使用率。  | 
|  `node_gpu_memory_total` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceId`, `InstanceType`, `NodeName`, `GpuDevice`  |  配置給節點之 GPU 上的影格緩衝區總大小 (以位元組為單位)。  | 
|  `node_gpu_memory_used` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceId`, `InstanceType`, `NodeName`, `GpuDevice`  |  配置給節點之 GPU 上使用的影格緩衝區位元組數目。  | 
|  `node_gpu_memory_utilization` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceId`, `InstanceType`, `NodeName`, `GpuDevice`  |  配置給節點之 GPU 上使用的影格緩衝區百分比。  | 
|  `node_gpu_power_draw` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceId`, `InstanceType`, `NodeName`, `GpuDevice`  |  配置給節點之 GPU 的用電量 (瓦)。  | 
|  `node_gpu_temperature` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceId`, `InstanceType`, `NodeName`, `GpuDevice`  |  配置給節點之 GPU 的溫度 (攝氏度)。  | 
|  `node_gpu_utilization` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceId`, `InstanceType`, `NodeName`, `GpuDevice`  |  配置給節點之 GPU 的使用率百分比。  | 
|  `node_gpu_tensor_core_utilization` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceId`, `InstanceType`, `NodeName`, `GpuDevice`  |  配置給節點的 GPU 上張量核心的百分比使用率 （張量核心）。  | 
|  `pod_gpu_memory_total` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`. `GpuDevice`  |  配置給 Pod 之 GPU 上的影格緩衝區總大小 (以位元組為單位)。  | 
|  `pod_gpu_memory_used` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`. `GpuDevice`  |  配置給 Pod 之 GPU 上使用的影格緩衝區位元組數目。  | 
|  `pod_gpu_memory_utilization` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`. `GpuDevice`  |  配置給 Pod 之 GPU 上使用的影格緩衝區百分比。  | 
|  `pod_gpu_power_draw` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`. `GpuDevice`  |  配置給 Pod 之 GPU 的用電量 (瓦)。  | 
|  `pod_gpu_temperature` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`. `GpuDevice`  |  配置給 Pod 之 GPU 的溫度 (攝氏度)。  | 
|  `pod_gpu_utilization` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `GpuDevice`  |  配置給 Pod 之 GPU 的使用率百分比。  | 
|  `pod_gpu_tensor_core_utilization` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `GpuDevice`  |  分配給 Pod 的 GPU 上張量核心的百分比使用率 （張量核心）。  | 

### 詳細的 GPU 監控
<a name="Container-Insights-detailed-GPU-monitoring"></a>

從 CloudWatch 代理程式`1.300062.0`的版本開始，具有 Amazon EKS 增強可觀測性的 Container Insights 支援以次分鐘的收集間隔進行詳細的 GPU 監控。這解決了標準收集間隔可能完全遺漏的短期機器學習推論工作負載的監控差距。必須使用 CloudWatch Observability EKS 附加元件版本 `v4.7.0-eksbuild.1` 或更新版本來安裝 CloudWatch 代理程式。如需詳細資訊，請參閱[使用 Amazon CloudWatch Observability EKS 附加元件或 Helm Chart 安裝 CloudWatch 代理程式](install-CloudWatch-Observability-EKS-addon.md)。

根據預設，會每隔 60 秒收集和擷取 GPU 指標。啟用詳細監控後，CloudWatch 代理程式會以次分鐘的間隔 （至少 1 秒） 收集 GPU 指標，但指標仍會以 1 分鐘的間隔擷取至 CloudWatch。不過，您可以查詢每 1 分鐘期間內次分鐘資料點的統計彙總 （例如最小值、最大值和百分位數，例如 p90)，提供準確的 GPU 使用率資料和更好的資源最佳化。

#### Configuration
<a name="Container-Insights-detailed-GPU-monitoring-configuration"></a>

若要啟用詳細的 GPU 監控，請更新您的 CloudWatch 代理程式組態，以在 `kubernetes`區段中包含 `accelerated_compute_gpu_metrics_collection_interval` 參數，如下列範例所示。

```
{  
    "logs": {  
        "metrics_collected": {  
            "kubernetes": {  
                "cluster_name": "MyCluster",  
                "enhanced_container_insights": true,  
                "accelerated_compute_metrics": true,  
                "accelerated_compute_gpu_metrics_collection_interval": 1  
            }  
        }  
    }  
}
```

`accelerated_compute_gpu_metrics_collection_interval` 參數以秒為單位接受值，最小值為 1 秒。將其設定為 `1`可啟用 1 秒的收集間隔。如果未指定此參數，則會使用預設的 60 秒間隔。

如需完整的組態指示，請參閱 [設定 CloudWatch 代理程式以收集叢集指標](Container-Insights-setup-metrics.md)。

## AWS AWS Trainium 和 AWS Inferentia 的 Neuron 指標
<a name="Container-Insights-metrics-EKS-Neuron"></a>

從 CloudWatch 代理程式`1.300036.0`的版本開始，具有 Amazon EKS 增強可觀測性的 Container Insights 預設會從 AWS Trainium 和 AWS Inferentia 加速器收集加速運算指標。必須使用 CloudWatch Observability EKS 附加元件版本 `v1.5.0-eksbuild.1` 或更新版本來安裝 CloudWatch 代理程式。如需有關附加元件的詳細資訊，請參閱[使用 Amazon CloudWatch Observability EKS 附加元件或 Helm Chart 安裝 CloudWatch 代理程式](install-CloudWatch-Observability-EKS-addon.md)。如需有關 AWS Trainium 的詳細資訊，請參閱 [AWS Trainium](https://aws.amazon.com/machine-learning/trainium/)。如需 AWS Inferentia 的詳細資訊，請參閱 [AWS Inferentia](https://aws.amazon.com/machine-learning/inferentia/)。

若要讓 Container Insights 收集 AWS Neuron 指標，您必須符合下列先決條件：
+ 必須搭配使用適用於 Amazon EKS 的具有增強可觀測性的 Container Insights 與 Amazon CloudWatch Observability EKS 附加元件版本 `v1.5.0-eksbuild.1` 或更新版本。
+ [Neuron 驅動程式](https://awsdocs-neuron.readthedocs-hosted.com/en/latest/general/setup/neuron-setup/pytorch/neuronx/ubuntu/torch-neuronx-ubuntu22.html#setup-torch-neuronx-ubuntu22)必須安裝在叢集的節點上。
+ [Neuron 裝置外掛程式](https://awsdocs-neuron.readthedocs-hosted.com/en/latest/containers/kubernetes-getting-started.html)必須安裝在叢集上。例如，Amazon EKS 最佳化加速 AMI 是用必要的元件建置而成。

收集的指標會列在本節的資料表中。系統會收集 AWS Trainium、 AWS Inferentia 和 AWS Inferentia2 的指標。

CloudWatch 代理程式會從 [Neuron 監視器](https://awsdocs-neuron.readthedocs-hosted.com/en/latest/tools/neuron-sys-tools/neuron-monitor-user-guide.html)收集這些指標，並執行必要的 Kubernetes 資源關聯，以在 Pod 和容器層級交付指標


| 指標名稱 | 維度 | Description | 
| --- | --- | --- | 
|  `container_neuroncore_utilization` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `NeuronDevice`, `NeuronCore`  |  在配置給容器的 NeuronCore 擷取期間的 NeuronCore 使用率。 單位：百分比  | 
|  `container_neuroncore_memory_usage_constants` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `NeuronDevice`, `NeuronCore`  |  在配置給容器的 NeuronCore 訓練期間，用於常數的裝置記憶體量 (或在推論期間的權重)。 單位：位元組  | 
|  `container_neuroncore_memory_usage_model_code` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `NeuronDevice`, `NeuronCore`  |  配置給容器的 NeuronCore 用於模型可執行程式碼的裝置記憶體數量。 單位：位元組  | 
|  `container_neuroncore_memory_usage_model_shared_scratchpad` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `NeuronDevice`, `NeuronCore`  |  配置給容器的 NeuronCore 所共用模型的暫存器所用的裝置記憶體量。此記憶體區域預留給模型。 單位：位元組  | 
|  `container_neuroncore_memory_usage_runtime_memory` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `NeuronDevice`, `NeuronCore`  |  配置給容器的 NeuronCore 用於 Neuron 執行期的裝置記憶體數量。 單位：位元組  | 
|  `container_neuroncore_memory_usage_tensors` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `NeuronDevice`, `NeuronCore`  |  配置給容器的 NeuronCore 用於張量的裝置記憶體數量。 單位：位元組  | 
|  `container_neuroncore_memory_usage_total` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `NeuronDevice`, `NeuronCore`  |  配置給容器的 NeuronCore 所使用的記憶體總量。 單位：位元組  | 
|  `container_neurondevice_hw_ecc_events_total` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `NeuronDevice`  |  節點上 Neuron 裝置的晶片上 SRAM 和裝置記憶體的已更正和未更正 ECC 事件數。 單位：計數  | 
|  `pod_neuroncore_utilization` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `NeuronDevice`, `NeuronCore`  |  在配置給 Pod 的 NeuronCore 擷取期間的 NeuronCore 使用率。 單位：百分比  | 
|  `pod_neuroncore_memory_usage_constants` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `NeuronDevice`, `NeuronCore`  |  在配置給 Pod 的 NeuronCore 訓練期間，用於常數的裝置記憶體量 (或在推論期間的權重)。 單位：位元組  | 
|  `pod_neuroncore_memory_usage_model_code` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `NeuronDevice`, `NeuronCore`  |  配置給 Pod 的 NeuronCore 用於模型可執行程式碼的裝置記憶體數量。 單位：位元組  | 
|  `pod_neuroncore_memory_usage_model_shared_scratchpad` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `NeuronDevice`, `NeuronCore`  |  配置給 Pod 的 NeuronCore 所共用模型的暫存器所用的裝置記憶體量。此記憶體區域預留給模型。 單位：位元組  | 
|  `pod_neuroncore_memory_usage_runtime_memory` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `NeuronDevice`, `NeuronCore`  |  配置給 Pod 的 NeuronCore 用於 Neuron 執行期的裝置記憶體數量。 單位：位元組  | 
|  `pod_neuroncore_memory_usage_tensors` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `NeuronDevice`, `NeuronCore`  |  配置給 Pod 的 NeuronCore 用於張量的裝置記憶體數量。 單位：位元組  | 
|  `pod_neuroncore_memory_usage_total` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `NeuronDevice`, `NeuronCore`  |  配置給 Pod 的 NeuronCore 所使用的記憶體總量。 單位：位元組  | 
|  `pod_neurondevice_hw_ecc_events_total` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `NeuronDevice`  |  配置給 Pod 之 Neuron 裝置的晶片上 SRAM 和裝置記憶體的已更正和未更正 ECC 事件數。 單位：位元組  | 
|  `node_neuroncore_utilization` |  `ClusterName` `ClusterName`, `UltraServer` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceType`, `InstanceId`, `NodeName`, `NeuronDevice`, `NeuronCore`  |  在配置給節點的 NeuronCore 擷取期間的 NeuronCore 使用率。 單位：百分比  | 
|  `node_neuroncore_memory_usage_constants` |  `ClusterName` `ClusterName`, `UltraServer` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceType`, `InstanceId`, `NodeName`, `NeuronDevice`, `NeuronCore`  |  在配置給節點的 NeuronCore 訓練期間，用於常數的裝置記憶體量 (或在推論期間的權重)。 單位：位元組  | 
|  `node_neuroncore_memory_usage_model_code` |  `ClusterName` `ClusterName`, `UltraServer` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceType`, `InstanceId`, `NodeName`, `NeuronDevice`, `NeuronCore`  |  配置給節點的 NeuronCore 用於模型可執行程式碼的裝置記憶體數量。 單位：位元組  | 
|  `node_neuroncore_memory_usage_model_shared_scratchpad` |  `ClusterName` `ClusterName`, `UltraServer` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceType`, `InstanceId`, `NodeName`, `NeuronDevice`, `NeuronCore`  |  配置給節點的 NeuronCore 所共用模型的暫存器所用的裝置記憶體量。這是預留給模型的記憶體區域。 單位：位元組  | 
|  `node_neuroncore_memory_usage_runtime_memory` |  `ClusterName` `ClusterName`, `UltraServer` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceType`, `InstanceId`, `NodeName`, `NeuronDevice`, `NeuronCore`  |  配置給節點的 NeuronCore 用於 Neuron 執行期的裝置記憶體數量。 單位：位元組  | 
|  `node_neuroncore_memory_usage_tensors` |  `ClusterName` `ClusterName`, `UltraServer` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceType`, `InstanceId`, `NodeName`, `NeuronDevice`, `NeuronCore`  |  配置給節點的 NeuronCore 用於張量的裝置記憶體數量。 單位：位元組  | 
|  `node_neuroncore_memory_usage_total` |  `ClusterName` `ClusterName`, `UltraServer` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceType`, `InstanceId`, `NodeName`, `NeuronDevice`, `NeuronCore`  |  配置給節點的 NeuronCore 所使用的記憶體總量。 單位：位元組  | 
|  `node_neuron_execution_errors_total` |  `ClusterName` `ClusterName`, `UltraServer` `ClusterName`, `InstanceId`, `NodeName`  |  節點上的執行錯誤總數。這是由 CloudWatch 代理程式透過彙總下列類型的錯誤來計算：`generic`、`numerical`、`transient`、`model`、`runtime` 和 `hardware` 單位：計數  | 
|  `node_neurondevice_runtime_memory_used_bytes` |  `ClusterName` `ClusterName`, `UltraServer` `ClusterName`, `InstanceId`, `NodeName`  |  節點上以位元組為單位的 Neuron 裝置記憶體總用量。 單位：位元組  | 
| `node_neuron_execution_latency` |  `ClusterName` `ClusterName`, `UltraServer` `ClusterName`, `InstanceId`, `NodeName`  |  Neuron 執行時期測量的節點上的執行延遲 (單位為秒)。 單位：秒  | 
| `node_neurondevice_hw_ecc_events_total` |  `ClusterName` `ClusterName`, `UltraServer` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceId`, `NodeName`, `NeuronDevice`  |  節點上 Neuron 裝置的晶片上 SRAM 和裝置記憶體的已更正和未更正 ECC 事件數。 單位：計數  | 

## AWS Elastic Fabric Adapter (EFA) 指標
<a name="Container-Insights-metrics-EFA"></a>

從 CloudWatch 代理程式`1.300037.0`的版本開始，具有 Amazon EKS 增強可觀測性的 Container Insights 會從 Linux 執行個體上的 Amazon EKS 叢集收集 AWS Elastic Fabric Adapter (EFA) 指標。必須使用 CloudWatch Observability EKS 附加元件版本 `v1.5.2-eksbuild.1` 或更新版本來安裝 CloudWatch 代理程式。如需有關附加元件的詳細資訊，請參閱[使用 Amazon CloudWatch Observability EKS 附加元件或 Helm Chart 安裝 CloudWatch 代理程式](install-CloudWatch-Observability-EKS-addon.md)。如需有關 AWS Elastic Fabric Adapter 的詳細資訊，請參閱 [Elastic Fabric Adapter](https://aws.amazon.com/hpc/efa/)。

若要讓 Container Insights 收集 AWS Elastic Fabric 轉接器指標，您必須符合下列先決條件：
+ 必須搭配使用適用於 Amazon EKS 的具有增強可觀測性的 Container Insights 與 Amazon CloudWatch Observability EKS 附加元件版本 `v1.5.2-eksbuild.1` 或更新版本。
+ EFA 裝置外掛程式必須安裝在叢集上。如需詳細資訊，請參閱 GitHub 上的 [aws-efa-k8s-device-plugin](https://github.com/aws/eks-charts/tree/master/stable/aws-efa-k8s-device-plugin)。

收集的指標列於下列資料表中。


| 指標名稱 | 維度 | Description | 
| --- | --- | --- | 
|  `container_efa_rx_bytes` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `NetworkInterfaceId`   |  配置給容器的 EFA 裝置每秒接收的位元組數。 單位：位元組/秒  | 
|  `container_efa_tx_bytes` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `NetworkInterfaceId`   |  配置給容器的 EFA 裝置每秒傳輸的位元組數。 單位：位元組/秒  | 
|  `container_efa_rx_dropped` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `NetworkInterfaceId`   |  配置給容器的 EFA 裝置接收並捨棄的封包數。 單位：計數/秒  | 
|  `container_efa_rdma_read_bytes` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `NetworkInterfaceId`   |  配置給容器的 EFA 裝置使用遠端直接記憶體存取讀取操作每秒接收的位元組數。 單位：位元組/秒  | 
|  `container_efa_rdma_write_bytes` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `NetworkInterfaceId`   |  配置給容器的 EFA 裝置使用遠端直接記憶體存取讀取操作每秒傳輸的位元組數。 單位：位元組/秒  | 
|  `container_efa_rdma_write_recv_bytes` |  `ClusterName` `ClusterName`, `Namespace`, `PodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `ContainerName`, `NetworkInterfaceId`   |  配置給容器的 EFA 裝置在遠端直接記憶體存取寫入操作期間每秒接收的位元組數。 單位：位元組/秒  | 
|  `pod_efa_rx_bytes` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `NetworkInterfaceId`  |  配置給 Pod 的 EFA 裝置每秒接收的位元組數。 單位：位元組/秒  | 
|  `pod_efa_tx_bytes` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `NetworkInterfaceId`  |  配置給 Pod 的 EFA 裝置每秒傳輸的位元組數。 單位：位元組/秒  | 
|  `pod_efa_rx_dropped` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `NetworkInterfaceId`  |  配置給 Pod 的 EFA 裝置接收並捨棄的封包數。 單位：計數/秒  | 
|  `pod_efa_rdma_read_bytes` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `NetworkInterfaceId`  |  配置給 Pod 的 EFA 裝置使用遠端直接記憶體存取讀取操作每秒接收的位元組數。 單位：位元組/秒  | 
|  `pod_efa_rdma_write_bytes` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `NetworkInterfaceId`  |  配置給 Pod 的 EFA 裝置使用遠端直接記憶體存取讀取操作每秒傳輸的位元組數。 單位：位元組/秒  | 
|  `pod_efa_rdma_write_recv_bytes` |  `ClusterName` `ClusterName`, `Namespace` `ClusterName`, `Namespace`, `Service` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName` `ClusterName`, `Namespace`, `PodName`, `FullPodName`, `NetworkInterfaceId`  |  配置給 Pod 的 EFA 裝置在遠端直接記憶體存取寫入操作期間每秒接收的位元組數。 單位：位元組/秒  | 
|  `node_efa_rx_bytes` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceId`, `InstanceType`, `NodeName`, `NetworkInterfaceId`  |  配置給節點的 EFA 裝置每秒接收的位元組數。 單位：位元組/秒  | 
|  `node_efa_tx_bytes` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceId`, `InstanceType`, `NodeName`, `NetworkInterfaceId`  |  配置給節點的 EFA 裝置每秒傳輸的位元組數。 單位：位元組/秒  | 
|  `node_efa_rx_dropped` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceId`, `InstanceType`, `NodeName`, `NetworkInterfaceId`  |  配置給節點的 EFA 裝置接收並捨棄的封包數。 單位：計數/秒  | 
|  `node_efa_rdma_read_bytes` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceId`, `InstanceType`, `NodeName`, `NetworkInterfaceId`  |  配置給節點的 EFA 裝置使用遠端直接記憶體存取讀取操作每秒接收的位元組數。 單位：位元組/秒  | 
|  `node_efa_rdma_write_bytes` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceId`, `InstanceType`, `NodeName`, `NetworkInterfaceId`  |  配置給 Pod 的 EFA 裝置使用遠端直接記憶體存取讀取操作每秒傳輸的位元組數。 單位：位元組/秒  | 
|  `node_efa_rdma_write_recv_bytes` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName` `ClusterName`, `InstanceId`, `InstanceType`, `NodeName`, `NetworkInterfaceId`  |  配置給節點的 EFA 裝置在遠端直接記憶體存取寫入操作期間每秒接收的位元組數。 單位：位元組/秒  | 

## Amazon SageMaker AI HyperPod 指標
<a name="Container-Insights-metrics-Sagemaker-HyperPod"></a>

從 CloudWatch Observability EKS 附加元件的 `v2.0.1-eksbuild.1` 版本開始，適用於 Amazon EKS 的具有增強可觀測性的 Container Insights 會自動從 Amazon EKS 叢集中收集 Amazon SageMaker AI HyperPod 指標。如需有關附加元件的詳細資訊，請參閱[使用 Amazon CloudWatch Observability EKS 附加元件或 Helm Chart 安裝 CloudWatch 代理程式](install-CloudWatch-Observability-EKS-addon.md)。如需有關 Amazon SageMaker AI HyperPod 的詳細資訊，請參閱 [Amazon SageMaker AI HyperPod](https://docs.aws.amazon.com/sagemaker/latest/dg/sagemaker-hyperpod-eks.html)。

收集的指標列於下列資料表中。


| 指標名稱 | 維度 | Description | 
| --- | --- | --- | 
|  `hyperpod_node_health_status_unschedulable` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`  |  指示 Amazon SageMaker AI HyperPod 是否將節點標記為 `Unschedulable`。這表示節點正在執行深度運作狀態檢查，不適用於執行中的工作負載。 單位：計數  | 
|  `hyperpod_node_health_status_schedulable` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`  |  指示 Amazon SageMaker AI HyperPod 是否將節點標記為 `Schedulable`。這表示節點已通過基本運作狀態檢查或深度運作狀態檢查，可用於執行中的工作負載。 單位：計數  | 
|  `hyperpod_node_health_status_unschedulable_pending_replacement` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`  |  指示 HyperPod 是否將節點標記為 `UnschedulablePendingReplacement`。這表示節點未通過深度運作狀態檢查或運作狀態監控代理程式檢查，且需要取代。 如果啟用自動節點復原，節點將自動取代為 Amazon SageMaker AI HyperPod。 單位：計數  | 
|  `hyperpod_node_health_status_unschedulable_pending_reboot` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`  |  指示 Amazon SageMaker AI HyperPod 是否將節點標記為 `UnschedulablePendingReboot`。這表示節點正在執行深度運作狀態檢查，且需要重新啟動。 如果啟用自動節點復原， Amazon SageMaker AI HyperPod 會自動重新啟動節點。 單位：計數  | 

## Amazon EBS NVMe 驅動程式指標
<a name="Container-Insights-metrics-EBS"></a>

從 CloudWatch 代理程式的 ` 1.300056.0` 版本開始，適用於 Amazon EKS 的具有增強可觀測性的 Container Insights 會自動從 Linux 執行個體上的 Amazon EKS 叢集中收集 Amazon EBS NVMe 驅動程式指標。必須使用 CloudWatch Observability Amazon EKS 附加元件版本 `4.1.0` 或更新版本來安裝 CloudWatch 代理程式。如需有關附加元件的詳細資訊，請參閱[使用 Amazon CloudWatch Observability EKS 附加元件或 Helm Chart 安裝 CloudWatch 代理程式](install-CloudWatch-Observability-EKS-addon.md)。如需 Amazon EBS 的詳細資訊，請參閱 [Amazon EBS 詳細效能統計資料](https://docs.aws.amazon.com/ebs/latest/userguide/nvme-detailed-performance-stats.html)。

若要讓 Container Insights 收集 Amazon EBS NVMe 驅動程式指標，必須滿足下列先決條件：
+ 必須搭配使用適用於 Amazon EKS 的具有增強可觀測性的 Container Insights 與 CloudWatch Observability Amazon EKS 附加元件版本 `4.1.0` 或更新版本。
+ EBS CSI 驅動程式 `1.42.0` 附加元件或 Helm Chart 必須安裝在已啟用指標的叢集上。
  + 若要在使用 Amazon EBS CSI 驅動程式附加元件時啟用指標，請在建立或更新附加元件時使用下列選項。`--configuration-values '{ "node": { "enableMetrics": true } }'`
  + 若要在使用 Helm Chart 時啟用指標，請在建立或更新附加元件時使用下列選項。`--set node.enableMetrics=true`

收集的指標列於下列資料表中。


| 指標名稱 | 維度 | Description | 
| --- | --- | --- | 
|  `node_diskio_ebs_total_read_ops` |  `ClusterName` `ClusterName`, `NodeName`, `InstanceId` `ClusterName`, `NodeName`, `InstanceId` `VolumeId`  | 已完成讀取操作的總數。 | 
|  `node_diskio_ebs_total_write_ops` |  `ClusterName` `ClusterName`, `NodeName`, `InstanceId` `ClusterName`, `NodeName`, `InstanceId` `VolumeId`  | 已完成寫入操作的總數。 | 
|  `node_diskio_ebs_total_read_bytes` |  `ClusterName` `ClusterName`, `NodeName`, `InstanceId` `ClusterName`, `NodeName`, `InstanceId` `VolumeId`  | 傳輸的讀取位元組總數。 | 
|  `node_diskio_ebs_total_write_bytes` |  `ClusterName` `ClusterName`, `NodeName`, `InstanceId` `ClusterName`, `NodeName`, `InstanceId` `VolumeId`  | 傳輸的寫入位元組總數。 | 
|  `node_diskio_ebs_total_read_time` |  `ClusterName` `ClusterName`, `NodeName`, `InstanceId` `ClusterName`, `NodeName`, `InstanceId` `VolumeId`  | 執行所有已完成讀取操作花費的總時間，以微秒為單位。 | 
|  `node_diskio_ebs_total_write_time` |  `ClusterName` `ClusterName`, `NodeName`, `InstanceId` `ClusterName`, `NodeName`, `InstanceId` `VolumeId`  | 執行所有已完成寫入操作花費的總時間，以微秒為單位。 | 
|  `node_diskio_ebs_volume_performance_exceeded_iops` |  `ClusterName` `ClusterName`, `NodeName`, `InstanceId` `ClusterName`, `NodeName`, `InstanceId` `VolumeId`  | IOPS 需求超過磁碟區佈建 IOPS 效能的總時間，以微秒為單位。 | 
|  `node_diskio_ebs_volume_performance_exceeded_tp` |  `ClusterName` `ClusterName`, `NodeName`, `InstanceId` `ClusterName`, `NodeName`, `InstanceId` `VolumeId`  | 輸送量需求超過磁碟區佈建輸送量效能的總時間，以微秒為單位。 | 
|  `node_diskio_ebs_ec2_instance_performance_exceeded_iops` |  `ClusterName` `ClusterName`, `NodeName`, `InstanceId` `ClusterName`, `NodeName`, `InstanceId` `VolumeId`  | EBS 磁碟區超過連結之 Amazon EC2 執行個體 IOPS 效能上限的總時間，以微秒為單位。 | 
|  `node_diskio_ebs_ec2_instance_performance_exceeded_tp` |  `ClusterName` `ClusterName`, `NodeName`, `InstanceId` `ClusterName`, `NodeName`, `InstanceId` `VolumeId`  | EBS 磁碟區超過連結的 Amazon EC2 執行個體輸送量效能上限的總時間，以微秒為單位。 | 
|  `node_diskio_ebs_volume_queue_length` |  `ClusterName` `ClusterName`, `NodeName`, `InstanceId` `ClusterName`, `NodeName`, `InstanceId` `VolumeId`  | 等待完成的讀取和寫入操作數目。 | 

# Amazon EKS 和 Kubernetes Container Insights 指標
<a name="Container-Insights-metrics-EKS"></a>

下列資料表列出 Container Insights 為 Amazon EKS 和 Kubernetes 收集的指標和維度。這些指標會在 `ContainerInsights` 命名空間中。如需詳細資訊，請參閱[指標](cloudwatch_concepts.md#Metric)。

如果您沒有在主控台中看到任何容器洞見指標，請確定您已完成容器洞見的設定。在完整設定容器洞見前指標都不會出現。如需詳細資訊，請參閱[設定 Container Insights](deploy-container-insights.md)。


| 指標名稱 | 維度 | Description | 
| --- | --- | --- | 
|  `cluster_failed_node_count`  |  `ClusterName`  |  叢集中失敗的工作者節點數量。如果節點受困於任何*節點條件*，則會將其判定為失敗。如需詳細資訊，請參閱 Kubernetes 文件中的[條件](https://kubernetes.io/docs/concepts/architecture/nodes/#condition)。  | 
|  `cluster_node_count`  |  `ClusterName`  |  叢集中的工作者節點總數。  | 
|  `namespace_number_of_running_pods`  |  `Namespace` `ClusterName` `ClusterName`  |  資源中每個命名空間執行的 pod 數量，該資源由您正在使用的維度所指定。  | 
|  `node_cpu_limit`  |  `ClusterName`   |  可指派至此叢集中單一節點的 CPU 單位數量上限。  | 
|  `node_cpu_reserved_capacity`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  為節點元件 (例如 kubelet、kube-proxy 和 Docker) 預留的 CPU 單位百分比。 公式：`node_cpu_request / node_cpu_limit`  `node_cpu_request` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `node_cpu_usage_total`  |  `ClusterName`  |  叢集中節點上正在使用的 CPU 單位數量。  | 
|  `node_cpu_utilization`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  叢集中節點上正在使用的 CPU 單位百分比總數。 公式：`node_cpu_usage_total / node_cpu_limit`  | 
|  `node_gpu_limit` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`  |  節點上可用的 GPU 總數。  | 
|  `node_gpu_usage_total` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`  |  節點上執行中 Pod 正在使用的 GPU 數量。  | 
|  `node_gpu_reserved_capacity` |  `ClusterName` `ClusterName`, `InstanceId`, `NodeName`  |  節點上目前預留的 GPU 百分比。公式為 `node_gpu_request / node_gpu_limit`。  `node_gpu_request` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `node_filesystem_utilization`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  叢集中節點上正在使用的檔案系統容量百分比總數。 公式：`node_filesystem_usage / node_filesystem_capacity`  `node_filesystem_usage` 和 `node_filesystem_capacity` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `node_memory_limit`  |  `ClusterName`  |  可指派至此叢集中單一節點的記憶體數量上限 (以位元組為單位)。  | 
|  `node_memory_reserved_capacity`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  目前在叢集中節點上使用的記憶體百分比。 公式：`node_memory_request / node_memory_limit`  `node_memory_request` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `node_memory_utilization`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  節點目前使用的記憶體百分比。這是節點記憶體使用量除以節點記憶體限制的百分比。 公式：`node_memory_working_set / node_memory_limit`。  | 
|  `node_memory_working_set`  |  `ClusterName`   |  叢集中運作中一組節點中正在使用的記憶體數量 (以位元組為單位)。  | 
|  `node_network_total_bytes`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  叢集中每個節點每秒透過網路傳輸和接收的位元組總數。 公式：`node_network_rx_bytes + node_network_tx_bytes`  `node_network_rx_bytes` 和 `node_network_tx_bytes` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `node_number_of_running_containers`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  叢集中每個節點執行中的容器數。  | 
|  `node_number_of_running_pods`  |  `NodeName`, `ClusterName`, `InstanceId` `ClusterName`  |  叢集中每個節點執行中的 pod 數。  | 
|  `pod_cpu_reserved_capacity`  |  `PodName`, `Namespace`, `ClusterName` `ClusterName`  |  叢集中每個 pod 預留的 CPU 容量。 公式：`pod_cpu_request / node_cpu_limit`  `pod_cpu_request` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `pod_cpu_utilization`  |  `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName` `Service`, `Namespace`, `ClusterName` `ClusterName`  |  Pod 使用的 CPU 單位百分比。 公式：`pod_cpu_usage_total / node_cpu_limit`  | 
|  `pod_cpu_utilization_over_pod_limit`  |  `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName` `Service`, `Namespace`, `ClusterName` `ClusterName`  |  Pod 正在使用的 CPU 單位百分比，此百分比與 Pod 限制相對。 公式：`pod_cpu_usage_total / pod_cpu_limit`  | 
|  `pod_gpu_request` |  `ClusterName` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `FullPodName`, `Namespace`, `PodName`  |  Pod 的 GPU 請求。此值必須始終等於 `pod_gpu_limit`。  | 
|  `pod_gpu_limit` |  `ClusterName` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `FullPodName`, `Namespace`, `PodName`  |  可指派給節點中 Pod 的 GPU 數量上限。  | 
|  `pod_gpu_usage_total` |  `ClusterName` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `FullPodName`, `Namespace`, `PodName`  |  在 Pod 上配置的 GPU 數量。  | 
|  `pod_gpu_reserved_capacity` |  `ClusterName` `ClusterName`, `Namespace`, `PodName` `ClusterName`, `FullPodName`, `Namespace`, `PodName`  |  目前為 Pod 預留的 GPU 百分比。公式為 - pod\$1gpu\$1request / node\$1gpu\$1reserved\$1capacity。  | 
|  `pod_memory_reserved_capacity`  |  `PodName`, `Namespace`, `ClusterName` `ClusterName`  |  為 Pod 保留的記憶體百分比。 公式：`pod_memory_request / node_memory_limit`  `pod_memory_request` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `pod_memory_utilization`  |  `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName` `Service`, `Namespace`, `ClusterName` `ClusterName`  |  Pod 目前使用的記憶體百分比。 公式：`pod_memory_working_set / node_memory_limit`  | 
|  `pod_memory_utilization_over_pod_limit`  |  `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName` `Service`, `Namespace`, `ClusterName` `ClusterName`  |  Pod 正在使用的記憶體百分比，此百分比與 Pod 限制相對。如果 Pod 中有任何容器未定義記憶體限制，這個指標將不會顯示。 公式：`pod_memory_working_set / pod_memory_limit`  | 
|  `pod_network_rx_bytes`  |  `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName` `Service`, `Namespace`, `ClusterName` `ClusterName`  |  Pod 透過網路每秒接收的位元組數。 公式：`sum(pod_interface_network_rx_bytes)`  `pod_interface_network_rx_bytes` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `pod_network_tx_bytes`  |  `PodName`, `Namespace`, `ClusterName` `Namespace`, `ClusterName` `Service`, `Namespace`, `ClusterName` `ClusterName`  |  Pod 透過網路每秒傳輸的位元組數。 公式：`sum(pod_interface_network_tx_bytes)`  `pod_interface_network_tx_bytes` 不會直接回報為指標，而是效能日誌事件中的欄位。如需詳細資訊，請參閱[Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)。   | 
|  `pod_number_of_container_restarts`  |  `PodName`, `Namespace`, `ClusterName`  |  Pod 中重新啟動的容器總數。  | 
|  `service_number_of_running_pods`  |  `Service`, `Namespace`, `ClusterName` `ClusterName`  |  叢集中執行服務的 Pod 數量。  | 

## Kueue 指標
<a name="Container-Insights-metrics-Kueue"></a>

從 CloudWatch Observability EKS 附加元件的版本 `v2.4.0-eksbuild.1` 開始，適用於 Amazon EKS 的 Container Insights 支援從 Amazon EKS 叢集收集 Kueue 指標。如需有關附加元件的詳細資訊，請參閱[使用 Amazon CloudWatch Observability EKS 附加元件或 Helm Chart 安裝 CloudWatch 代理程式](install-CloudWatch-Observability-EKS-addon.md)。

如需有關啟用指標的資訊，請參閱[啟用 Kueue 指標](install-CloudWatch-Observability-EKS-addon.md#enable-Kueue-metrics)以啟用指標。

收集的 Kueue 指標列於下列資料表中。這些指標會發布到 CloudWatch 的 `ContainerInsights/Prometheus` 命名空間中：其中一些指標會使用下列維度：
+ `ClusterQueue` 為 ClusterQueue 的名稱
+ `Status` 的可能值為 `active` 和 `inadmissible`
+ `Reason` 的可能值為 `Preempted`、`PodsReadyTimeout`、`AdmissionCheck`、`ClusterQueueStopped` 和 `InactiveWorkload`
+ `Flavor` 為參考版本。
+ `Resource` 是指叢集計算機資源，例如 `cpu`、`memory`、`gpu` 等。


| 指標名稱 | 維度 | Description | 
| --- | --- | --- | 
|  `kueue_pending_workloads` |  `ClusterName`, `ClusterQueue`, `Status` `ClusterName`, `ClusterQueue` `ClusterName`, `Status` `ClusterName`  |  待處理工作負載的數量。  | 
|  `kueue_evicted_workloads_total` |  `ClusterName`, `ClusterQueue`, `Reason` `ClusterName`, `ClusterQueue` `ClusterName`, `Reason` `ClusterName`  |  已移出的工作負載總數。  | 
|  `kueue_admitted_active_workloads` |  `ClusterName`, `ClusterQueue` `ClusterName`  |  作用中的已確認工作負載數量 (未暫停和未完成)。  | 
|  `kueue_cluster_queue_resource_usage` |  `ClusterName`, `ClusterQueue`, `Resource`, `Flavor` `ClusterName`, `ClusterQueue`, `Resource` `ClusterName`, `ClusterQueue`, `Flavor` `ClusterName`, `ClusterQueue` `ClusterName`  |  報告 ClusterQueue 的總資源用量。  | 
|  `kueue_cluster_queue_nominal_quota` |  `ClusterName`, `ClusterQueue`, `Resource`, `Flavor` `ClusterName`, `ClusterQueue`, `Resource` `ClusterName`, `ClusterQueue`, `Flavor` `ClusterName`, `ClusterQueue` `ClusterName`  |  報告 ClusterQueue 的資源配額。  | 

# Container Insights 效能日誌參考
<a name="Container-Insights-reference"></a>

本節包含 Container Insights 如何使用效能日誌事件收集指標的參考資訊。當您部署 Container Insights 時，它會自動建立效能日誌事件的日誌群組。您不需要自行建立此日誌群組。

**Topics**
+ [Amazon ECS 的 Container Insights 效能日誌事件](Container-Insights-reference-performance-logs-ECS.md)
+ [Amazon EKS 和 Kubernetes 的 Container Insights 效能日誌事件](Container-Insights-reference-performance-logs-EKS.md)
+ [Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位](Container-Insights-reference-performance-entries-EKS.md)

# Amazon ECS 的 Container Insights 效能日誌事件
<a name="Container-Insights-reference-performance-logs-ECS"></a>

以下是 Container Insights 從 Amazon ECS 中收集的效能日誌事件範例。

這些日誌位於 CloudWatch Logs 的日誌群組 `/aws/ecs/containerinsights/CLUSTER_NAME/performance`。在該日誌群組中，每個容器執行個體都會有日誌串流 `AgentTelemetry-CONTAINER_INSTANCE_ID`。

您可以使用 `{ $.Type = "Container" }` 等查詢來查詢這些日誌，以檢視所有容器日誌事件。

**類型：容器**

```
{
	"Version":"0",
	"Type":"Container",
	"ContainerName":"sleep",
	"TaskId":"7ac4dfba69214411b4783a3b8189c9ba",
	"TaskDefinitionFamily":"sleep360",
	"TaskDefinitionRevision":"1",
	"ContainerInstanceId":"0d7650e6dec34c1a9200f72098071e8f",
	"EC2InstanceId":"i-0c470579dbcdbd2f3",
	"ClusterName":"MyCluster",
	"Image":"busybox",
	"ContainerKnownStatus":"RUNNING",
	"Timestamp":1623963900000,
	"CpuUtilized":0.0,
	"CpuReserved":10.0,
	"MemoryUtilized":0,
	"MemoryReserved":10,
	"StorageReadBytes":0,
	"StorageWriteBytes":0,
	"NetworkRxBytes":0,
	"NetworkRxDropped":0,
	"NetworkRxErrors":0,
	"NetworkRxPackets":14,
	"NetworkTxBytes":0,
	"NetworkTxDropped":0,
	"NetworkTxErrors":0,
	"NetworkTxPackets":0
}
```

**類型：任務**

儘管 `StorageReadBytes` 和 `StorageWriteBytes` 的單位為位元組/秒，但這些值分別表示從儲存體讀取和寫入的累積位元組數。

```
{
    "Version": "0",
    "Type": "Task",
    "TaskId": "7ac4dfba69214411b4783a3b8189c9ba",
    "TaskDefinitionFamily": "sleep360",
    "TaskDefinitionRevision": "1",
    "ContainerInstanceId": "0d7650e6dec34c1a9200f72098071e8f",
    "EC2InstanceId": "i-0c470579dbcdbd2f3",
    "ClusterName": "MyCluster",
    "AccountID": "637146863587",
    "Region": "us-west-2",
    "AvailabilityZone": "us-west-2b",
    "KnownStatus": "RUNNING",
    "LaunchType": "EC2",
    "PullStartedAt": 1623963608201,
    "PullStoppedAt": 1623963610065,
    "CreatedAt": 1623963607094,
    "StartedAt": 1623963610382,
    "Timestamp": 1623963900000,
    "CpuUtilized": 0.0,
    "CpuReserved": 10.0,
    "MemoryUtilized": 0,
    "MemoryReserved": 10,
    "StorageReadBytes": 0,
    "StorageWriteBytes": 0,
    "NetworkRxBytes": 0,
    "NetworkRxDropped": 0,
    "NetworkRxErrors": 0,
    "NetworkRxPackets": 14,
    "NetworkTxBytes": 0,
    "NetworkTxDropped": 0,
    "NetworkTxErrors": 0,
    "NetworkTxPackets": 0,
    "EBSFilesystemUtilized": 10,
    "EBSFilesystemSize": 20,
    "CloudWatchMetrics": [
        {
            "Namespace": "ECS/ContainerInsights",
            "Metrics": [
                {
                    "Name": "CpuUtilized",
                    "Unit": "None"
                },
                {
                    "Name": "CpuReserved",
                    "Unit": "None"
                },
                {
                    "Name": "MemoryUtilized",
                    "Unit": "Megabytes"
                },
                {
                    "Name": "MemoryReserved",
                    "Unit": "Megabytes"
                },
                {
                    "Name": "StorageReadBytes",
                    "Unit": "Bytes/Second"
                },
                {
                    "Name": "StorageWriteBytes",
                    "Unit": "Bytes/Second"
                },
                {
                    "Name": "NetworkRxBytes",
                    "Unit": "Bytes/Second"
                },
                {
                    "Name": "NetworkTxBytes",
                    "Unit": "Bytes/Second"
                },
                {
                    "Name": "EBSFilesystemSize",
                    "Unit": "Gigabytes"
                },
                {
                    "Name": "EBSFilesystemUtilzed",
                    "Unit": "Gigabytes"
                }
            ],
            "Dimensions": [
                ["ClusterName"],
                [
                    "ClusterName",
                    "TaskDefinitionFamily"
                ]
            ]
        }
    ]
}
```

**類型：服務**

```
{   
    "Version": "0",
    "Type": "Service",
    "ServiceName": "myCIService",
    "ClusterName": "myCICluster",
    "Timestamp": 1561586460000,
    "DesiredTaskCount": 2,
    "RunningTaskCount": 2,
    "PendingTaskCount": 0,
    "DeploymentCount": 1,
    "TaskSetCount": 0,
    "CloudWatchMetrics": [
        {
            "Namespace": "ECS/ContainerInsights",
            "Metrics": [
                {
                    "Name": "DesiredTaskCount",
                    "Unit": "Count"
                },
                {
                    "Name": "RunningTaskCount",
                    "Unit": "Count"
                },
                {
                    "Name": "PendingTaskCount",
                    "Unit": "Count"
                },
                {
                    "Name": "DeploymentCount",
                    "Unit": "Count"
                },
                {
                    "Name": "TaskSetCount",
                    "Unit": "Count"
                }
            ],
            "Dimensions": [
                [
                    "ServiceName",
                    "ClusterName"
                ]
            ]
        }
    ]
}
```

**類型：磁碟區**

```
{
    "Version": "0",
    "Type": "Volume",
    "TaskDefinitionFamily": "myCITaskDef",
    "TaskId": "7ac4dfba69214411b4783a3b8189c9ba",
    "ClusterName": "myCICluster",
    "ServiceName": "myCIService",
    "VolumeId": "vol-1233436545ff708cb",
    "InstanceId": "i-0c470579dbcdbd2f3",
    "LaunchType": "EC2",
    "VolumeName": "MyVolumeName",
    "EBSFilesystemUtilized": 10,
    "EBSFilesystemSize": 20,
    "CloudWatchMetrics": [
        {
            "Namespace": "ECS/ContainerInsights",
            "Metrics": [
                {
                    "Name": "EBSFilesystemSize",
                    "Unit": "Gigabytes"
                },
                {
                    "Name": "EBSFilesystemUtilzed",
                    "Unit": "Gigabytes"
                }
            ],
            "Dimensions": [
                ["ClusterName"],
                [
                    "VolumeName",
                    "TaskDefinitionFamily",
                    "ClusterName"
                ],
                [
                    "ServiceName",
                    "ClusterName"
                ]
            ]
        }
    ]
}
```

**類型：叢集**

```
{
    "Version": "0",
    "Type": "Cluster",
    "ClusterName": "myCICluster",
    "Timestamp": 1561587300000,
    "TaskCount": 5,
    "ContainerInstanceCount": 5,
    "ServiceCount": 2,
    "CloudWatchMetrics": [
        {
            "Namespace": "ECS/ContainerInsights",
            "Metrics": [
                {
                    "Name": "TaskCount",
                    "Unit": "Count"
                },
                {
                    "Name": "ContainerInstanceCount",
                    "Unit": "Count"
                },
                {
                    "Name": "ServiceCount",
                    "Unit": "Count"
                }
            ],
            "Dimensions": [
                [
                    "ClusterName"
                ]
            ]
        }
    ]
}
```

# Amazon EKS 和 Kubernetes 的 Container Insights 效能日誌事件
<a name="Container-Insights-reference-performance-logs-EKS"></a>

以下是 Container Insights 從 Amazon EKS 和 Kubernetes 叢集所收集效能日誌事件的範例。

**類型：節點**

```
{
  "AutoScalingGroupName": "eksctl-myCICluster-nodegroup-standard-workers-NodeGroup-1174PV2WHZAYU",
  "CloudWatchMetrics": [
    {
      "Metrics": [
        {
          "Unit": "Percent",
          "Name": "node_cpu_utilization"
        },
        {
          "Unit": "Percent",
          "Name": "node_memory_utilization"
        },
        {
          "Unit": "Bytes/Second",
          "Name": "node_network_total_bytes"
        },
        {
          "Unit": "Percent",
          "Name": "node_cpu_reserved_capacity"
        },
        {
          "Unit": "Percent",
          "Name": "node_memory_reserved_capacity"
        },
        {
          "Unit": "Count",
          "Name": "node_number_of_running_pods"
        },
        {
          "Unit": "Count",
          "Name": "node_number_of_running_containers"
        }
      ],
      "Dimensions": [
        [
          "NodeName",
          "InstanceId",
          "ClusterName"
        ]
      ],
      "Namespace": "ContainerInsights"
    },
    {
      "Metrics": [
        {
          "Unit": "Percent",
          "Name": "node_cpu_utilization"
        },
        {
          "Unit": "Percent",
          "Name": "node_memory_utilization"
        },
        {
          "Unit": "Bytes/Second",
          "Name": "node_network_total_bytes"
        },
        {
          "Unit": "Percent",
          "Name": "node_cpu_reserved_capacity"
        },
        {
          "Unit": "Percent",
          "Name": "node_memory_reserved_capacity"
        },
        {
          "Unit": "Count",
          "Name": "node_number_of_running_pods"
        },
        {
          "Unit": "Count",
          "Name": "node_number_of_running_containers"
        },
        {
          "Name": "node_cpu_usage_total"
        },
        {
          "Name": "node_cpu_limit"
        },
        {
          "Unit": "Bytes",
          "Name": "node_memory_working_set"
        },
        {
          "Unit": "Bytes",
          "Name": "node_memory_limit"
        }
      ],
      "Dimensions": [
        [
          "ClusterName"
        ]
      ],
      "Namespace": "ContainerInsights"
    }
  ],
  "ClusterName": "myCICluster",
  "InstanceId": "i-1234567890123456",
  "InstanceType": "t3.xlarge",
  "NodeName": "ip-192-0-2-0.us-west-2.compute.internal",
  "Sources": [
    "cadvisor",
    "/proc",
    "pod",
    "calculated"
  ],
  "Timestamp": "1567096682364",
  "Type": "Node",
  "Version": "0",
  "kubernetes": {
    "host": "ip-192-168-75-26.us-west-2.compute.internal"
  },
  "node_cpu_limit": 4000,
  "node_cpu_request": 1130,
  "node_cpu_reserved_capacity": 28.249999999999996,
  "node_cpu_usage_system": 33.794636630852764,
  "node_cpu_usage_total": 136.47852169244098,
  "node_cpu_usage_user": 71.67075111567326,
  "node_cpu_utilization": 3.4119630423110245,
  "node_memory_cache": 3103297536,
  "node_memory_failcnt": 0,
  "node_memory_hierarchical_pgfault": 0,
  "node_memory_hierarchical_pgmajfault": 0,
  "node_memory_limit": 16624865280,
  "node_memory_mapped_file": 406646784,
  "node_memory_max_usage": 4230746112,
  "node_memory_pgfault": 0,
  "node_memory_pgmajfault": 0,
  "node_memory_request": 1115684864,
  "node_memory_reserved_capacity": 6.7109407818311055,
  "node_memory_rss": 798146560,
  "node_memory_swap": 0,
  "node_memory_usage": 3901444096,
  "node_memory_utilization": 6.601302600149552,
  "node_memory_working_set": 1097457664,
  "node_network_rx_bytes": 35918.392817386324,
  "node_network_rx_dropped": 0,
  "node_network_rx_errors": 0,
  "node_network_rx_packets": 157.67565245448117,
  "node_network_total_bytes": 68264.20276554905,
  "node_network_tx_bytes": 32345.80994816272,
  "node_network_tx_dropped": 0,
  "node_network_tx_errors": 0,
  "node_network_tx_packets": 154.21455923431654,
  "node_number_of_running_containers": 16,
  "node_number_of_running_pods": 13
}
```

**類型：NodeFS**

```
{
  "AutoScalingGroupName": "eksctl-myCICluster-nodegroup-standard-workers-NodeGroup-1174PV2WHZAYU",
  "CloudWatchMetrics": [
    {
      "Metrics": [
        {
          "Unit": "Percent",
          "Name": "node_filesystem_utilization"
        }
      ],
      "Dimensions": [
        [
          "NodeName",
          "InstanceId",
          "ClusterName"
        ],
        [
          "ClusterName"
        ]
      ],
      "Namespace": "ContainerInsights"
    }
  ],
  "ClusterName": "myCICluster",
  "EBSVolumeId": "aws://us-west-2b/vol-0a53108976d4a2fda",
  "InstanceId": "i-1234567890123456",
  "InstanceType": "t3.xlarge",
  "NodeName": "ip-192-0-2-0.us-west-2.compute.internal",
  "Sources": [
    "cadvisor",
    "calculated"
  ],
  "Timestamp": "1567097939726",
  "Type": "NodeFS",
  "Version": "0",
  "device": "/dev/nvme0n1p1",
  "fstype": "vfs",
  "kubernetes": {
    "host": "ip-192-168-75-26.us-west-2.compute.internal"
  },
  "node_filesystem_available": 17298395136,
  "node_filesystem_capacity": 21462233088,
  "node_filesystem_inodes": 10484720,
  "node_filesystem_inodes_free": 10367158,
  "node_filesystem_usage": 4163837952,
  "node_filesystem_utilization": 19.400767547940255
}
```

**類型：NodeDiskIO**

```
{
  "AutoScalingGroupName": "eksctl-myCICluster-nodegroup-standard-workers-NodeGroup-1174PV2WHZAYU",
  "ClusterName": "myCICluster",
  "EBSVolumeId": "aws://us-west-2b/vol-0a53108976d4a2fda",
  "InstanceId": "i-1234567890123456",
  "InstanceType": "t3.xlarge",
  "NodeName": "ip-192-0-2-0.us-west-2.compute.internal",
  "Sources": [
    "cadvisor"
  ],
  "Timestamp": "1567096928131",
  "Type": "NodeDiskIO",
  "Version": "0",
  "device": "/dev/nvme0n1",
  "kubernetes": {
    "host": "ip-192-168-75-26.us-west-2.compute.internal"
  },
  "node_diskio_io_service_bytes_async": 9750.505814277016,
  "node_diskio_io_service_bytes_read": 0,
  "node_diskio_io_service_bytes_sync": 230.6174506688036,
  "node_diskio_io_service_bytes_total": 9981.123264945818,
  "node_diskio_io_service_bytes_write": 9981.123264945818,
  "node_diskio_io_serviced_async": 1.153087253344018,
  "node_diskio_io_serviced_read": 0,
  "node_diskio_io_serviced_sync": 0.03603397666700056,
  "node_diskio_io_serviced_total": 1.1891212300110185,
  "node_diskio_io_serviced_write": 1.1891212300110185
}
```

**類型：NodeNet**

```
{
  "AutoScalingGroupName": "eksctl-myCICluster-nodegroup-standard-workers-NodeGroup-1174PV2WHZAYU",
  "ClusterName": "myCICluster",
  "InstanceId": "i-1234567890123456",
  "InstanceType": "t3.xlarge",
  "NodeName": "ip-192-0-2-0.us-west-2.compute.internal",
  "Sources": [
    "cadvisor",
    "calculated"
  ],
  "Timestamp": "1567096928131",
  "Type": "NodeNet",
  "Version": "0",
  "interface": "eni972f6bfa9a0",
  "kubernetes": {
    "host": "ip-192-168-75-26.us-west-2.compute.internal"
  },
  "node_interface_network_rx_bytes": 3163.008420864309,
  "node_interface_network_rx_dropped": 0,
  "node_interface_network_rx_errors": 0,
  "node_interface_network_rx_packets": 16.575629266820258,
  "node_interface_network_total_bytes": 3518.3935157426017,
  "node_interface_network_tx_bytes": 355.385094878293,
  "node_interface_network_tx_dropped": 0,
  "node_interface_network_tx_errors": 0,
  "node_interface_network_tx_packets": 3.9997714100370625
}
```

**類型：Pod**

```
{
  "AutoScalingGroupName": "eksctl-myCICluster-nodegroup-standard-workers-NodeGroup-1174PV2WHZAYU",
  "CloudWatchMetrics": [
    {
      "Metrics": [
        {
          "Unit": "Percent",
          "Name": "pod_cpu_utilization"
        },
        {
          "Unit": "Percent",
          "Name": "pod_memory_utilization"
        },
        {
          "Unit": "Bytes/Second",
          "Name": "pod_network_rx_bytes"
        },
        {
          "Unit": "Bytes/Second",
          "Name": "pod_network_tx_bytes"
        },
        {
          "Unit": "Percent",
          "Name": "pod_cpu_utilization_over_pod_limit"
        },
        {
          "Unit": "Percent",
          "Name": "pod_memory_utilization_over_pod_limit"
        }
      ],
      "Dimensions": [
        [
          "PodName",
          "Namespace",
          "ClusterName"
        ],
        [
          "Service",
          "Namespace",
          "ClusterName"
        ],
        [
          "Namespace",
          "ClusterName"
        ],
        [
          "ClusterName"
        ]
      ],
      "Namespace": "ContainerInsights"
    },
    {
      "Metrics": [
        {
          "Unit": "Percent",
          "Name": "pod_cpu_reserved_capacity"
        },
        {
          "Unit": "Percent",
          "Name": "pod_memory_reserved_capacity"
        }
      ],
      "Dimensions": [
        [
          "PodName",
          "Namespace",
          "ClusterName"
        ],
        [
          "ClusterName"
        ]
      ],
      "Namespace": "ContainerInsights"
    },
    {
      "Metrics": [
        {
          "Unit": "Count",
          "Name": "pod_number_of_container_restarts"
        }
      ],
      "Dimensions": [
        [
          "PodName",
          "Namespace",
          "ClusterName"
        ]
      ],
      "Namespace": "ContainerInsights"
    }
  ],
  "ClusterName": "myCICluster",
  "InstanceId": "i-1234567890123456",
  "InstanceType": "t3.xlarge",
  "Namespace": "amazon-cloudwatch",
  "NodeName": "ip-192-0-2-0.us-west-2.compute.internal",
  "PodName": "cloudwatch-agent-statsd",
  "Service": "cloudwatch-agent-statsd",
  "Sources": [
    "cadvisor",
    "pod",
    "calculated"
  ],
  "Timestamp": "1567097351092",
  "Type": "Pod",
  "Version": "0",
  "kubernetes": {
    "host": "ip-192-168-75-26.us-west-2.compute.internal",
    "labels": {
      "app": "cloudwatch-agent-statsd",
      "pod-template-hash": "df44f855f"
    },
    "namespace_name": "amazon-cloudwatch",
    "pod_id": "2f4ff5ac-c813-11e9-a31d-06e9dde32928",
    "pod_name": "cloudwatch-agent-statsd-df44f855f-ts4q2",
    "pod_owners": [
      {
        "owner_kind": "Deployment",
        "owner_name": "cloudwatch-agent-statsd"
      }
    ],
    "service_name": "cloudwatch-agent-statsd"
  },
  "pod_cpu_limit": 200,
  "pod_cpu_request": 200,
  "pod_cpu_reserved_capacity": 5,
  "pod_cpu_usage_system": 1.4504841104992765,
  "pod_cpu_usage_total": 5.817016867430125,
  "pod_cpu_usage_user": 1.1281543081661038,
  "pod_cpu_utilization": 0.14542542168575312,
  "pod_cpu_utilization_over_pod_limit": 2.9085084337150624,
  "pod_memory_cache": 8192,
  "pod_memory_failcnt": 0,
  "pod_memory_hierarchical_pgfault": 0,
  "pod_memory_hierarchical_pgmajfault": 0,
  "pod_memory_limit": 104857600,
  "pod_memory_mapped_file": 0,
  "pod_memory_max_usage": 25268224,
  "pod_memory_pgfault": 0,
  "pod_memory_pgmajfault": 0,
  "pod_memory_request": 104857600,
  "pod_memory_reserved_capacity": 0.6307275170893897,
  "pod_memory_rss": 22777856,
  "pod_memory_swap": 0,
  "pod_memory_usage": 25141248,
  "pod_memory_utilization": 0.10988455961791709,
  "pod_memory_utilization_over_pod_limit": 17.421875,
  "pod_memory_working_set": 18268160,
  "pod_network_rx_bytes": 9880.697124714186,
  "pod_network_rx_dropped": 0,
  "pod_network_rx_errors": 0,
  "pod_network_rx_packets": 107.80005532263283,
  "pod_network_total_bytes": 10158.829201483635,
  "pod_network_tx_bytes": 278.13207676944796,
  "pod_network_tx_dropped": 0,
  "pod_network_tx_errors": 0,
  "pod_network_tx_packets": 1.146027574644318,
  "pod_number_of_container_restarts": 0,
  "pod_number_of_containers": 1,
  "pod_number_of_running_containers": 1,
  "pod_status": "Running"
}
```

**類型：PodNet**

```
{
  "AutoScalingGroupName": "eksctl-myCICluster-nodegroup-standard-workers-NodeGroup-1174PV2WHZAYU",
  "ClusterName": "myCICluster",
  "InstanceId": "i-1234567890123456",
  "InstanceType": "t3.xlarge",
  "Namespace": "amazon-cloudwatch",
  "NodeName": "ip-192-0-2-0.us-west-2.compute.internal",
  "PodName": "cloudwatch-agent-statsd",
  "Service": "cloudwatch-agent-statsd",
  "Sources": [
    "cadvisor",
    "calculated"
  ],
  "Timestamp": "1567097351092",
  "Type": "PodNet",
  "Version": "0",
  "interface": "eth0",
  "kubernetes": {
    "host": "ip-192-168-75-26.us-west-2.compute.internal",
    "labels": {
      "app": "cloudwatch-agent-statsd",
      "pod-template-hash": "df44f855f"
    },
    "namespace_name": "amazon-cloudwatch",
    "pod_id": "2f4ff5ac-c813-11e9-a31d-06e9dde32928",
    "pod_name": "cloudwatch-agent-statsd-df44f855f-ts4q2",
    "pod_owners": [
      {
        "owner_kind": "Deployment",
        "owner_name": "cloudwatch-agent-statsd"
      }
    ],
    "service_name": "cloudwatch-agent-statsd"
  },
  "pod_interface_network_rx_bytes": 9880.697124714186,
  "pod_interface_network_rx_dropped": 0,
  "pod_interface_network_rx_errors": 0,
  "pod_interface_network_rx_packets": 107.80005532263283,
  "pod_interface_network_total_bytes": 10158.829201483635,
  "pod_interface_network_tx_bytes": 278.13207676944796,
  "pod_interface_network_tx_dropped": 0,
  "pod_interface_network_tx_errors": 0,
  "pod_interface_network_tx_packets": 1.146027574644318
}
```

**類型：容器**

```
{
  "AutoScalingGroupName": "eksctl-myCICluster-nodegroup-standard-workers-NodeGroup-sample",
  "ClusterName": "myCICluster",
  "InstanceId": "i-1234567890123456",
  "InstanceType": "t3.xlarge",
  "Namespace": "amazon-cloudwatch",
  "NodeName": "ip-192-0-2-0.us-west-2.compute.internal",
  "PodName": "cloudwatch-agent-statsd",
  "Service": "cloudwatch-agent-statsd",
  "Sources": [
    "cadvisor",
    "pod",
    "calculated"
  ],
  "Timestamp": "1567097399912",
  "Type": "Container",
  "Version": "0",
  "container_cpu_limit": 200,
  "container_cpu_request": 200,
  "container_cpu_usage_system": 1.87958283771964,
  "container_cpu_usage_total": 6.159993652997942,
  "container_cpu_usage_user": 1.6707403001952357,
  "container_cpu_utilization": 0.15399984132494854,
  "container_memory_cache": 8192,
  "container_memory_failcnt": 0,
  "container_memory_hierarchical_pgfault": 0,
  "container_memory_hierarchical_pgmajfault": 0,
  "container_memory_limit": 104857600,
  "container_memory_mapped_file": 0,
  "container_memory_max_usage": 24580096,
  "container_memory_pgfault": 0,
  "container_memory_pgmajfault": 0,
  "container_memory_request": 104857600,
  "container_memory_rss": 22736896,
  "container_memory_swap": 0,
  "container_memory_usage": 24453120,
  "container_memory_utilization": 0.10574541028701798,
  "container_memory_working_set": 17580032,
  "container_status": "Running",
  "kubernetes": {
    "container_name": "cloudwatch-agent",
    "docker": {
      "container_id": "8967b6b37da239dfad197c9fdea3e5dfd35a8a759ec86e2e4c3f7b401e232706"
    },
    "host": "ip-192-168-75-26.us-west-2.compute.internal",
    "labels": {
      "app": "cloudwatch-agent-statsd",
      "pod-template-hash": "df44f855f"
    },
    "namespace_name": "amazon-cloudwatch",
    "pod_id": "2f4ff5ac-c813-11e9-a31d-06e9dde32928",
    "pod_name": "cloudwatch-agent-statsd-df44f855f-ts4q2",
    "pod_owners": [
      {
        "owner_kind": "Deployment",
        "owner_name": "cloudwatch-agent-statsd"
      }
    ],
    "service_name": "cloudwatch-agent-statsd"
  },
  "number_of_container_restarts": 0
}
```

**類型：ContainerFS**

```
{
  "AutoScalingGroupName": "eksctl-myCICluster-nodegroup-standard-workers-NodeGroup-1174PV2WHZAYU",
  "ClusterName": "myCICluster",
  "EBSVolumeId": "aws://us-west-2b/vol-0a53108976d4a2fda",
  "InstanceId": "i-1234567890123456",
  "InstanceType": "t3.xlarge",
  "Namespace": "amazon-cloudwatch",
  "NodeName": "ip-192-0-2-0.us-west-2.compute.internal",
  "PodName": "cloudwatch-agent-statsd",
  "Service": "cloudwatch-agent-statsd",
  "Sources": [
    "cadvisor",
    "calculated"
  ],
  "Timestamp": "1567097399912",
  "Type": "ContainerFS",
  "Version": "0",

  "device": "/dev/nvme0n1p1",
  "fstype": "vfs",
  "kubernetes": {
    "container_name": "cloudwatch-agent",
    "docker": {
      "container_id": "8967b6b37da239dfad197c9fdea3e5dfd35a8a759ec86e2e4c3f7b401e232706"
    },
    "host": "ip-192-168-75-26.us-west-2.compute.internal",
    "labels": {
      "app": "cloudwatch-agent-statsd",
      "pod-template-hash": "df44f855f"
    },
    "namespace_name": "amazon-cloudwatch",
    "pod_id": "2f4ff5ac-c813-11e9-a31d-06e9dde32928",
    "pod_name": "cloudwatch-agent-statsd-df44f855f-ts4q2",
    "pod_owners": [
      {
        "owner_kind": "Deployment",
        "owner_name": "cloudwatch-agent-statsd"
      }
    ],
    "service_name": "cloudwatch-agent-statsd"
  }
}
```

**類型：叢集**

```
{
  "CloudWatchMetrics": [
    {
      "Metrics": [
        {
          "Unit": "Count",
          "Name": "cluster_node_count"
        },
        {
          "Unit": "Count",
          "Name": "cluster_failed_node_count"
        }
      ],
      "Dimensions": [
        [
          "ClusterName"
        ]
      ],
      "Namespace": "ContainerInsights"
    }
  ],
  "ClusterName": "myCICluster",
  "Sources": [
    "apiserver"
  ],
  "Timestamp": "1567097534160",
  "Type": "Cluster",
  "Version": "0",
  "cluster_failed_node_count": 0,
  "cluster_node_count": 3
}
```

**類型：ClusterService**

```
{
  "CloudWatchMetrics": [
    {
      "Metrics": [
        {
          "Unit": "Count",
          "Name": "service_number_of_running_pods"
        }
      ],
      "Dimensions": [
        [
          "Service",
          "Namespace",
          "ClusterName"
        ],
        [
          "ClusterName"
        ]
      ],
      "Namespace": "ContainerInsights"
    }
  ],
  "ClusterName": "myCICluster",
  "Namespace": "amazon-cloudwatch",
  "Service": "cloudwatch-agent-statsd",
  "Sources": [
    "apiserver"
  ],
  "Timestamp": "1567097534160",
  "Type": "ClusterService",
  "Version": "0",
  "kubernetes": {
    "namespace_name": "amazon-cloudwatch",
    "service_name": "cloudwatch-agent-statsd"
  },
  "service_number_of_running_pods": 1
}
```

**類型：ClusterNamespace**

```
{
  "CloudWatchMetrics": [
    {
      "Metrics": [
        {
          "Unit": "Count",
          "Name": "namespace_number_of_running_pods"
        }
      ],
      "Dimensions": [
        [
          "Namespace",
          "ClusterName"
        ],
        [
          "ClusterName"
        ]
      ],
      "Namespace": "ContainerInsights"
    }
  ],
  "ClusterName": "myCICluster",
  "Namespace": "amazon-cloudwatch",
  "Sources": [
    "apiserver"
  ],
  "Timestamp": "1567097594160",
  "Type": "ClusterNamespace",
  "Version": "0",
  "kubernetes": {
    "namespace_name": "amazon-cloudwatch"
  },
  "namespace_number_of_running_pods": 7
}
```

# Amazon EKS 和 Kubernetes 效能日誌事件中的相關欄位
<a name="Container-Insights-reference-performance-entries-EKS"></a>

對於 Amazon EKS 和 Kubernetes，容器化的 CloudWatch 代理程式會以效能日誌事件的形式發出資料。這可讓 CloudWatch 擷取和存放高基數資料。CloudWatch 使用效能日誌事件中的資料來建立在叢集、節點、與 pod 層級彙總的 CloudWatch 指標，而不需遺失精細的詳細資訊。

下表列出在這些效能日誌事件中與容器洞見指標資料集合相關的欄位。您可以使用 CloudWatch Logs 來查詢任何這些欄位以收集資料或調查問題。如需詳細資訊，請參閱[搭配 CloudWatch Logs Insights 分析日誌資料](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html)。


| Type | 日誌欄位 | 來源 | 公式或備註 | 
| --- | --- | --- | --- | 
|  Pod |  `pod_cpu_utilization`  |  計算  |  公式：`pod_cpu_usage_total / node_cpu_limit`  | 
|  Pod |  `pod_cpu_usage_total` `pod_cpu_usage_total` 的報告單位為 millicore。  |  cadvisor  |   | 
|  Pod |  `pod_cpu_limit`  |  計算  |  公式：`sum(container_cpu_limit)` `sum(container_cpu_limit)` 包含已完成的 Pod。 如果 pod 中的任何容器未定義 CPU 限制，這個欄位就不會在日誌事件中顯示。此項包含[初始化容器](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#resources)。  | 
|  Pod |  `pod_cpu_request`  |  計算  |  公式：`sum(container_cpu_request)` 不保證要設定 `container_cpu_request`。只有已設定的項目會包含在總和中。  | 
|  Pod |  `pod_cpu_utilization_over_pod_limit`  |  計算  |  公式：`pod_cpu_usage_total / pod_cpu_limit`  | 
|  Pod |  `pod_cpu_reserved_capacity`  |  計算  |  公式：`pod_cpu_request / node_cpu_limit`  | 
|  Pod |  `pod_memory_utilization`  |  計算  |  公式：`pod_memory_working_set / node_memory_limit` 它是 pod 記憶體使用量佔節點記憶體限制的百分比。  | 
|  Pod |  `pod_memory_working_set`  |  cadvisor  |   | 
|  Pod |  `pod_memory_limit`  |  計算  |  公式：`sum(container_memory_limit)` 如果 pod 中的任何容器未定義記憶體限制，這個欄位就不會在日誌事件中顯示。此項包含[初始化容器](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#resources)。  | 
|  Pod |  `pod_memory_request`  |  計算  |  公式：`sum(container_memory_request)` 不保證要設定 `container_memory_request`。只有已設定的項目會包含在總和中。  | 
|  Pod |  `pod_memory_utilization_over_pod_limit`  |  計算  |  公式：`pod_memory_working_set / pod_memory_limit` 如果 pod 中的任何容器未定義記憶體限制，這個欄位就不會在日誌事件中顯示。此項包含[初始化容器](https://kubernetes.io/docs/concepts/workloads/pods/init-containers/#resources)。  | 
|  Pod |  `pod_memory_reserved_capacity`  |  計算  |  公式：`pod_memory_request / node_memory_limit`  | 
|  Pod |  `pod_network_tx_bytes`  |  計算  |  公式：`sum(pod_interface_network_tx_bytes)` 此資料可用於每個 pod 的所有網路介面。CloudWatch 代理程式會計算總和並新增指標擷取規則。  | 
|  Pod |  `pod_network_rx_bytes`  |  計算  |  公式：`sum(pod_interface_network_rx_bytes)`  | 
|  Pod |  `pod_network_total_bytes`  |  計算  |  公式：`pod_network_rx_bytes + pod_network_tx_bytes`  | 
|  PodNet |  `pod_interface_network_rx_bytes`  |  cadvisor  | 此資料是 pod 網路介面的網路 rx 每秒位元組。  | 
|  PodNet |  `pod_interface_network_tx_bytes`  |  cadvisor  | 此資料是 pod 網路介面的網路 tx 每秒位元組。 | 
|  容器 |  `container_cpu_usage_total`  |  cadvisor  |   | 
|  容器 |  `container_cpu_limit`  |  cadvisor  |  不保證要設定。如果未設定則不會發出。 | 
|  容器 |  `container_cpu_request`  |  cadvisor  |  不保證要設定。如果未設定則不會發出。 | 
|  容器 |  `container_memory_working_set`  |  cadvisor  |   | 
|  容器 |  `container_memory_limit`  |  Pod  |  不保證要設定。如果未設定則不會發出。 | 
|  容器 |  `container_memory_request`  |  Pod  |  不保證要設定。如果未設定則不會發出。 | 
|  節點 |  `node_cpu_utilization`  |  計算  |  公式：`node_cpu_usage_total / node_cpu_limit`  | 
|  節點 |  `node_cpu_usage_total`  |  cadvisor  |   | 
|  節點 |  `node_cpu_limit`  |  /proc  |   | 
|  節點 |  `node_cpu_request`  |  計算  | 公式：`sum(pod_cpu_request)` 對於 cronjobs，`node_cpu_request` 也包含來自已完成 Pod 的請求。這可能會導致較高的 `node_cpu_reserved_capacity` 值。  | 
|  節點 |  `node_cpu_reserved_capacity`  |  計算  | 公式：`node_cpu_request / node_cpu_limit`  | 
|  節點 |  `node_memory_utilization`  |  計算  | 公式：`node_memory_working_set / node_memory_limit`  | 
|  節點 |  `node_memory_working_set`  |  cadvisor  |   | 
|  節點 |  `node_memory_limit`  |  /proc  |   | 
|  節點 |  `node_memory_request`  |  計算  |  公式：`sum(pod_memory_request)`  | 
|  節點 |  `node_memory_reserved_capacity`  |  計算  | 公式：`node_memory_request / node_memory_limit`  | 
|  節點 |  `node_network_rx_bytes`  |  計算  | 公式：`sum(node_interface_network_rx_bytes)`  | 
|  節點 |  `node_network_tx_bytes`  |  計算  | 公式：`sum(node_interface_network_tx_bytes)`  | 
|  節點 |  `node_network_total_bytes`  |  計算  | 公式：`node_network_rx_bytes + node_network_tx_bytes`  | 
|  節點 |  `node_number_of_running_pods`  |  Pod 清單  |   | 
|  節點 |  `node_number_of_running_containers`  |  Pod 清單  |   | 
|  NodeNet |  `node_interface_network_rx_bytes`  |  cadvisor  |  此資料是工作者節點網路介面的網路 rx 每秒位元組。  | 
|  NodeNet |  `node_interface_network_tx_bytes`  |  cadvisor  |  此資料是工作者節點網路介面的網路 tx 每秒位元組。  | 
|  NodeFS |  `node_filesystem_capacity`  |  cadvisor  |   | 
|  NodeFS |  `node_filesystem_usage`  |  cadvisor  |   | 
|  NodeFS |  `node_filesystem_utilization`  |  計算  |  公式：`node_filesystem_usage / node_filesystem_capacity` 可根據裝置名稱提供此資料。  | 
|  叢集 |  `cluster_failed_node_count`  |  API 伺服器  |   | 
|  叢集 |  `cluster_node_count`  |  API 伺服器  |   | 
|  服務 |  `service_number_of_running_pods`  |  API 伺服器  |   | 
|  `Namespace` |  `namespace_number_of_running_pods`  |  API 伺服器  |   | 

## 指標計算範例
<a name="Container-Insights-calculation-examples"></a>

本區段包含的範例會說明先前資料表中部分值的計算方式。

假設您有一個處於以下狀態的叢集。

```
Node1
   node_cpu_limit = 4
   node_cpu_usage_total = 3
   
   Pod1
     pod_cpu_usage_total = 2
     
     Container1
        container_cpu_limit = 1
        container_cpu_request = 1
        container_cpu_usage_total = 0.8
        
     Container2
        container_cpu_limit = null
        container_cpu_request = null
        container_cpu_usage_total = 1.2
        
   Pod2
     pod_cpu_usage_total = 0.4
     
     Container3
        container_cpu_limit = 1
        container_cpu_request = 0.5
        container_cpu_usage_total = 0.4
        
Node2
   node_cpu_limit = 8
   node_cpu_usage_total = 1.5
   
   Pod3
     pod_cpu_usage_total = 1
     
     Container4
        container_cpu_limit = 2
        container_cpu_request = 2
        container_cpu_usage_total = 1
```

下表顯示如何使用此資料計算 pod CPU 指標。


| 指標 | 公式 | Pod1 | Pod2 | Pod3 | 
| --- | --- | --- | --- | --- | 
|  `pod_cpu_utilization` |  `pod_cpu_usage_total / node_cpu_limit`  |  2 / 4 = 50%  |  0.4 / 4 = 10%  |  1 / 8 = 12.5%  | 
|  `pod_cpu_utilization_over_pod_limit` |  `pod_cpu_usage_total / sum(container_cpu_limit)`  |  不適用，因為未定義 `Container2` 的 CPU 限制  |  0.4 / 1 = 40%  |  1 / 2 = 50%  | 
|  `pod_cpu_reserved_capacity` |  `sum(container_cpu_request) / node_cpu_limit`  |  (1 \$1 0) / 4 = 25%  |  0.5 / 4 = 12.5%  |  2 / 8 = 25%  | 

下表顯示如何使用此資料計算節點 CPU 指標。


| 指標 | 公式 | Node1 | Node2 | 
| --- | --- | --- | --- | 
|  `node_cpu_utilization` |  `node_cpu_usage_total / node_cpu_limit`  |  3 / 4 = 75%  |  1.5 / 8 = 18.75%  | 
|  `node_cpu_reserved_capacity` |  `sum(pod_cpu_request) / node_cpu_limit`  |  1.5 / 4 = 37.5%  |  2 / 8 = 25%  | 

# Container Insights Prometheus 指標監控
<a name="ContainerInsights-Prometheus"></a>

適用於 Prometheus 的 CloudWatch Container Insights 監控可自動從容器化系統和工作負載探索 Prometheus 指標。Prometheus 是一種開放原始碼系統監控和警示工具組。如需詳細資訊，請參閱 Prometheus 文件中的[什麼是 Prometheus？](https://prometheus.io/docs/introduction/overview/)。

探索 Prometheus 指標可支援在 Amazon EC2 執行個體上執行的 [Amazon Elastic Container Service](https://aws.amazon.com/ecs/)、[Amazon Elastic Kubernetes Service](https://aws.amazon.com/eks/) 和 [Kubernetes](https://aws.amazon.com/kubernetes/) 叢集。將會收集 Prometheus 計數器、量測計和摘要指標類型。

對於 Amazon ECS 和 Amazon EKS 叢集，支援 EC2 和 Fargate 啟動類型。Container Insights 會自動從數個工作負載收集指標，而您可以將其設定為從任何工作負載收集指標。

您可以將 Prometheus 採用為開放原始碼和開放標準的方式，在 CloudWatch 中擷取自訂指標。具有 Prometheus 支援的 CloudWatch 代理程式會探索並收集 Prometheus 指儀表板標，以便更快速地對應用程式效能折損和故障進行監控、故障排除和警示。這也會減少所需的監控工具數目以改善可觀察性。

Container Insights Prometheus 支援涉及指標和日誌的依使用次數計費，包括收集、存放和分析。如需詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

**適用於某些工作負載的預先建置儀表板**

Container Insights Prometheus 解決方案包含適用於本節所列熱門工作負載的預先建置儀表板。如需這些工作負載的範例組態，請參閱 [(選用) 設定範例容器化 Amazon ECS 工作負載，以進行 Prometheus 指標測試](ContainerInsights-Prometheus-Sample-Workloads-ECS.md) 和 [(選用) 設定範例容器化 Amazon EKS 工作負載範例進行 Prometheus 指標測試](ContainerInsights-Prometheus-Sample-Workloads.md)。

您也可以編輯代理程式組態檔案，將 Container Insights 設定為從其他容器化服務和應用程式收集 Prometheus 指標。

具有預先建置儀表板的工作負載，適用於 Amazon EC2 執行個體上執行的 Amazon EKS 叢集和 Kubernetes 叢集：
+ AWS App Mesh
+ NGINX
+ Memcached
+ Java/JMX
+ HAProxy

具有預先建置儀表板的工作負載，適用於 Amazon ECS 叢集：
+ AWS App Mesh
+ Java/JMX
+ NGINX
+ NGINX Plus

# 在 Amazon ECS 執行個體上安裝和設定 Prometheus 指標集合
<a name="ContainerInsights-Prometheus-Setup-ECS"></a>

若要從 Amazon ECS 叢集收集 Prometheus 指標，您可以使用 CloudWatch 代理程式做為收集器，或使用 AWS Distro for OpenTelemetry 收集器。如需使用 AWS Distro for OpenTelemetry 收集器的詳細資訊，請參閱 https：//[https://aws-otel.github.io/docs/getting-started/container-insights/ecs-prometheus](https://aws-otel.github.io/docs/getting-started/container-insights/ecs-prometheus)。

以下各節說明如何使用 CloudWatch 代理程式作為收集器來擷取 Prometheus 指標。您可以在執行 Amazon ECS 的叢集上安裝具有 Prometheus 監控的 CloudWatch 代理程式，您也可以選擇性地設定代理程式以湊集其他目標。這些章節也提供選擇性的教學課程，用於設定範例工作負載，以便使用 Prometheus 監控進行測試。

Amazon ECS 上的 Container Insights 支援下列 Prometheus 指標的啟動類型和網路模式組合：


| Amazon ECS 啟動類型 | 支援的網路模式 | 
| --- | --- | 
|  EC2 (Linux)  |  橋接器、主機和 awsvpc  | 
|  Fargate  |  awsvpc  | 

**VPC 安全群組要求**

Prometheus 工作負載安全群組的輸入規則必須開啟到 CloudWatch 代理程式的 Prometheus 連接埠，以便透過私有 IP 擷取 Prometheus 指標。

CloudWatch 代理程式安全群組的輸出規則必須允許 CloudWatch 代理程式透過私有 IP 連接至 Prometheus 工作負載的連接埠。

**Topics**
+ [在 Amazon ECS 叢集上安裝含有 Prometheus 指標收集的 CloudWatch 代理程式](ContainerInsights-Prometheus-install-ECS.md)
+ [湊集其他 Prometheus 來源並匯入這些指標](ContainerInsights-Prometheus-Setup-configure-ECS.md)
+ [(選用) 設定範例容器化 Amazon ECS 工作負載，以進行 Prometheus 指標測試](ContainerInsights-Prometheus-Sample-Workloads-ECS.md)

# 在 Amazon ECS 叢集上安裝含有 Prometheus 指標收集的 CloudWatch 代理程式
<a name="ContainerInsights-Prometheus-install-ECS"></a>

本節說明如何在執行 Amazon ECS 的叢集中設定具有 Prometheus 監控的 CloudWatch 代理程式。執行這項操作之後，代理程式會自動湊集和匯入該叢集中執行的下列工作負載的指標。
+ AWS App Mesh
+ Java/JMX

您也可以設定代理程式，以從其他 Prometheus 工作負載和來源湊集和匯入指標。

## 設定 IAM 角色
<a name="ContainerInsights-Prometheus-Setup-ECS-IAM"></a>

您需要兩個 IAM 角色來執行 CloudWatch 代理程式任務定義。如果您在 CloudFormation 堆疊**CreateIAMRoles=True**中指定 ，讓 Container Insights 為您建立這些角色，則會使用正確的許可來建立角色。如果您想要自行建立或使用現有角色，則需要下列角色和許可。
+ **CloudWatch 代理程式 ECS 任務角色** — CloudWatch 代理程式容器會使用此角色。它必須包含 **CloudWatchAgentServerPolicy** 政策和包含下列唯讀許可的客戶受管政策：
  + `ec2:DescribeInstances`
  + `ecs:ListTasks`
  + `ecs:ListServices`
  + `ecs:DescribeContainerInstances`
  + `ecs:DescribeServices`
  + `ecs:DescribeTasks`
  + `ecs:DescribeTaskDefinition`
+ **CloudWatch 代理程式 ECS 任務執行角色** — 這是 Amazon ECS 啟動和執行容器所需的角色。確保您的任務執行角色已連接至 **AmazonSSMReadOnlyAccess**、**AmazonECSTaskExecutionRolePolicy** 和 **CloudWatchAgentServerPolicy** 政策。如果您要存放更敏感的資料以供 Amazon ECS 使用，請參閱[指定敏感資料](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/specifying-sensitive-data.html)。

## 使用 安裝具有 Prometheus 監控的 CloudWatch 代理程式 CloudFormation
<a name="ContainerInsights-Prometheus-Setup-ECS-CFN"></a>

您可以使用 AWS CloudFormation 安裝具有 Amazon ECS 叢集 Prometheus 監控的 CloudWatch 代理程式。下列清單顯示了您將在 CloudFormation 範本中使用的參數。
+ **ECSClusterName**— 指定目標 Amazon ECS 叢集。
+ **CreateIAMRoles**— 指定 **True**，以為 Amazon ECS 任務角色和 Amazon ECS 任務執行角色建立新角色。指定 **False** 以重複使用現有角色。
+ **TaskRoleName**— 如果您將 **CreateIAMRoles** 指定為 **True**，則會指定要用於新 Amazon ECS 任務角色的名稱。如果您將 **CreateIAMRoles** 指定為 **False**，則會指定要作為 Amazon ECS 任務角色使用的現有角色。
+ **TaskRoleName**— 如果您將 **CreateIAMRoles** 指定為 **True**，則會指定要用於新 Amazon ECS 任務角色的名稱。如果您將 **CreateIAMRoles** 指定為 **False**，則會指定要作為 Amazon ECS 任務執行角色使用的現有角色。
+ **ECSNetworkMode**— 如果您使用 EC2 啟動類型，請在此處指定網路模式。其必須為 **bridge** 或 **host**。
+ **ECSLaunchType**— 指定 **fargate** 或 **EC2**。
+ **SecurityGroupID**— 如果 **ECSNetworkMode** 是 **awsvpc**，請在此指定安全群組 ID。
+ **SubneId**— 如果 **ECSNetworkMode** 是 **awsvpc**，請在此處指定子網路 ID。

### 命令範例
<a name="ContainerInsights-Prometheus-Setup-ECS-CFNcommands"></a>

本節包含在各種情況下使用 Prometheus 監控安裝 Container Insights 的範例 CloudFormation 命令。

**在橋接網路模式下為 Amazon ECS 叢集建立 CloudFormation 堆疊**

```
export AWS_PROFILE=your_aws_config_profile_eg_default
export AWS_DEFAULT_REGION=your_aws_region_eg_ap-southeast-1
export ECS_CLUSTER_NAME=your_ec2_ecs_cluster_name
export ECS_NETWORK_MODE=bridge
export CREATE_IAM_ROLES=True
export ECS_TASK_ROLE_NAME=your_selected_ecs_task_role_name
export ECS_EXECUTION_ROLE_NAME=your_selected_ecs_execution_role_name

curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/replica-service/cwagent-prometheus/cloudformation-quickstart/cwagent-ecs-prometheus-metric-for-bridge-host.yaml

aws cloudformation create-stack --stack-name CWAgent-Prometheus-ECS-${ECS_CLUSTER_NAME}-EC2-${ECS_NETWORK_MODE} \
    --template-body file://cwagent-ecs-prometheus-metric-for-bridge-host.yaml \
    --parameters ParameterKey=ECSClusterName,ParameterValue=${ECS_CLUSTER_NAME} \
                 ParameterKey=CreateIAMRoles,ParameterValue=${CREATE_IAM_ROLES} \
                 ParameterKey=ECSNetworkMode,ParameterValue=${ECS_NETWORK_MODE} \
                 ParameterKey=TaskRoleName,ParameterValue=${ECS_TASK_ROLE_NAME} \
                 ParameterKey=ExecutionRoleName,ParameterValue=${ECS_EXECUTION_ROLE_NAME} \
    --capabilities CAPABILITY_NAMED_IAM \
    --region ${AWS_DEFAULT_REGION} \
    --profile ${AWS_PROFILE}
```

**在主機網路模式中為 Amazon ECS 叢集建立 CloudFormation 堆疊**

```
export AWS_PROFILE=your_aws_config_profile_eg_default
export AWS_DEFAULT_REGION=your_aws_region_eg_ap-southeast-1
export ECS_CLUSTER_NAME=your_ec2_ecs_cluster_name
export ECS_NETWORK_MODE=host
export CREATE_IAM_ROLES=True
export ECS_TASK_ROLE_NAME=your_selected_ecs_task_role_name
export ECS_EXECUTION_ROLE_NAME=your_selected_ecs_execution_role_name


curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/replica-service/cwagent-prometheus/cloudformation-quickstart/cwagent-ecs-prometheus-metric-for-bridge-host.yaml

aws cloudformation create-stack --stack-name CWAgent-Prometheus-ECS-${ECS_CLUSTER_NAME}-EC2-${ECS_NETWORK_MODE} \
    --template-body file://cwagent-ecs-prometheus-metric-for-bridge-host.yaml \
    --parameters ParameterKey=ECSClusterName,ParameterValue=${ECS_CLUSTER_NAME} \
                 ParameterKey=CreateIAMRoles,ParameterValue=${CREATE_IAM_ROLES} \
                 ParameterKey=ECSNetworkMode,ParameterValue=${ECS_NETWORK_MODE} \
                 ParameterKey=TaskRoleName,ParameterValue=${ECS_TASK_ROLE_NAME} \
                 ParameterKey=ExecutionRoleName,ParameterValue=${ECS_EXECUTION_ROLE_NAME} \ 
    --capabilities CAPABILITY_NAMED_IAM \
    --region ${AWS_DEFAULT_REGION} \
    --profile ${AWS_PROFILE}
```

**在 awsvpc 網路模式中為 Amazon ECS 叢集建立 CloudFormation 堆疊**

```
export AWS_PROFILE=your_aws_config_profile_eg_default
export AWS_DEFAULT_REGION=your_aws_region_eg_ap-southeast-1
export ECS_CLUSTER_NAME=your_ec2_ecs_cluster_name
export ECS_LAUNCH_TYPE=EC2
export CREATE_IAM_ROLES=True
export ECS_CLUSTER_SECURITY_GROUP=your_security_group_eg_sg-xxxxxxxxxx
export ECS_CLUSTER_SUBNET=your_subnet_eg_subnet-xxxxxxxxxx
export ECS_TASK_ROLE_NAME=your_selected_ecs_task_role_name
export ECS_EXECUTION_ROLE_NAME=your_selected_ecs_execution_role_name

curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/replica-service/cwagent-prometheus/cloudformation-quickstart/cwagent-ecs-prometheus-metric-for-awsvpc.yaml

aws cloudformation create-stack --stack-name CWAgent-Prometheus-ECS-${ECS_CLUSTER_NAME}-${ECS_LAUNCH_TYPE}-awsvpc \
    --template-body file://cwagent-ecs-prometheus-metric-for-awsvpc.yaml \
    --parameters ParameterKey=ECSClusterName,ParameterValue=${ECS_CLUSTER_NAME} \
                 ParameterKey=CreateIAMRoles,ParameterValue=${CREATE_IAM_ROLES} \
                 ParameterKey=ECSLaunchType,ParameterValue=${ECS_LAUNCH_TYPE} \
                 ParameterKey=SecurityGroupID,ParameterValue=${ECS_CLUSTER_SECURITY_GROUP} \
                 ParameterKey=SubnetID,ParameterValue=${ECS_CLUSTER_SUBNET} \
                 ParameterKey=TaskRoleName,ParameterValue=${ECS_TASK_ROLE_NAME} \
                 ParameterKey=ExecutionRoleName,ParameterValue=${ECS_EXECUTION_ROLE_NAME} \
    --capabilities CAPABILITY_NAMED_IAM \
    --region ${AWS_DEFAULT_REGION} \
    --profile ${AWS_PROFILE}
```

**在 awsvpc 網路模式中為 Fargate 叢集建立 CloudFormation 堆疊**

```
export AWS_PROFILE=your_aws_config_profile_eg_default
export AWS_DEFAULT_REGION=your_aws_region_eg_ap-southeast-1
export ECS_CLUSTER_NAME=your_ec2_ecs_cluster_name
export ECS_LAUNCH_TYPE=FARGATE
export CREATE_IAM_ROLES=True
export ECS_CLUSTER_SECURITY_GROUP=your_security_group_eg_sg-xxxxxxxxxx
export ECS_CLUSTER_SUBNET=your_subnet_eg_subnet-xxxxxxxxxx
export ECS_TASK_ROLE_NAME=your_selected_ecs_task_role_name
export ECS_EXECUTION_ROLE_NAME=your_selected_ecs_execution_role_name            

curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/replica-service/cwagent-prometheus/cloudformation-quickstart/cwagent-ecs-prometheus-metric-for-awsvpc.yaml

aws cloudformation create-stack --stack-name CWAgent-Prometheus-ECS-${ECS_CLUSTER_NAME}-${ECS_LAUNCH_TYPE}-awsvpc \
    --template-body file://cwagent-ecs-prometheus-metric-for-awsvpc.yaml \
    --parameters ParameterKey=ECSClusterName,ParameterValue=${ECS_CLUSTER_NAME} \
                 ParameterKey=CreateIAMRoles,ParameterValue=${CREATE_IAM_ROLES} \
                 ParameterKey=ECSLaunchType,ParameterValue=${ECS_LAUNCH_TYPE} \
                 ParameterKey=SecurityGroupID,ParameterValue=${ECS_CLUSTER_SECURITY_GROUP} \
                 ParameterKey=SubnetID,ParameterValue=${ECS_CLUSTER_SUBNET} \
                 ParameterKey=TaskRoleName,ParameterValue=${ECS_TASK_ROLE_NAME} \
                 ParameterKey=ExecutionRoleName,ParameterValue=${ECS_EXECUTION_ROLE_NAME} \
    --capabilities CAPABILITY_NAMED_IAM \
    --region ${AWS_DEFAULT_REGION} \
    --profile ${AWS_PROFILE}
```

### AWS CloudFormation 堆疊建立的資源
<a name="ContainerInsights-Prometheus-Setup-ECS-resources"></a>

下表列出當您 CloudFormation 使用 在 Amazon ECS 叢集上設定 Container Insights with Prometheus 監控時所建立 AWS 的資源。


| Resource Type (資源類型) | 資源名稱 | 說明 | 
| --- | --- | --- | 
|  AWS::SSM::Parameter  |  AmazonCloudWatch-CWAgentConfig-\$1*ECS\$1CLUSTER\$1NAME*-\$1*ECS\$1LAUNCH\$1TYPE*-\$1*ECS\$1NETWORK\$1MODE*  |  這是具有預設 App Mesh 和 Java/JMX 內嵌指標格式定義的 CloudWatch 代理程式。  | 
|  AWS::SSM::Parameter  |  AmazonCloudWatch-PrometheusConfigName-\$1*ECS\$1CLUSTER\$1NAME*-\$1*ECS\$1LAUNCH\$1TYPE*-\$1*ECS\$1NETWORK\$1MODE*  |  這是 Prometheus 湊集組態。  | 
|  AWS::IAM::Role  |  **\$1ECS\$1TASK\$1ROLE\$1NAME**。  |  Amazon ECS 任務角色。這僅在您為 `CREATE_IAM_ROLES` 指定 **True** 時建立。  | 
|  AWS::IAM::Role  |  **\$1\$1ECS\$1EXECUTION\$1ROLE\$1NAME\$1**   |  Amazon ECS 任務執行角色。這僅在您為 `CREATE_IAM_ROLES` 指定 **True** 時建立。  | 
|  AWS::ECS::TaskDefinition  |  cwagent-prometheus-\$1*ECS\$1CLUSTER\$1NAME*-\$1*ECS\$1LAUNCH\$1TYPE*-\$1*ECS\$1NETWORK\$1MODE*   |   | 
|  AWS::ECS::Service  |  cwagent-prometheus-replica-service-\$1*ECS\$1LAUNCH\$1TYPE*-\$1*ECS\$1NETWORK\$1MODE*  |   | 

### 使用 Prometheus 監控刪除 CloudWatch 代理程式的 CloudFormation 堆疊
<a name="ContainerInsights-Prometheus-ECS-delete"></a>

若要從 Amazon ECS 叢集刪除 CloudWatch 代理程式，請輸入這些命令。

```
export AWS_PROFILE=your_aws_config_profile_eg_default
export AWS_DEFAULT_REGION=your_aws_region_eg_ap-southeast-1
export CLOUDFORMATION_STACK_NAME=your_cloudformation_stack_name

aws cloudformation delete-stack \
--stack-name ${CLOUDFORMATION_STACK_NAME} \
--region ${AWS_DEFAULT_REGION} \
--profile ${AWS_PROFILE}
```

# 湊集其他 Prometheus 來源並匯入這些指標
<a name="ContainerInsights-Prometheus-Setup-configure-ECS"></a>

具有 Prometheus 監控的 CloudWatch 代理程式需要兩種組態來湊集 Prometheus 指標。其中一個是 Prometheus 文件的 [<scrape\$1config>](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config) 中記錄的標準 Prometheus 湊集組態。另一個適用於 CloudWatch 代理程式組態。

對於 Amazon ECS 叢集，組態會透過 Amazon ECS 任務定義中的秘密與 AWS Systems Manager 的參數存放區進行整合：
+ 秘密 `PROMETHEUS_CONFIG_CONTENT` 適用於 Prometheus 湊集組態。
+ 秘密 `CW_CONFIG_CONTENT` 適用於 CloudWatch 代理程式組態。

若要湊集其他 Prometheus 指標來源並將這些指標匯入 CloudWatch，您可以修改 Prometheus 湊集組態和 CloudWatch 代理程式組態，然後使用更新的組態重新部署代理程式。

**VPC 安全群組要求**

Prometheus 工作負載安全群組的輸入規則必須開啟到 CloudWatch 代理程式的 Prometheus 連接埠，以便透過私有 IP 擷取 Prometheus 指標。

CloudWatch 代理程式安全群組的輸出規則必須允許 CloudWatch 代理程式透過私有 IP 連接至 Prometheus 工作負載的連接埠。

## Prometheus 湊集組態
<a name="ContainerInsights-Prometheus-Setup-config-global"></a>

CloudWatch 代理程式支援標準 Prometheus 湊集組態，如 Prometheus 文件的 [<scrape\$1config>](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config) 中所述。您可以編輯此區段來更新已存在於此檔案中的組態，並新增其他 Prometheus 湊集目標。根據預設，範例組態檔案包含下列全域組態行：

```
global:
  scrape_interval: 1m
  scrape_timeout: 10s
```
+ **scrape\$1interval**— 定義湊集目標的頻率。
+ **scrape\$1timeout**— 定義湊集請求逾時之前要等待的時間。

您也可以在任務層級為這些設定定義不同的數值，以覆寫全域設定。

### Prometheus 湊集任務
<a name="ContainerInsights-Prometheus-Setup-config-scrape"></a>

CloudWatch 代理程式 YAML 檔案已設定一些預設的湊集任務。例如，在 Amazon ECS 的 YAML 檔案中，例如 `cwagent-ecs-prometheus-metric-for-bridge-host.yaml`，已在 `ecs_service_discovery` 區段中設定預設湊集任務。

```
"ecs_service_discovery": {
                  "sd_frequency": "1m",
                  "sd_result_file": "/tmp/cwagent_ecs_auto_sd.yaml",
                  "docker_label": {
                  },
                  "task_definition_list": [
                    {
                      "sd_job_name": "ecs-appmesh-colors",
                      "sd_metrics_ports": "9901",
                      "sd_task_definition_arn_pattern": ".*:task-definition\/.*-ColorTeller-(white):[0-9]+",
                      "sd_metrics_path": "/stats/prometheus"
                    },
                    {
                      "sd_job_name": "ecs-appmesh-gateway",
                      "sd_metrics_ports": "9901",
                      "sd_task_definition_arn_pattern": ".*:task-definition/.*-ColorGateway:[0-9]+",
                      "sd_metrics_path": "/stats/prometheus"
                    }
                  ]
                }
```

會湊集這些預設目標當中的各個目標，並使用內嵌的指標格式將指標傳送到日誌事件中的 CloudWatch。如需詳細資訊，請參閱[在日誌中內嵌指標](CloudWatch_Embedded_Metric_Format.md)。

來自 Amazon ECS 叢集的日誌事件會存放在 **/aws/ecs/containerinsights/*cluster\$1name*/prometheus** 日誌群組。

每個湊集任務都包含在此日誌群組的不同日誌串流中。

若要新增湊集目標，您可在 YAML 檔案的 `ecs_service_discovery` 區段下的 `task_definition_list` 區段中新增條目，然後重新啟動代理程式。如需此程序的範例，請參閱[新增 Prometheus 湊集目標的教學課程：Prometheus API 伺服器指標](ContainerInsights-Prometheus-Setup-configure.md#ContainerInsights-Prometheus-Setup-new-exporters)。

## Prometheus 的 CloudWatch 代理程式組態
<a name="ContainerInsights-Prometheus-Setup-cw-agent-config"></a>

CloudWatch 代理程式組態檔案在 `metrics_collected` 下有一個 `prometheus` 區段可用於 Prometheus 湊集組態。其包含下列組態選項：
+ **cluster\$1name**— 指定要在日誌事件中新增為標籤的叢集名稱。此欄位為選用欄位。如果您省略此值，代理程式可以偵測 Amazon ECS 叢集名稱。
+ **log\$1group\$1name**— 為湊集的 Prometheus 指標指定日誌檔案群組名稱。此欄位為選用欄位。如果您省略此值，CloudWatch 會將 **/aws/ecs/containerinsights/*cluster\$1name*/prometheus** 用於來自 Amazon ECS 叢集的日誌。
+ **prometheus\$1config\$1path**— 指定 Prometheus 湊集組態檔案路徑。如果此欄位的值以 `env:` 為開頭，則將從容器的環境變數中擷取 Prometheus 湊集組態檔案內容。請不要變更此欄位。
+ **ecs\$1service\$1discovery**— 是指定 Amazon ECS Prometheus 目標自動探索功能組態的區段。支援兩種模式來探索 Prometheus 目標：根據容器的 Docker 標籤進行探索，或根據 Amazon ECS 任務定義 ARN 規則表達式進行探索。您可以同時使用這兩種模式，CloudWatch 代理程式會根據以下情況刪除重複的已搜索到的目標：*\$1private\$1ip\$1:\$1port\$1/\$1metrics\$1path\$1*。

  `ecs_service_discovery` 區段可以包含下列欄位：
  + `sd_frequency` 是發現 Prometheus Exporters 的頻率。指定數字和單位尾碼。例如：每分鐘一次 `1m` 或每 30 秒`30s`一次。有效的單位尾碼為`ns`、`us`、`ms`、`s`、`m` 以及 `h`。

    此欄位為選用欄位。預設值為 60 秒 (1 分鐘)。
  + `sd_target_cluster` 是用於自動探索的目標 Amazon ECS 叢集名稱。此欄位為選用欄位。預設是安裝 CloudWatch 代理程式的 Amazon ECS 叢集名稱。
  + `sd_cluster_region` 是目標 Amazon ECS 叢集的區域。此欄位為選用欄位。預設是安裝 CloudWatch 代理程式的 Amazon ECS 叢集區域。
  + `sd_result_file` 是 Prometheus 目標結果的 YAML 檔案路徑。Prometheus 湊集組態將參與此檔案。
  + `docker_label` 是選用區段，您可以用它來指定 Docker 標籤型服務探索的組態。如果您省略此區段，則不會使用 Docker 標籤型探索。此區段可以包含下列欄位：
    + `sd_port_label` 是容器的 Docker 標籤名稱，用於指定 Prometheus 指標的容器連接埠。預設值為 `ECS_PROMETHEUS_EXPORTER_PORT`。如果容器沒有此 Docker 標籤，CloudWatch 代理程式將略過它。
    + `sd_metrics_path_label` 是容器的 Docker 標籤名稱，用於指定 Prometheus 指標路徑。預設值為 `ECS_PROMETHEUS_METRICS_PATH`。如果容器沒有此 Docker 標籤，則代理程式會假設預設路徑 `/metrics`。
    + `sd_job_name_label` 是容器的 Docker 標籤名稱，用於指定 Prometheus 湊集任務名稱。預設值為 `job`。如果容器沒有此 Docker 標籤，CloudWatch 代理程式會在 Prometheus 湊集組態中使用任務名稱。
  + `task_definition_list` 是選用區段，您可以用它來指定任務定義型服務探索的組態。如果您省略此區段，則不會使用任務定義型探索。此區段可以包含下列欄位：
    + `sd_task_definition_arn_pattern` 是用來指定要探索的 Amazon ECS 任務定義的模式。這是規則表達式。
    + `sd_metrics_ports` 列出了 Prometheus 指標的 containerPort。使用分號分隔 containerPorts。
    + `sd_container_name_pattern` 指定了 Amazon ECS 任務容器名稱。這是規則表達式。
    + `sd_metrics_path` 指定了 Prometheus 指標路徑。如果您省略此項，代理程式會假設預設路徑 `/metrics`
    + `sd_job_name` 指定了 Prometheus 湊集任務名稱。如果您省略此欄位，CloudWatch 代理程式會使用 Prometheus 湊集組態中的任務名稱。
  + `service_name_list_for_tasks` 是選用區段，您可以用它來指定服務名稱型探索的組態。如果您省略此區段，則不會使用服務名稱型探索。此區段可以包含下列欄位：
    + `sd_service_name_pattern` 是用來指定要探索任務的 Amazon ECS 服務的模式。這是規則表達式。
    + `sd_metrics_ports` 列出了 Prometheus 指標的 `containerPort`。使用分號分隔多個 `containerPorts`。
    + `sd_container_name_pattern` 指定了 Amazon ECS 任務容器名稱。這是規則表達式。
    + `sd_metrics_path` 指定了 Prometheus 指標路徑。如果您省略此項，代理程式會假設預設路徑 `/metrics`。
    + `sd_job_name` 指定了 Prometheus 湊集任務名稱。如果您省略此欄位，CloudWatch 代理程式會使用 Prometheus 湊集組態中的任務名稱。
+ **metric\$1declaration**— 是以要產生之內嵌指標格式來指定日誌陣列的區段。根據預設，CloudWatch 代理程式匯入的每個 Prometheus 來源都有 `metric_declaration` 區段。這些區段各包括下列欄位：
  + `label_matcher` 是一個規則表達式，會檢查 `source_labels` 中列出的標籤值。符合的指標已啟用，可包含在傳送至 CloudWatch 的內嵌指標格式。

    如果您在 `source_labels` 中指定了多個標籤，我們建議您不要在 `label_matcher` 的規則表達式中使用 `^` 或 `$` 字元。
  + `source_labels` 指定由 `label_matcher` 行檢查的標籤值。
  + `label_separator` 指定要在 ` label_matcher` 行中使用的分隔符號 (如果指定多個 `source_labels`)。預設值為 `;`。您可以在下面的範例中看到 `label_matcher` 行中使用此預設值。
  + `metric_selectors` 是一個規則表達式，可指定要收集和傳送至 CloudWatch 的指標。
  + `dimensions` 是要用作為每個所選指標之 CloudWatch 維度的標籤清單。

請參閱以下 `metric_declaration` 範例。

```
"metric_declaration": [
  {
     "source_labels":[ "Service", "Namespace"],
     "label_matcher":"(.*node-exporter.*|.*kube-dns.*);kube-system$",
     "dimensions":[
        ["Service", "Namespace"]
     ],
     "metric_selectors":[
        "^coredns_dns_request_type_count_total$"
     ]
  }
]
```

此範例會在符合下列條件時，設定內嵌指標格式區段，以作為日誌事件傳送：
+ `Service` 的數值包含 `node-exporter` 或 `kube-dns`。
+ `Namespace` 的值為 `kube-system`。
+ Prometheus 指標 `coredns_dns_request_type_count_total` 包含 `Service` 和 `Namespace` 標籤。

傳送的日誌事件包含下列反白顯示的區段：

```
{
   "CloudWatchMetrics":[
      {
         "Metrics":[
            {
               "Name":"coredns_dns_request_type_count_total"
            }
         ],
         "Dimensions":[
            [
               "Namespace",
               "Service"
            ]
         ],
         "Namespace":"ContainerInsights/Prometheus"
      }
   ],
   "Namespace":"kube-system",
   "Service":"kube-dns",
   "coredns_dns_request_type_count_total":2562,
   "eks_amazonaws_com_component":"kube-dns",
   "instance":"192.168.61.254:9153",
   "job":"kubernetes-service-endpoints",
   ...
}
```

# 在 Amazon ECS 叢集上自動探索的詳細指南
<a name="ContainerInsights-Prometheus-Setup-autodiscovery-ecs"></a>

Prometheus 提供數十種動態服務探索機制，如 [<scrape\$1config>](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config) 中所述 不過，Amazon ECS 沒有內建的服務探索。CloudWatch 代理程式會新增此機制。

啟用 Amazon ECS Prometheus 服務探索後，CloudWatch 代理程式會定期對 Amazon ECS 和 Amazon EC2 前端進行下列 API 呼叫，以擷取目標 ECS 叢集中正在執行的 ECS 任務的中繼資料。

```
EC2:DescribeInstances
ECS:ListTasks
ECS:ListServices
ECS:DescribeContainerInstances
ECS:DescribeServices
ECS:DescribeTasks
ECS:DescribeTaskDefinition
```

CloudWatch 代理程式會使用中繼資料來掃描 ECS 叢集內的 Prometheus 目標。CloudWatch 代理程式支援三種服務探索模式：
+ 容器 Docker 標籤型服務探索
+ ECS 任務定義 ARN 規則表達式型服務探索
+ ECS 服務名稱規則表達式型服務探索

所有模式可以一起使用。CloudWatch 代理程式會根據下列項目刪除重複的已搜索到的目標：`{private_ip}:{port}/{metrics_path}`。

所有已搜索到的目標都會寫入由 CloudWatch 代理程式容器內的 `sd_result_file` 組態欄位指定的結果檔案中。以下是範例結果檔案：

```
- targets:
  - 10.6.1.95:32785
  labels:
    __metrics_path__: /metrics
    ECS_PROMETHEUS_EXPORTER_PORT: "9406"
    ECS_PROMETHEUS_JOB_NAME: demo-jar-ec2-bridge-dynamic
    ECS_PROMETHEUS_METRICS_PATH: /metrics
    InstanceType: t3.medium
    LaunchType: EC2
    SubnetId: subnet-123456789012
    TaskDefinitionFamily: demo-jar-ec2-bridge-dynamic-port
    TaskGroup: family:demo-jar-ec2-bridge-dynamic-port
    TaskRevision: "7"
    VpcId: vpc-01234567890
    container_name: demo-jar-ec2-bridge-dynamic-port
    job: demo-jar-ec2-bridge-dynamic
- targets:
  - 10.6.3.193:9404
  labels:
    __metrics_path__: /metrics
    ECS_PROMETHEUS_EXPORTER_PORT_SUBSET_B: "9404"
    ECS_PROMETHEUS_JOB_NAME: demo-tomcat-ec2-bridge-mapped-port
    ECS_PROMETHEUS_METRICS_PATH: /metrics
    InstanceType: t3.medium
    LaunchType: EC2
    SubnetId: subnet-123456789012
    TaskDefinitionFamily: demo-tomcat-ec2-bridge-mapped-port
    TaskGroup: family:demo-jar-tomcat-bridge-mapped-port
    TaskRevision: "12"
    VpcId: vpc-01234567890
    container_name: demo-tomcat-ec2-bridge-mapped-port
    job: demo-tomcat-ec2-bridge-mapped-port
```

您可以將此結果檔案與 Prometheus 檔案型服務探索直接整合。如需 Prometheus 檔案型服務探索的詳細資訊，請參閱 [<file\$1sd\$1config>](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#file_sd_config)。

 假設結果檔案寫入 `/tmp/cwagent_ecs_auto_sd.yaml`。下列 Prometheus 湊集組態將會使用它。

```
global:
  scrape_interval: 1m
  scrape_timeout: 10s
scrape_configs:
  - job_name: cwagent-ecs-file-sd-config
    sample_limit: 10000
    file_sd_configs:
      - files: [ "/tmp/cwagent_ecs_auto_sd.yaml" ]
```

CloudWatch 代理程式也會為已搜索到的目標新增下列其他標籤。
+ `container_name`
+ `TaskDefinitionFamily`
+ `TaskRevision`
+ `TaskGroup`
+ `StartedBy`
+ `LaunchType`
+ `job`
+ `__metrics_path__`
+ Docker 標籤

當叢集具有 EC2 啟動類型時，會新增以下三個標籤。
+ `InstanceType`
+ `VpcId`
+ `SubnetId`

**注意**  
不符合規則表達式的 Docker 標籤 `[a-zA-Z_][a-zA-Z0-9_]*` 會被篩選掉。這與 Prometheus 文件中的[組態檔案](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#labelname)的 `label_name` 列出的 Prometheus 慣例相符。

## ECS 服務探索組態範例
<a name="ContainerInsights-Prometheus-Setup-autodiscovery-ecs-examples"></a>

本節包含示範 ECS 服務探索的範例。

**範例 1**

```
"ecs_service_discovery": {
  "sd_frequency": "1m",
  "sd_result_file": "/tmp/cwagent_ecs_auto_sd.yaml",
  "docker_label": {
  }
}
```

此範例會啟用 Docker 標籤型服務探索。CloudWatch 代理程式將會每分鐘查詢一次 ECS 任務的中繼資料，然後將已搜索到的目標寫入 CloudWatch 代理程式容器內的 `/tmp/cwagent_ecs_auto_sd.yaml` 檔案中。

`docker_label` 區段中的 `sd_port_label` 的預設值為 `ECS_PROMETHEUS_EXPORTER_PORT`。如果 ECS 任務中任何正在執行的容器具有 `ECS_PROMETHEUS_EXPORTER_PORT` Docker 標籤，則 CloudWatch 代理程式會使用其值作為 `container port` 掃描容器的所有公開連接埠。如果有相符項目，則會使用映射的主機連接埠加上容器的私有 IP，以下列格式建構 Prometheus 匯出工具目標：`private_ip:host_port`。

`docker_label` 區段中的 `sd_metrics_path_label` 的預設值為 `ECS_PROMETHEUS_METRICS_PATH`。如果容器具有此 Docker 標籤，則其值將被用作 `__metrics_path__`。如果容器沒有此標籤，則會使用預設值 `/metrics`。

`docker_label` 區段中的 `sd_job_name_label` 的預設值為 `job`。如果容器具有此 Docker 標籤，其值會附加為目標的其中一個標籤，以取代 Prometheus 組態中指定的預設任務名稱。此 Docker 標籤的值會用作 CloudWatch Logs 日誌群組中的日誌串流名稱。

**範例 2**

```
"ecs_service_discovery": {
  "sd_frequency": "15s",
  "sd_result_file": "/tmp/cwagent_ecs_auto_sd.yaml",
  "docker_label": {
    "sd_port_label": "ECS_PROMETHEUS_EXPORTER_PORT_SUBSET_A",
    "sd_job_name_label": "ECS_PROMETHEUS_JOB_NAME"  
  }
}
```

此範例會啟用 Docker 標籤型服務探索。CloudWatch 代理程式將會每 15 秒查詢一次 ECS 任務的中繼資料，然後將已搜索到的目標寫入 CloudWatch 代理程式容器內的 `/tmp/cwagent_ecs_auto_sd.yaml` 檔案中。將掃描帶有 Docker 標籤的容器 `ECS_PROMETHEUS_EXPORTER_PORT_SUBSET_A`。Docker 標籤的值 `ECS_PROMETHEUS_JOB_NAME` 可用作任務名稱。

**範例 3**

```
"ecs_service_discovery": {
  "sd_frequency": "5m",
  "sd_result_file": "/tmp/cwagent_ecs_auto_sd.yaml",
  "task_definition_list": [
    {
      "sd_job_name": "java-prometheus",
      "sd_metrics_path": "/metrics",
      "sd_metrics_ports": "9404; 9406",
      "sd_task_definition_arn_pattern": ".*:task-definition/.*javajmx.*:[0-9]+"
    },
    {
      "sd_job_name": "envoy-prometheus",
      "sd_metrics_path": "/stats/prometheus",
      "sd_container_name_pattern": "^envoy$", 
      "sd_metrics_ports": "9901",
      "sd_task_definition_arn_pattern": ".*:task-definition/.*appmesh.*:23"
    }
  ]
}
```

此範例會啟用 ECS 任務定義 ARN 規則表達式型服務探索。CloudWatch 代理程式將會每 5 分鐘查詢一次 ECS 任務的中繼資料，然後將已搜索到的目標寫入 CloudWatch 代理程式容器內的 `/tmp/cwagent_ecs_auto_sd.yaml` 檔案中。

定義了兩個任務定義 ARN 規則表達式部分：
+  對於第一個區段，會篩選出其 ECS 任務定義 ARN 中具有 `javajmx` 的 ECS 任務，以進行容器連接埠掃描。如果這些 ECS 任務中的容器在 9404 或 9406 上公開容器連接埠，則會使用映射的主機連接埠以及容器的私有 IP 來建立 Prometheus 匯出工具目標。`sd_metrics_path` 的值會將 `__metrics_path__` 設定為 `/metrics`。因此，CloudWatch 代理程式將從 `private_ip:host_port/metrics` 湊集 Prometheus 指標，湊集的指標將會傳送至日誌群組 `/aws/ecs/containerinsights/cluster_name/prometheus` 中的 CloudWatch Logs 的 `java-prometheus` 日誌串流。
+  對於第一個區段，會篩選出其 ECS 任務定義 ARN 中具有 `appmesh` 且 `:23` 的 `version` 的 ECS 任務，以進行容器連接埠掃描。對於名稱為 `envoy` 且在 `9901` 上公開容器連接埠的容器，則會使用映射的主機連接埠以及容器的私有 IP 來建立 Prometheus 匯出工具目標。這些 ECS 任務中的值在 9404 或 9406 上公開容器連接埠，則會使用映射的主機連接埠以及容器的私有 IP 來建立 Prometheus 匯出工具目標。`sd_metrics_path` 的值會將 `__metrics_path__` 設定為 `/stats/prometheus`。因此，CloudWatch 代理程式將從 `private_ip:host_port/stats/prometheus` 湊集 Prometheus 指標，並會將湊集的指標傳送至日誌群組 `/aws/ecs/containerinsights/cluster_name/prometheus` 中的 CloudWatch Logs 的 `envoy-prometheus` 日誌串流。

**範例 4**

```
"ecs_service_discovery": {
  "sd_frequency": "5m",
  "sd_result_file": "/tmp/cwagent_ecs_auto_sd.yaml",
  "service_name_list_for_tasks": [
    {
      "sd_job_name": "nginx-prometheus",
      "sd_metrics_path": "/metrics",
      "sd_metrics_ports": "9113",
      "sd_service_name_pattern": "^nginx-.*"
    },
    {
      "sd_job_name": "haproxy-prometheus",
      "sd_metrics_path": "/stats/metrics",
      "sd_container_name_pattern": "^haproxy$",
      "sd_metrics_ports": "8404",
      "sd_service_name_pattern": ".*haproxy-service.*"
    }
  ]
}
```

此範例會啟用 ECS 服務名稱規則表達式型服務探索。CloudWatch 代理程式將會每 5 分鐘查詢一次 ECS 服務的中繼資料，然後將已搜索到的目標寫入 CloudWatch 代理程式容器內的 `/tmp/cwagent_ecs_auto_sd.yaml` 檔案中。

定義了兩個服務名稱規則表達式區段：
+  對於第一個區段，會篩選出與 ECS 服務相關聯的 ECS 任務，且其名稱符合規則表達式 `^nginx-.*`，以進行容器連接埠掃描。如果這些 ECS 任務中的容器在 9113 上公開容器連接埠，則會使用映射的主機連接埠以及容器的私有 IP 來建立 Prometheus 匯出工具目標。`sd_metrics_path` 的值會將 `__metrics_path__` 設定為 `/metrics`。因此，CloudWatch 代理程式將從 `private_ip:host_port/metrics` 湊集 Prometheus 指標，而湊集的指標將會傳送至日誌群組 `/aws/ecs/containerinsights/cluster_name/prometheus` 中的 CloudWatch Logs 的 `nginx-prometheus` 日誌串流。
+  對於第一個區段，會篩選出與 ECS 服務相關聯的 ECS 任務，且其名稱符合規則表達式 `.*haproxy-service.*`，以進行容器連接埠掃描。對於名稱為 `haproxy` 且在 8404 上公開容器連接埠的容器，則會使用映射的主機連接埠以及容器的私有 IP 來建立 Prometheus 匯出工具目標。`sd_metrics_path` 的值會將 `__metrics_path__` 設定為 `/stats/metrics`。因此，CloudWatch 代理程式將從 `private_ip:host_port/stats/metrics` 湊集 Prometheus 指標，而湊集的指標將會傳送至日誌群組 `/aws/ecs/containerinsights/cluster_name/prometheus` 中的 CloudWatch Logs 的 `haproxy-prometheus` 日誌串流。

**範例 5**

```
"ecs_service_discovery": {
  "sd_frequency": "1m30s",
  "sd_result_file": "/tmp/cwagent_ecs_auto_sd.yaml",
  "docker_label": {
    "sd_port_label": "MY_PROMETHEUS_EXPORTER_PORT_LABEL",
    "sd_metrics_path_label": "MY_PROMETHEUS_METRICS_PATH_LABEL",
    "sd_job_name_label": "MY_PROMETHEUS_METRICS_NAME_LABEL"  
  }
  "task_definition_list": [
    {
      "sd_metrics_ports": "9150",
      "sd_task_definition_arn_pattern": "*memcached.*"
    }
  ]
}
```

此範例會啟用兩種 ECS 服務探索模式。CloudWatch 代理程式將會每 90 秒查詢一次 ECS 任務的中繼資料，然後將已搜索到的目標寫入 CloudWatch 代理程式容器內的 `/tmp/cwagent_ecs_auto_sd.yaml` 檔案中。

若為 Docker 型服務探索組態：
+ 具有 Docker 標籤的 ECS 任務 `MY_PROMETHEUS_EXPORTER_PORT_LABEL` 將被篩選為 Prometheus 連接埠掃描。目標 Prometheus 容器連接埠由標籤 `MY_PROMETHEUS_EXPORTER_PORT_LABEL` 的值指定。
+ Docker 標籤的值 `MY_PROMETHEUS_EXPORTER_PORT_LABEL` 可用於 `__metrics_path__`。如果容器沒有此 Docker 標籤，則會使用預設值 `/metrics`。
+ Docker 標籤的值 `MY_PROMETHEUS_EXPORTER_PORT_LABEL` 可用作任務名稱。如果容器沒有此 Docker 標籤，則會使用 Prometheus 組態中定義的任務名稱。

若為 ECS 任務定義 ARN 規則表達式型服務探索組態：
+ 會篩選出 ECS 任務定義 ARN 中具有 `memcached` 的 ECS 任務，以進行容器連接埠掃描。目標 Prometheus 容器連接埠由 `sd_metrics_ports` 定義為 9150。使用預設指標路徑 `/metrics`。使用 Prometheus 組態中定義的任務名稱。

# (選用) 設定範例容器化 Amazon ECS 工作負載，以進行 Prometheus 指標測試
<a name="ContainerInsights-Prometheus-Sample-Workloads-ECS"></a>

若要測試 CloudWatch Container Insights 中的 Prometheus 指標支援，您可以設定下列一或多個容器化工作負載。具有 Prometheus 支援的 CloudWatch 代理程式會自動從這些工作負載收集指標。若要查看預設收集的指標，請參閱 [CloudWatch 代理程式收集的 Prometheus 指標](ContainerInsights-Prometheus-metrics.md)。

**Topics**
+ [適用於 Amazon ECS 叢集的範例 App Mesh 工作負載](ContainerInsights-Prometheus-Sample-Workloads-ECS-appmesh.md)
+ [適用於 Amazon ECS 叢集的範例 Java/JMX 工作負載](ContainerInsights-Prometheus-Sample-Workloads-ECS-javajmx.md)
+ [適用於 Amazon ECS 叢集的範例 NGINX 工作負載](ContainerInsights-Prometheus-Setup-nginx-ecs.md)
+ [適用於 Amazon ECS 叢集的範例 NGINX Plus 工作負載](ContainerInsights-Prometheus-Setup-nginx-plus-ecs.md)
+ [新增 Prometheus 湊集目標的教學：Amazon ECS 上的 Memcached](ContainerInsights-Prometheus-Setup-memcached-ecs.md)
+ [在 Amazon ECS Fargate 上抓取 Redis OSS Prometheus 指標的教學課程](ContainerInsights-Prometheus-Setup-redis-ecs.md)

# 適用於 Amazon ECS 叢集的範例 App Mesh 工作負載
<a name="ContainerInsights-Prometheus-Sample-Workloads-ECS-appmesh"></a>

若要從 Amazon ECS 的範例 Prometheus 工作負載收集指標，您必須在叢集中執行 Container Insights。如需安裝 Container Insights 的相關資訊，請參閱 [在 Amazon ECS 上設定 Container Insights](deploy-container-insights-ECS.md)。

首先，按照這個[演練](https://github.com/aws/aws-app-mesh-examples/tree/main/examples/apps/colorapp#app-mesh-walkthrough-deploy-the-color-app-on-ecs)在 Amazon ECS 叢集上部署範例色彩應用程式。完成後，您將在連接埠 9901 上公開 App Mesh Prometheus 指標。

接下來，請依照下列步驟，在安裝彩色應用程式的相同 Amazon ECS 叢集上安裝具有 Prometheus 監控的 CloudWatch 代理程式。本節中的步驟會以橋接網路模式安裝 CloudWatch 代理程式。

下列步驟也將使用您在演練中設定的環境變數 `ENVIRONMENT_NAME`、`AWS_PROFILE` 以及 `AWS_DEFAULT_REGION`。

**若要安裝具有 Prometheus 監控的 CloudWatch 代理程式以進行測試**

1. 輸入下列命令來下載 CloudFormation 範本。

   ```
   curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/replica-service/cwagent-prometheus/cloudformation-quickstart/cwagent-ecs-prometheus-metric-for-bridge-host.yaml
   ```

1. 輸入下列命令，設定網路模式。

   ```
   export ECS_CLUSTER_NAME=${ENVIRONMENT_NAME}
   export ECS_NETWORK_MODE=bridge
   ```

1. 輸入下列命令來建立 CloudFormation 堆疊。

   ```
   aws cloudformation create-stack --stack-name CWAgent-Prometheus-ECS-${ECS_CLUSTER_NAME}-EC2-${ECS_NETWORK_MODE} \
       --template-body file://cwagent-ecs-prometheus-metric-for-bridge-host.yaml \
       --parameters ParameterKey=ECSClusterName,ParameterValue=${ECS_CLUSTER_NAME} \
                    ParameterKey=CreateIAMRoles,ParameterValue=True \
                    ParameterKey=ECSNetworkMode,ParameterValue=${ECS_NETWORK_MODE} \
                    ParameterKey=TaskRoleName,ParameterValue=CWAgent-Prometheus-TaskRole-${ECS_CLUSTER_NAME} \
                    ParameterKey=ExecutionRoleName,ParameterValue=CWAgent-Prometheus-ExecutionRole-${ECS_CLUSTER_NAME} \
       --capabilities CAPABILITY_NAMED_IAM \
       --region ${AWS_DEFAULT_REGION} \
       --profile ${AWS_PROFILE}
   ```

1. （選用） 建立 CloudFormation 堆疊時，您會看到`CREATE_COMPLETE`訊息。如果您要在看到訊息之前檢查狀態，請輸入下列命令。

   ```
   aws cloudformation describe-stacks \
   --stack-name CWAgent-Prometheus-ECS-${ECS_CLUSTER_NAME}-EC2-${ECS_NETWORK_MODE} \
   --query 'Stacks[0].StackStatus' \
   --region ${AWS_DEFAULT_REGION} \
   --profile ${AWS_PROFILE}
   ```

**疑難排解**

演練中的步驟會使用 jq 來剖析 AWS CLI的輸出結果。如需安裝 jq 的詳細資訊，請參閱 [jq](https://stedolan.github.io/jq/)。使用下列命令，將您 AWS CLI 的預設輸出格式設定為 JSON，以便 jq 可以正確進行剖析。

```
$ aws configure
```

當回應變為 `Default output format` 時，輸入 **json**。

## 解除安裝具有 Prometheus 監控的 CloudWatch 代理程式
<a name="ContainerInsights-Prometheus-Sample-Workloads-ECS-appmesh-uninstall"></a>

完成測試後，請輸入下列命令，透過刪除 CloudFormation 堆疊來解除安裝 CloudWatch 代理程式。

```
aws cloudformation delete-stack \
--stack-name CWAgent-Prometheus-ECS-${ECS_CLUSTER_NAME}-EC2-${ECS_NETWORK_MODE} \
--region ${AWS_DEFAULT_REGION} \
--profile ${AWS_PROFILE}
```

# 適用於 Amazon ECS 叢集的範例 Java/JMX 工作負載
<a name="ContainerInsights-Prometheus-Sample-Workloads-ECS-javajmx"></a>

JMX Exporter 是官方的 Prometheus 匯出工具，可以湊集 JMX mBeans 並將其公開為 Prometheus 指標。如需詳細資訊，請參閱 [prometheus/jmx\$1exporter](https://github.com/prometheus/jmx_exporter)。

具有 Prometheus 支援的 CloudWatch 代理程式會根據 Amazon ECS 叢集中的服務探索組態來湊集 Java/JMX Prometheus 指標。您可以設定 JMX Exporter 在不同的連接埠或 metrics\$1path 上公開指標。如果您確實變更連接埠或路徑，請更新 CloudWatch 代理程式組態中的預設 `ecs_service_discovery` 區段。

若要從 Amazon ECS 的範例 Prometheus 工作負載收集指標，您必須在叢集中執行 Container Insights。如需安裝 Container Insights 的相關資訊，請參閱 [在 Amazon ECS 上設定 Container Insights](deploy-container-insights-ECS.md)。

**若要安裝適用於 Amazon ECS 叢集的 Java/JMX 範例工作負載**

1. 請依照這些章節中的步驟建立 Docker 影像。
   + [範例：具有 Prometheus 指標的 Java Jar 應用程式 Docker 影像](ContainerInsights-Prometheus-Sample-Workloads-javajmx.md#ContainerInsights-Prometheus-Sample-Workloads-javajmx-jar)
   + [範例：具有 Prometheus 指標的 Apache Tomcat Docker 影像](ContainerInsights-Prometheus-Sample-Workloads-javajmx.md#ContainerInsights-Prometheus-Sample-Workloads-javajmx-tomcat)

1. 在 Amazon ECS 任務定義檔案中指定以下兩個 Docker 標籤。然後，您可以在叢集中以 Amazon ECS 服務或 Amazon ECS 任務的形式執行任務定義。
   + 將 `ECS_PROMETHEUS_EXPORTER_PORT` 設定為指向公開 Prometheus 指標的 containerPort。
   + 將 `Java_EMF_Metrics` 設定為 `true`。CloudWatch 代理程式會使用此旗標在日誌事件中產生內嵌指標格式。

   以下是範例：

   ```
   {
     "family": "workload-java-ec2-bridge",
     "taskRoleArn": "{{task-role-arn}}",
     "executionRoleArn": "{{execution-role-arn}}",
     "networkMode": "bridge",
     "containerDefinitions": [
       {
         "name": "tomcat-prometheus-workload-java-ec2-bridge-dynamic-port",
         "image": "your_docker_image_tag_for_tomcat_with_prometheus_metrics",
         "portMappings": [
           {
             "hostPort": 0,
             "protocol": "tcp",
             "containerPort": 9404
           }
         ],
         "dockerLabels": {
           "ECS_PROMETHEUS_EXPORTER_PORT": "9404",
           "Java_EMF_Metrics": "true"
         }
       }
     ],
     "requiresCompatibilities": [
       "EC2"  ],
     "cpu": "256",
     "memory": "512"
     }
   ```

 CloudFormation 範本中 CloudWatch 代理程式的預設設定可同時啟用 Docker 標籤型服務探索和任務定義 ARN 型服務探索。若要檢視這些預設設定，請參閱[ CloudWatch 代理程式 YAML 組態檔案](https://github.com/aws-samples/amazon-cloudwatch-container-insights/blob/latest/ecs-task-definition-templates/deployment-mode/replica-service/cwagent-prometheus/cloudformation-quickstart/cwagent-ecs-prometheus-metric-for-bridge-host.yaml#L65)的第 65 行。將根據 Prometheus 湊集的指定容器連接埠自動探索具有 `ECS_PROMETHEUS_EXPORTER_PORT` 標籤的容器。

CloudWatch 代理程式的預設設定在同一個檔案的第 112 行也具有針對 Java/JMX 的 `metric_declaration` 設定。目標容器的所有 Docker 標籤將會新增為 Prometheus 指標中的其他標籤，並傳送至 CloudWatch Logs。對於帶有 Docker 標籤的 Java/JMX 容器 `Java_EMF_Metrics=“true”`，會產生內嵌指標格式。

# 適用於 Amazon ECS 叢集的範例 NGINX 工作負載
<a name="ContainerInsights-Prometheus-Setup-nginx-ecs"></a>

NGINX Prometheus 匯出工具可以湊集和公開 NGINX 資料作為 Prometheus 指標。此範例會聯合使用匯出工具與 Amazon ECS 的 NGINX 反向代理服務。

如需有關 NGINX Prometheus 匯出工具的詳細資訊，請參閱 Github 上的[ nginx-prometheus-exporter](https://github.com/nginxinc/nginx-prometheus-exporter)。如需有關 NGINX 反向代理的詳細資訊，請參閱 Github 上的 [ ecs-nginx-reverse-proxy](https://github.com/awslabs/ecs-nginx-reverse-proxy)。

具有 Prometheus 支援的 CloudWatch 代理程式會根據 Amazon ECS 叢集中的服務探索組態來湊集 NGINX Prometheus 指標。您可以設定 NGINX Prometheus Exporter 在不同的連接埠或路徑上公開指標。如果您變更連接埠或路徑，請更新 CloudWatch 代理程式組態檔案中的 `ecs_service_discovery` 區段。

## 安裝適用於 Amazon ECS 叢集的 NGINX 反向代理範例工作負載
<a name="ContainerInsights-Prometheus-nginx-ecs-setup"></a>

請遵循這些步驟，安裝 NGINX 反向代理範例工作負載。

### 建立 Docker 影像
<a name="ContainerInsights-Prometheus-nginx-ecs-setup-docker"></a>

**若要為 NGINX 反向代理範例工作負載建立 Docker 影像**

1. 從 NGINX 反向代理儲存庫下載下列資料夾：[https://github.com/awslabs/ecs-nginx-reverse-proxy/tree/master/reverse-proxy/](https://github.com/awslabs/ecs-nginx-reverse-proxy/tree/master/reverse-proxy/)。

1. 尋找 `app` 目錄並從該目錄建置一個映像：

   ```
   docker build -t web-server-app ./path-to-app-directory
   ```

1. 為 NGINX 建置一個自訂映像。首先，建立一個具有以下兩個檔案的目錄：
   + 一個範例 Dockerfile：

     ```
     FROM nginx
     COPY nginx.conf /etc/nginx/nginx.conf
     ```
   + 一個修改自 [ https://github.com/awslabs/ecs-nginx-reverse-proxy/tree/master/reverse-proxy/](https://github.com/awslabs/ecs-nginx-reverse-proxy/tree/master/reverse-proxy/) 的 `nginx.conf` 檔案：

     ```
     events {
       worker_connections 768;
     }
     
     http {
       # Nginx will handle gzip compression of responses from the app server
       gzip on;
       gzip_proxied any;
       gzip_types text/plain application/json;
       gzip_min_length 1000;
     
       server{
         listen 8080;
         location /stub_status {
             stub_status   on;
         }
       }
     
       server {
         listen 80;
     
         # Nginx will reject anything not matching /api
         location /api {
           # Reject requests with unsupported HTTP method
           if ($request_method !~ ^(GET|POST|HEAD|OPTIONS|PUT|DELETE)$) {
             return 405;
           }
     
           # Only requests matching the whitelist expectations will
           # get sent to the application server
           proxy_pass http://app:3000;
           proxy_http_version 1.1;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection 'upgrade';
           proxy_set_header Host $host;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_cache_bypass $http_upgrade;
         }
       }
     }
     ```
**注意**  
必須在 `nginx-prometheus-exporter` 設定為從中湊集指標的相同連接埠啟用 `stub_status`。在我們的範例任務定義中，將 `nginx-prometheus-exporter` 設定為從連接埠 8080 湊集指標。

1. 從新目錄中的檔案建置映像：

   ```
   docker build -t nginx-reverse-proxy ./path-to-your-directory
   ```

1. 將您的新映像上傳至映像儲存庫以供日後使用。

### 建立任務定義，以在 Amazon ECS 中執行 NGINX 和 Web 伺服器應用程式
<a name="ContainerInsights-Prometheus-nginx-ecs-setup-task"></a>

接著，設定任務定義。

此任務定義可以啟用 NGINX Prometheus 指標的收集與匯出。NGINX 容器會追蹤應用程式的輸入，並將該資料公開到連接埠 8080，如 `nginx.conf` 中所設定。NGINX Prometheus 匯出工具容器會湊集這些指標，並將它們發佈到連接埠 9113，以便在 CloudWatch 中使用。

**若要設定 NGINX 範例 Amazon ECS 工作負載的任務定義**

1. 使用以下內容，建立名為任務定義 JSON 檔案。將 *your-customized-nginx-iamge* 取代為您自訂 NGINX 映像的映像 URI，並將 *your-web-server-app-image* 取代為您 Web 伺服器應用程式映像的映像 URI。

   ```
   {
     "containerDefinitions": [
       {
         "name": "nginx",
         "image": "your-customized-nginx-image",
         "memory": 256,
         "cpu": 256,
         "essential": true,
         "portMappings": [
           {
             "containerPort": 80,
             "protocol": "tcp"
           }
         ],
         "links": [
           "app"
         ]
       },
       {
         "name": "app",
         "image": "your-web-server-app-image",
         "memory": 256,
         "cpu": 256,
         "essential": true
       },
       {
         "name": "nginx-prometheus-exporter",
         "image": "docker.io/nginx/nginx-prometheus-exporter:0.8.0",
         "memory": 256,
         "cpu": 256,
         "essential": true,
         "command": [
           "-nginx.scrape-uri",
           "http://nginx:8080/stub_status"
       ],
       "links":[
         "nginx"
       ],
         "portMappings":[
           {
             "containerPort": 9113,
             "protocol": "tcp"
           }
         ]
       }
     ],
     "networkMode": "bridge",
     "placementConstraints": [],
     "family": "nginx-sample-stack"
   }
   ```

1. 透過輸入以下命令，註冊任務定義。

   ```
   aws ecs register-task-definition --cli-input-json file://path-to-your-task-definition-json
   ```

1. 透過輸入以下命令，建立服務以執行任務：

   請務必不要變更服務名稱。我們將使用組態來執行 CloudWatch 代理程式服務，而該組態會使用啟動這些服務的名稱模式來搜尋任務。例如，若要讓 CloudWatch 代理程式尋找由此命令啟動的任務，您可以將 `sd_service_name_pattern` 的值指定為 `^nginx-service$`。下一節將提供更多詳細資訊。

   ```
   aws ecs create-service \
    --cluster your-cluster-name \
    --service-name nginx-service \
    --task-definition nginx-sample-stack:1 \
    --desired-count 1
   ```

### 設定 CloudWatch 代理程式以湊集 NGINX Prometheus 指標
<a name="ContainerInsights-Prometheus-nginx-ecs-setup-agent"></a>

最後一步是設定 CloudWatch 代理程序以湊集 NGINX 指標。在此範例中，CloudWatch 代理程式會透過服務名稱模式探索任務，而連接埠 9113 (匯出公式會公開 NGINX 的 Prometheus 指標)。在探索任務和可用指標之後，CloudWatch 代理程式會開始將收集的指標張貼至記錄串流 **nginx-prometheus-exporter**。

**若要設定 CloudWatch 代理程式以湊集 NGINX 指標**

1. 輸入下列命令，以下載最新版本的必要 YAML 檔案。

   ```
   curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/replica-service/cwagent-prometheus/cloudformation-quickstart/cwagent-ecs-prometheus-metric-for-bridge-host.yaml
   ```

1. 使用文字編輯器開啟檔案，然後在 `resource:CWAgentConfigSSMParameter` 區段中的 `value` 金鑰查找完整的 CloudWatch 代理程式組態。然後，在 `ecs_service_discovery` 區段中，新增下列 `service_name_list_for_tasks` 區段。

   ```
   "service_name_list_for_tasks": [
     {
       "sd_job_name": "nginx-prometheus-exporter",
       "sd_metrics_path": "/metrics",
       "sd_metrics_ports": "9113",
       "sd_service_name_pattern": "^nginx-service$"
      }
   ],
   ```

1. 在相同的檔案中，在 `metric_declaration` 區段中新增以下區段，以允許 NGINX 指標。請務必遵循現有的縮排模式。

   ```
   {
     "source_labels": ["job"],
     "label_matcher": ".*nginx.*",
     "dimensions": [["ClusterName", "TaskDefinitionFamily", "ServiceName"]],
     "metric_selectors": [
       "^nginx_.*$"
     ]
   },
   ```

1. 如果您尚未在此叢集中部署 CloudWatch 代理程式，請跳至步驟 8。

   如果您已經透過使用 AWS CloudFormation，在 Amazon ECS 叢集中部署了 CloudWatch 代理程式，則您可以輸入下列指令來建立變更集：

   ```
   ECS_CLUSTER_NAME=your_cluster_name
   AWS_REGION=your_aws_region
   ECS_NETWORK_MODE=bridge
   CREATE_IAM_ROLES=True
   ECS_TASK_ROLE_NAME=your_selected_ecs_task_role_name
   ECS_EXECUTION_ROLE_NAME=your_selected_ecs_execution_role_name
   
   aws cloudformation create-change-set --stack-name CWAgent-Prometheus-ECS-${ECS_CLUSTER_NAME}-EC2-${ECS_NETWORK_MODE} \
       --template-body file://cwagent-ecs-prometheus-metric-for-bridge-host.yaml \
       --parameters ParameterKey=ECSClusterName,ParameterValue=$ECS_CLUSTER_NAME \
                    ParameterKey=CreateIAMRoles,ParameterValue=$CREATE_IAM_ROLES \
                    ParameterKey=ECSNetworkMode,ParameterValue=$ECS_NETWORK_MODE \
                    ParameterKey=TaskRoleName,ParameterValue=$ECS_TASK_ROLE_NAME \
                    ParameterKey=ExecutionRoleName,ParameterValue=$ECS_EXECUTION_ROLE_NAME \
       --capabilities CAPABILITY_NAMED_IAM \
       --region $AWS_REGION \
       --change-set-name nginx-scraping-support
   ```

1. 在 https：//[https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/) 開啟 CloudFormation 主控台。

1. 檢閱新建立的變更集 **nginx-scraping-support**。您應該會看到一個可套用至 **CWAgentConfigSSMParameter** 資源的變更。輸入下列命令以執行變更集，然後重新啟動 CloudWatch 代理程式任務：

   ```
   aws ecs update-service --cluster $ECS_CLUSTER_NAME \
   --desired-count 0 \
   --service cwagent-prometheus-replica-service-EC2-$ECS_NETWORK_MODE \
   --region $AWS_REGION
   ```

1. 請等候約 10 秒鐘，然後輸入下列命令。

   ```
   aws ecs update-service --cluster $ECS_CLUSTER_NAME \
   --desired-count 1 \
   --service cwagent-prometheus-replica-service-EC2-$ECS_NETWORK_MODE \
   --region $AWS_REGION
   ```

1. 如果您是第一次在叢集上安裝具有 Prometheus 指標收集的 CloudWatch 代理程式，請輸入下列命令。

   ```
   ECS_CLUSTER_NAME=your_cluster_name
   AWS_REGION=your_aws_region
   ECS_NETWORK_MODE=bridge
   CREATE_IAM_ROLES=True
   ECS_TASK_ROLE_NAME=your_selected_ecs_task_role_name
   ECS_EXECUTION_ROLE_NAME=your_selected_ecs_execution_role_name
   
   aws cloudformation create-stack --stack-name CWAgent-Prometheus-ECS-${ECS_CLUSTER_NAME}-EC2-${ECS_NETWORK_MODE} \
       --template-body file://cwagent-ecs-prometheus-metric-for-bridge-host.yaml \
       --parameters ParameterKey=ECSClusterName,ParameterValue=$ECS_CLUSTER_NAME \
                    ParameterKey=CreateIAMRoles,ParameterValue=$CREATE_IAM_ROLES \
                    ParameterKey=ECSNetworkMode,ParameterValue=$ECS_NETWORK_MODE \
                    ParameterKey=TaskRoleName,ParameterValue=$ECS_TASK_ROLE_NAME \
                    ParameterKey=ExecutionRoleName,ParameterValue=$ECS_EXECUTION_ROLE_NAME \
       --capabilities CAPABILITY_NAMED_IAM \
       --region $AWS_REGION
   ```

## 檢視您的 NGINX 指標和日誌
<a name="ContainerInsights-Prometheus-Setup-nginx-view"></a>

您現在可以檢視收集的 NGINX 指標。

**若要檢視範例 NGINX 工作負載的指標**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在執行叢集的區域中，在左側的導覽窗格中選擇 **Metrics** (指標)。尋找 **ContainerInsights/Prometheus** 命名空間來查看指標。

1. 若要查看 CloudWatch Logs 事件，請在導覽窗格中選擇 **Log groups** (日誌群組)。事件位於日誌串流 *nginx-prometheus-exporter* 中的日誌群組 **/aws/containerinsights/*your\$1cluster\$1name*/prometheus** 中。

# 適用於 Amazon ECS 叢集的範例 NGINX Plus 工作負載
<a name="ContainerInsights-Prometheus-Setup-nginx-plus-ecs"></a>

NGINX Plus 是 NGINX 的商用版本。您必須擁有授權才能使用。如需詳細資訊，請參閱 [NGINX Plus](https://www.nginx.com/products/nginx/)

NGINX Prometheus 匯出工具可以湊集和公開 NGINX 資料作為 Prometheus 指標。此範例會聯合使用匯出工具與 Amazon ECS 的 NGINX Plus 反向代理服務。

如需有關 NGINX Prometheus 匯出工具的詳細資訊，請參閱 Github 上的[ nginx-prometheus-exporter](https://github.com/nginxinc/nginx-prometheus-exporter)。如需有關 NGINX 反向代理的詳細資訊，請參閱 Github 上的 [ ecs-nginx-reverse-proxy](https://github.com/awslabs/ecs-nginx-reverse-proxy)。

具有 Prometheus 支援的 CloudWatch 代理程式會根據 Amazon ECS 叢集中的服務探索組態來湊集 NGINX Plus Prometheus 指標。您可以設定 NGINX Prometheus Exporter 在不同的連接埠或路徑上公開指標。如果您變更連接埠或路徑，請更新 CloudWatch 代理程式組態檔案中的 `ecs_service_discovery` 區段。

## 安裝適用於 Amazon ECS 叢集的 NGINX Plus 反向代理範例工作負載
<a name="ContainerInsights-Prometheus-nginx-plus-ecs-setup"></a>

請遵循這些步驟，安裝 NGINX 反向代理範例工作負載。

### 建立 Docker 影像
<a name="ContainerInsights-Prometheus-nginx-plus-ecs-setup-docker"></a>

**若要為 NGINX Plus 反向代理範例工作負載建立 Docker 影像**

1. 從 NGINX 反向代理儲存庫下載下列資料夾：[https://github.com/awslabs/ecs-nginx-reverse-proxy/tree/master/reverse-proxy/](https://github.com/awslabs/ecs-nginx-reverse-proxy/tree/master/reverse-proxy/)。

1. 尋找 `app` 目錄並從該目錄建置一個映像：

   ```
   docker build -t web-server-app ./path-to-app-directory
   ```

1. 為 NGINX Plus 建置一個自訂映像。在為 NGINX Plus 建置映像之前，您需要為您授權的 NGINX Plus 獲取名為 `nginx-repo.key` 的金鑰和 SSL 憑證 `nginx-repo.crt`。建立目錄，並將您的 `nginx-repo.key` 和 `nginx-repo.crt` 檔案存放於其中。

   在您剛才建立的目錄中，建立下列兩個檔案：
   + 含有下列內容的範例 Dockerfile。該 Docker 檔案採用自提供的範例檔案：[https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-docker/\$1docker\$1plus\$1image](https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-docker/#docker_plus_image)。我們做出的重要變更是我們會載入一個名為 `nginx.conf` 的單獨檔案，而該檔案將在下一個步驟中建立。

     ```
     FROM debian:buster-slim
     
     LABEL maintainer="NGINX Docker Maintainers <docker-maint@nginx.com>“
     
     # Define NGINX versions for NGINX Plus and NGINX Plus modules
     # Uncomment this block and the versioned nginxPackages block in the main RUN
     # instruction to install a specific release
     # ENV NGINX_VERSION 21
     # ENV NJS_VERSION 0.3.9
     # ENV PKG_RELEASE 1~buster
     
     # Download certificate and key from the customer portal (https://cs.nginx.com (https://cs.nginx.com/))
     # and copy to the build context
     COPY nginx-repo.crt /etc/ssl/nginx/
     COPY nginx-repo.key /etc/ssl/nginx/
     # COPY nginx.conf /etc/ssl/nginx/nginx.conf
     
     RUN set -x \
     # Create nginx user/group first, to be consistent throughout Docker variants
     && addgroup --system --gid 101 nginx \
     && adduser --system --disabled-login --ingroup nginx --no-create-home --home /nonexistent --gecos "nginx user" --shell /bin/false --uid 101 nginx \
     && apt-get update \
     && apt-get install --no-install-recommends --no-install-suggests -y ca-certificates gnupg1 \
     && \
     NGINX_GPGKEY=573BFD6B3D8FBC641079A6ABABF5BD827BD9BF62; \
     found=''; \
     for server in \
     ha.pool.sks-keyservers.net (http://ha.pool.sks-keyservers.net/) \
     hkp://keyserver.ubuntu.com:80 \
     hkp://p80.pool.sks-keyservers.net:80 \
     pgp.mit.edu (http://pgp.mit.edu/) \
     ; do \
     echo "Fetching GPG key $NGINX_GPGKEY from $server"; \
     apt-key adv --keyserver "$server" --keyserver-options timeout=10 --recv-keys "$NGINX_GPGKEY" && found=yes && break; \
     done; \
     test -z "$found" && echo >&2 "error: failed to fetch GPG key $NGINX_GPGKEY" && exit 1; \
     apt-get remove --purge --auto-remove -y gnupg1 && rm -rf /var/lib/apt/lists/* \
     # Install the latest release of NGINX Plus and/or NGINX Plus modules
     # Uncomment individual modules if necessary
     # Use versioned packages over defaults to specify a release
     && nginxPackages=" \
     nginx-plus \
     # nginx-plus=${NGINX_VERSION}-${PKG_RELEASE} \
     # nginx-plus-module-xslt \
     # nginx-plus-module-xslt=${NGINX_VERSION}-${PKG_RELEASE} \
     # nginx-plus-module-geoip \
     # nginx-plus-module-geoip=${NGINX_VERSION}-${PKG_RELEASE} \
     # nginx-plus-module-image-filter \
     # nginx-plus-module-image-filter=${NGINX_VERSION}-${PKG_RELEASE} \
     # nginx-plus-module-perl \
     # nginx-plus-module-perl=${NGINX_VERSION}-${PKG_RELEASE} \
     # nginx-plus-module-njs \
     # nginx-plus-module-njs=${NGINX_VERSION}+${NJS_VERSION}-${PKG_RELEASE} \
     " \
     && echo "Acquire::https::plus-pkgs.nginx.com::Verify-Peer \"true\";" >> /etc/apt/apt.conf.d/90nginx \
     && echo "Acquire::https::plus-pkgs.nginx.com::Verify-Host \"true\";" >> /etc/apt/apt.conf.d/90nginx \
     && echo "Acquire::https::plus-pkgs.nginx.com::SslCert \"/etc/ssl/nginx/nginx-repo.crt\";" >> /etc/apt/apt.conf.d/90nginx \
     && echo "Acquire::https::plus-pkgs.nginx.com::SslKey \"/etc/ssl/nginx/nginx-repo.key\";" >> /etc/apt/apt.conf.d/90nginx \
     && printf "deb https://plus-pkgs.nginx.com/debian buster nginx-plus\n" > /etc/apt/sources.list.d/nginx-plus.list \
     && apt-get update \
     && apt-get install --no-install-recommends --no-install-suggests -y \
     $nginxPackages \
     gettext-base \
     curl \
     && apt-get remove --purge --auto-remove -y && rm -rf /var/lib/apt/lists/* /etc/apt/sources.list.d/nginx-plus.list \
     && rm -rf /etc/apt/apt.conf.d/90nginx /etc/ssl/nginx
     
     # Forward request logs to Docker log collector
     RUN ln -sf /dev/stdout /var/log/nginx/access.log \
     && ln -sf /dev/stderr /var/log/nginx/error.log
     
     COPY nginx.conf /etc/nginx/nginx.conf
     
     EXPOSE 80
     
     STOPSIGNAL SIGTERM
     
     CMD ["nginx", "-g", "daemon off;"]
     ```
   + 一個修改自 [ https://github.com/awslabs/ecs-nginx-reverse-proxy/tree/master/reverse-proxy/nginx](https://github.com/awslabs/ecs-nginx-reverse-proxy/tree/master/reverse-proxy/nginx) 的 `nginx.conf` 檔案。

     ```
     events {
       worker_connections 768;
     }
     
     http {
       # Nginx will handle gzip compression of responses from the app server
       gzip on;
       gzip_proxied any;
       gzip_types text/plain application/json;
       gzip_min_length 1000;
     
       upstream backend {
         zone name 10m;
         server app:3000    weight=2;
         server app2:3000    weight=1;
       }
     
       server{
         listen 8080;
         location /api {
           api write=on;
         }
       }
     
       match server_ok {
         status 100-599;
       }
     
       server {
         listen 80;
         status_zone zone;
         # Nginx will reject anything not matching /api
         location /api {
           # Reject requests with unsupported HTTP method
           if ($request_method !~ ^(GET|POST|HEAD|OPTIONS|PUT|DELETE)$) {
             return 405;
           }
     
           # Only requests matching the whitelist expectations will
           # get sent to the application server
           proxy_pass http://backend;
           health_check uri=/lorem-ipsum match=server_ok;
           proxy_http_version 1.1;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection 'upgrade';
           proxy_set_header Host $host;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_cache_bypass $http_upgrade;
         }
       }
     }
     ```

1. 從新目錄中的檔案建置映像：

   ```
   docker build -t nginx-plus-reverse-proxy ./path-to-your-directory
   ```

1. 將您的新映像上傳至映像儲存庫以供日後使用。

### 建立任務定義，以在 Amazon ECS 中執行 NGINX Plus 和 Web 伺服器應用程式
<a name="ContainerInsights-Prometheus-nginx-plus-ecs-setup-task"></a>

接著，設定任務定義。

此任務定義可以啟用 NGINX Plus Prometheus 指標的收集與匯出。NGINX 容器會追蹤應用程式的輸入，並將該資料公開到連接埠 8080，如 `nginx.conf` 中所設定。NGINX Prometheus 匯出工具容器會湊集這些指標，並將它們發佈到連接埠 9113，以便在 CloudWatch 中使用。

**若要設定 NGINX 範例 Amazon ECS 工作負載的任務定義**

1. 使用以下內容，建立名為任務定義 JSON 檔案。將 *your-customized-nginx-plus-image* 取代為您自訂 NGINX Plus 映像的映像 URI，並將 *your-web-server-app-image* 取代為您 Web 伺服器應用程式映像的映像 URI。

   ```
   {
     "containerDefinitions": [
       {
         "name": "nginx",
         "image": "your-customized-nginx-plus-image",
         "memory": 256,
         "cpu": 256,
         "essential": true,
         "portMappings": [
           {
             "containerPort": 80,
             "protocol": "tcp"
           }
         ],
         "links": [
           "app",
           "app2"
         ]
       },
       {
         "name": "app",
         "image": "your-web-server-app-image",
         "memory": 256,
         "cpu": 128,
         "essential": true
       },
       {
         "name": "app2",
         "image": "your-web-server-app-image",
         "memory": 256,
         "cpu": 128,
         "essential": true
       },
       {
         "name": "nginx-prometheus-exporter",
         "image": "docker.io/nginx/nginx-prometheus-exporter:0.8.0",
         "memory": 256,
         "cpu": 256,
         "essential": true,
         "command": [
           "-nginx.plus",
           "-nginx.scrape-uri",
            "http://nginx:8080/api"
       ],
       "links":[
         "nginx"
       ],
         "portMappings":[
           {
             "containerPort": 9113,
             "protocol": "tcp"
           }
         ]
       }
     ],
     "networkMode": "bridge",
     "placementConstraints": [],
     "family": "nginx-plus-sample-stack"
   }
   ```

1. 註冊任務定義：

   ```
   aws ecs register-task-definition --cli-input-json file://path-to-your-task-definition-json
   ```

1. 透過輸入以下命令，建立服務以執行任務：

   ```
   aws ecs create-service \
    --cluster your-cluster-name \
    --service-name nginx-plus-service \
    --task-definition nginx-plus-sample-stack:1 \
    --desired-count 1
   ```

   請務必不要變更服務名稱。我們將使用組態來執行 CloudWatch 代理程式服務，而該組態會使用啟動這些服務的名稱模式來搜尋任務。例如，若要讓 CloudWatch 代理程式尋找由此命令啟動的任務，您可以將 `sd_service_name_pattern` 的值指定為 `^nginx-plus-service$`。下一節將提供更多詳細資訊。

### 設定 CloudWatch 代理程式以湊集 NGINX Plus Prometheus 指標
<a name="ContainerInsights-Prometheus-nginx-plus-ecs-setup-agent"></a>

最後一步是設定 CloudWatch 代理程序以湊集 NGINX 指標。在此範例中，CloudWatch 代理程式會透過服務名稱模式探索任務，而連接埠 9113 (匯出公式會公開 NGINX 的 Prometheus 指標)。在探索任務和可用指標之後，CloudWatch 代理程式會開始將收集的指標張貼至記錄串流 **nginx-prometheus-exporter**。

**若要設定 CloudWatch 代理程式以湊集 NGINX 指標**

1. 輸入下列命令，以下載最新版本的必要 YAML 檔案。

   ```
   curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/replica-service/cwagent-prometheus/cloudformation-quickstart/cwagent-ecs-prometheus-metric-for-bridge-host.yaml
   ```

1. 使用文字編輯器開啟檔案，然後在 `resource:CWAgentConfigSSMParameter` 區段中的 `value` 金鑰查找完整的 CloudWatch 代理程式組態。然後，在 `ecs_service_discovery` 區段中，新增下列 `service_name_list_for_tasks` 區段。

   ```
   "service_name_list_for_tasks": [
     {
       "sd_job_name": "nginx-plus-prometheus-exporter",
       "sd_metrics_path": "/metrics",
       "sd_metrics_ports": "9113",
       "sd_service_name_pattern": "^nginx-plus.*"
      }
   ],
   ```

1. 在相同的檔案中，在 `metric_declaration` 區段中新增以下區段，以允許 NGINX Plus 指標。請務必遵循現有的縮排模式。

   ```
   {
     "source_labels": ["job"],
     "label_matcher": "^nginx-plus.*",
     "dimensions": [["ClusterName", "TaskDefinitionFamily", "ServiceName"]],
     "metric_selectors": [
       "^nginxplus_connections_accepted$",
       "^nginxplus_connections_active$",
       "^nginxplus_connections_dropped$",
       "^nginxplus_connections_idle$",
       "^nginxplus_http_requests_total$",
       "^nginxplus_ssl_handshakes$",
       "^nginxplus_ssl_handshakes_failed$",
       "^nginxplus_up$",
       "^nginxplus_upstream_server_health_checks_fails$"
     ]
   },
   {
     "source_labels": ["job"],
     "label_matcher": "^nginx-plus.*",
     "dimensions": [["ClusterName", "TaskDefinitionFamily", "ServiceName", "upstream"]],
     "metric_selectors": [
       "^nginxplus_upstream_server_response_time$"
     ]
   },
   {
     "source_labels": ["job"],
     "label_matcher": "^nginx-plus.*",
     "dimensions": [["ClusterName", "TaskDefinitionFamily", "ServiceName", "code"]],
     "metric_selectors": [
       "^nginxplus_upstream_server_responses$",
       "^nginxplus_server_zone_responses$"
     ]
   },
   ```

1. 如果您尚未在此叢集中部署 CloudWatch 代理程式，請跳至步驟 8。

   如果您已經透過使用 AWS CloudFormation，在 Amazon ECS 叢集中部署了 CloudWatch 代理程式，則您可以輸入下列指令來建立變更集：

   ```
   ECS_CLUSTER_NAME=your_cluster_name
   AWS_REGION=your_aws_region
   ECS_NETWORK_MODE=bridge
   CREATE_IAM_ROLES=True
   ECS_TASK_ROLE_NAME=your_selected_ecs_task_role_name
   ECS_EXECUTION_ROLE_NAME=your_selected_ecs_execution_role_name
   
   aws cloudformation create-change-set --stack-name CWAgent-Prometheus-ECS-${ECS_CLUSTER_NAME}-EC2-${ECS_NETWORK_MODE} \
       --template-body file://cwagent-ecs-prometheus-metric-for-bridge-host.yaml \
       --parameters ParameterKey=ECSClusterName,ParameterValue=$ECS_CLUSTER_NAME \
                    ParameterKey=CreateIAMRoles,ParameterValue=$CREATE_IAM_ROLES \
                    ParameterKey=ECSNetworkMode,ParameterValue=$ECS_NETWORK_MODE \
                    ParameterKey=TaskRoleName,ParameterValue=$ECS_TASK_ROLE_NAME \
                    ParameterKey=ExecutionRoleName,ParameterValue=$ECS_EXECUTION_ROLE_NAME \
       --capabilities CAPABILITY_NAMED_IAM \
       --region $AWS_REGION \
       --change-set-name nginx-plus-scraping-support
   ```

1. 在 https：//[https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/) 開啟 CloudFormation 主控台。

1. 檢閱新建立的變更集 **nginx-plus-scraping-support**。您應該會看到一個可套用至 **CWAgentConfigSSMParameter** 資源的變更。輸入下列命令，以執行變更集並重新執行 CloudWatch 代理程式任務：

   ```
   aws ecs update-service --cluster $ECS_CLUSTER_NAME \
   --desired-count 0 \
   --service cwagent-prometheus-replica-service-EC2-$ECS_NETWORK_MODE \
   --region $AWS_REGION
   ```

1. 請等候約 10 秒鐘，然後輸入下列命令。

   ```
   aws ecs update-service --cluster $ECS_CLUSTER_NAME \
   --desired-count 1 \
   --service cwagent-prometheus-replica-service-EC2-$ECS_NETWORK_MODE \
   --region $AWS_REGION
   ```

1. 如果您是第一次在叢集上安裝具有 Prometheus 指標收集的 CloudWatch 代理程式，請輸入下列命令。

   ```
   ECS_CLUSTER_NAME=your_cluster_name
   AWS_REGION=your_aws_region
   ECS_NETWORK_MODE=bridge
   CREATE_IAM_ROLES=True
   ECS_TASK_ROLE_NAME=your_selected_ecs_task_role_name
   ECS_EXECUTION_ROLE_NAME=your_selected_ecs_execution_role_name
   
   aws cloudformation create-stack --stack-name CWAgent-Prometheus-ECS-${ECS_CLUSTER_NAME}-EC2-${ECS_NETWORK_MODE} \
       --template-body file://cwagent-ecs-prometheus-metric-for-bridge-host.yaml \
       --parameters ParameterKey=ECSClusterName,ParameterValue=$ECS_CLUSTER_NAME \
                    ParameterKey=CreateIAMRoles,ParameterValue=$CREATE_IAM_ROLES \
                    ParameterKey=ECSNetworkMode,ParameterValue=$ECS_NETWORK_MODE \
                    ParameterKey=TaskRoleName,ParameterValue=$ECS_TASK_ROLE_NAME \
                    ParameterKey=ExecutionRoleName,ParameterValue=$ECS_EXECUTION_ROLE_NAME \
       --capabilities CAPABILITY_NAMED_IAM \
       --region $AWS_REGION
   ```

## 檢視您的 NGINX Plus 指標和日誌
<a name="ContainerInsights-Prometheus-Setup-nginx-plus-view"></a>

您現在可以檢視收集的 NGINX Plus 指標。

**若要檢視範例 NGINX 工作負載的指標**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在執行叢集的區域中，在左側的導覽窗格中選擇 **Metrics** (指標)。尋找 **ContainerInsights/Prometheus** 命名空間來查看指標。

1. 若要查看 CloudWatch Logs 事件，請在導覽窗格中選擇 **Log groups** (日誌群組)。事件位於日誌串流 *nginx-plus-prometheus-exporter* 中的日誌群組 **/aws/containerinsights/*your\$1cluster\$1name*/prometheus** 中。

# 新增 Prometheus 湊集目標的教學：Amazon ECS 上的 Memcached
<a name="ContainerInsights-Prometheus-Setup-memcached-ecs"></a>

本教學課程提供實作介紹，讓您在具有 EC2 啟動類型的 Amazon ECS 叢集上湊集範例 Memcached 應用程式的 Prometheus 指標。CloudWatch 代理程式會透過 ECS 任務定義型服務探索自動探索 Memcached Prometheus 匯出工具目標。

Memcached 是一個通用的分佈式記憶體快取系統。它通常用於透過在 RAM 中快取資料和物件，來加速動態資料庫驅動的網站，進而減少必須讀取外部資料來源 (例如資料庫或 API) 的次數。如需詳細資訊，請參閱[什麼是 Memcached？](https://www.memcached.org/)

[memchached\$1exporter](https://github.com/prometheus/memcached_exporter) (Apache License 2.0) 是 Prometheus 其中一個正式匯出工具。memcache\$1exporter 預設會在 `/metrics.` 的連接埠 0.0.0.0:9150 上提供服務

本教學課程會使用下列兩個 Docker Hub 儲存庫中的 Docker 影像：
+ [Memcached](https://hub.docker.com/_/memcached?tab=description)
+ [prom/memcached-exporter](https://hub.docker.com/r/prom/memcached-exporter/)

**必要條件**

若要從 Amazon ECS 的範例 Prometheus 工作負載收集指標，您必須在叢集中執行 Container Insights。如需安裝 Container Insights 的相關資訊，請參閱 [在 Amazon ECS 上設定 Container Insights](deploy-container-insights-ECS.md)。

**Topics**
+ [設定 Amazon ECS EC2 叢集環境變數](#ContainerInsights-Prometheus-Setup-memcached-ecs-environment)
+ [安裝範例 Memcached 工作負載](#ContainerInsights-Prometheus-Setup-memcached-ecs-install-workload)
+ [設定 CloudWatch 代理程式以湊集 Memcached Prometheus 指標](#ContainerInsights-Prometheus-Setup-memcached-ecs-agent)
+ [檢視您的 Memcached 指標](#ContainerInsights-Prometheus-ECS-memcached-view)

## 設定 Amazon ECS EC2 叢集環境變數
<a name="ContainerInsights-Prometheus-Setup-memcached-ecs-environment"></a>

**如要設定 Amazon ECS EC2 叢集環境變數**

1. 安裝 Amazon ECS CLI (如果您尚未安裝)。如需詳細資訊，請參閱[安裝 Amazon ECS CLI](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI_installation.html)。

1. 設定新的 Amazon ECS 叢集名稱和區域。例如：

   ```
   ECS_CLUSTER_NAME=ecs-ec2-memcached-tutorial
   AWS_DEFAULT_REGION=ca-central-1
   ```

1. (選用) 如果您還沒有要在其中安裝範例 Memcached 工作負載和 CloudWatch 代理程式的 EC2 啟動類型的 Amazon ECS 叢集，您可以輸入下列命令，進而建立一個叢集。

   ```
   ecs-cli up --capability-iam --size 1 \
   --instance-type t3.medium \
   --cluster $ECS_CLUSTER_NAME \
   --region $AWS_REGION
   ```

   此命令的預期結果如下所示：

   ```
   WARN[0000] You will not be able to SSH into your EC2 instances without a key pair. 
   INFO[0000] Using recommended Amazon Linux 2 AMI with ECS Agent 1.44.4 and Docker version 19.03.6-ce 
   INFO[0001] Created cluster                               cluster=ecs-ec2-memcached-tutorial region=ca-central-1
   INFO[0002] Waiting for your cluster resources to be created... 
   INFO[0002] Cloudformation stack status                   stackStatus=CREATE_IN_PROGRESS
   INFO[0063] Cloudformation stack status                   stackStatus=CREATE_IN_PROGRESS
   INFO[0124] Cloudformation stack status                   stackStatus=CREATE_IN_PROGRESS
   VPC created: vpc-xxxxxxxxxxxxxxxxx
   Security Group created: sg-xxxxxxxxxxxxxxxxx
   Subnet created: subnet-xxxxxxxxxxxxxxxxx
   Subnet created: subnet-xxxxxxxxxxxxxxxxx
   Cluster creation succeeded.
   ```

## 安裝範例 Memcached 工作負載
<a name="ContainerInsights-Prometheus-Setup-memcached-ecs-install-workload"></a>

**若要安裝公開 Prometheus 指標的範例 Memcached 工作負載**

1. 輸入下列命令來下載 Memcached CloudFormation 範本。

   ```
   curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/replica-service/cwagent-prometheus/sample_traffic/memcached/memcached-traffic-sample.yaml
   ```

1. 輸入下列指令，設定要為 Memcached 建立的 IAM 角色名稱。

   ```
   MEMCACHED_ECS_TASK_ROLE_NAME=memcached-prometheus-demo-ecs-task-role-name
   MEMCACHED_ECS_EXECUTION_ROLE_NAME=memcached-prometheus-demo-ecs-execution-role-name
   ```

1. 輸入下列命令，以安裝範例 Memcached 工作負載。此範例會在 `host` 網路模式中安裝工作負載。

   ```
   MEMCACHED_ECS_NETWORK_MODE=host
   
   aws cloudformation create-stack --stack-name Memcached-Prometheus-Demo-ECS-$ECS_CLUSTER_NAME-EC2-$MEMCACHED_ECS_NETWORK_MODE \
       --template-body file://memcached-traffic-sample.yaml \
       --parameters ParameterKey=ECSClusterName,ParameterValue=$ECS_CLUSTER_NAME \
                    ParameterKey=ECSNetworkMode,ParameterValue=$MEMCACHED_ECS_NETWORK_MODE \
                    ParameterKey=TaskRoleName,ParameterValue=$MEMCACHED_ECS_TASK_ROLE_NAME \
                    ParameterKey=ExecutionRoleName,ParameterValue=$MEMCACHED_ECS_EXECUTION_ROLE_NAME \
       --capabilities CAPABILITY_NAMED_IAM \
       --region $AWS_REGION
   ```

 CloudFormation 堆疊會建立四個資源：
+ 一個 ECS 任務角色
+ 一個 ECS 任務執行角色
+ 一個 Memcached 任務定義
+ 一個 Memcached 服務

在 Memcached 任務定義中，定義了兩個容器：
+ 主要容器執行簡易的 Memcached 應用程式，並開啟連接埠 11211 以進行存取。
+ 另一個容器會執行 Redis OSS 匯出工具程序，以公開連接埠 9150 上的 Prometheus 指標。這是由 CloudWatch 代理程式探索及湊集的容器。

## 設定 CloudWatch 代理程式以湊集 Memcached Prometheus 指標
<a name="ContainerInsights-Prometheus-Setup-memcached-ecs-agent"></a>

**若要設定 CloudWatch 代理程式以湊集 Memcached Prometheus 指標**

1. 輸入下列命令，以下載最新版本的 `cwagent-ecs-prometheus-metric-for-awsvpc.yaml`。

   ```
   curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/replica-service/cwagent-prometheus/cloudformation-quickstart/cwagent-ecs-prometheus-metric-for-awsvpc.yaml
   ```

1. 使用文字編輯器開啟檔案，然後在 `resource:CWAgentConfigSSMParameter` 區段中的 `value` 金鑰查找完整的 CloudWatch 代理程式組態。

   然後，在 `ecs_service_discovery` 區段中，將下列組態新增至 `task_definition_list` 區段。

   ```
   {
       "sd_job_name": "ecs-memcached",
       "sd_metrics_ports": "9150",
       "sd_task_definition_arn_pattern": ".*:task-definition/memcached-prometheus-demo.*:[0-9]+"
   },
   ```

   對於 `metric_declaration` 區段中，預設設定不允許任何 Memcached 指標。新增下列區段，以允許 Memcached 指標。請務必遵循現有的縮排模式。

   ```
   {
     "source_labels": ["container_name"],
     "label_matcher": "memcached-exporter-.*",
     "dimensions": [["ClusterName", "TaskDefinitionFamily"]],
     "metric_selectors": [
       "^memcached_current_(bytes|items|connections)$",
       "^memcached_items_(reclaimed|evicted)_total$",
       "^memcached_(written|read)_bytes_total$",
       "^memcached_limit_bytes$",
       "^memcached_commands_total$"
     ]
   },
   {
     "source_labels": ["container_name"],
     "label_matcher": "memcached-exporter-.*",
     "dimensions": [["ClusterName", "TaskDefinitionFamily","status","command"], ["ClusterName", "TaskDefinitionFamily","command"]],
     "metric_selectors": [
       "^memcached_commands_total$"
     ]
   },
   ```

1. 如果您已在 Amazon ECS 叢集中部署 CloudWatch 代理程式 CloudFormation，您可以輸入下列命令來建立變更集。

   ```
   ECS_NETWORK_MODE=bridge
   CREATE_IAM_ROLES=True
   ECS_TASK_ROLE_NAME=your_selected_ecs_task_role_name
   ECS_EXECUTION_ROLE_NAME=your_selected_ecs_execution_role_name
   
   aws cloudformation create-change-set --stack-name CWAgent-Prometheus-ECS-${ECS_CLUSTER_NAME}-EC2-${ECS_NETWORK_MODE} \
       --template-body file://cwagent-ecs-prometheus-metric-for-bridge-host.yaml \
       --parameters ParameterKey=ECSClusterName,ParameterValue=$ECS_CLUSTER_NAME \
                    ParameterKey=CreateIAMRoles,ParameterValue=$CREATE_IAM_ROLES \
                    ParameterKey=ECSNetworkMode,ParameterValue=$ECS_NETWORK_MODE \
                    ParameterKey=TaskRoleName,ParameterValue=$ECS_TASK_ROLE_NAME \
                    ParameterKey=ExecutionRoleName,ParameterValue=$ECS_EXECUTION_ROLE_NAME \
       --capabilities CAPABILITY_NAMED_IAM \
       --region $AWS_REGION \
       --change-set-name memcached-scraping-support
   ```

1. 在 https：//[https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/) 開啟 CloudFormation 主控台。

1. 檢閱新建立的變更集 `memcached-scraping-support`。您應該會看到一個可套用至 `CWAgentConfigSSMParameter` 資源的變更。輸入下列命令，以執行變更集並重新執行 CloudWatch 代理程式任務。

   ```
   aws ecs update-service --cluster $ECS_CLUSTER_NAME \
   --desired-count 0 \
   --service cwagent-prometheus-replica-service-EC2-$ECS_NETWORK_MODE \
   --region $AWS_REGION
   ```

1. 請等候約 10 秒鐘，然後輸入下列命令。

   ```
   aws ecs update-service --cluster $ECS_CLUSTER_NAME \
   --desired-count 1 \
   --service cwagent-prometheus-replica-service-EC2-$ECS_NETWORK_MODE \
   --region $AWS_REGION
   ```

1. 如果您是第一次在叢集上安裝具有 Prometheus 指標收集的 CloudWatch 代理程式，請輸入下列命令：

   ```
   ECS_NETWORK_MODEE=bridge
   CREATE_IAM_ROLES=True
   ECS_TASK_ROLE_NAME=your_selected_ecs_task_role_name
   ECS_EXECUTION_ROLE_NAME=your_selected_ecs_execution_role_name
   
   aws cloudformation create-stack --stack-name CWAgent-Prometheus-ECS-${ECS_CLUSTER_NAME}-EC2-${ECS_NETWORK_MODE} \
       --template-body file://cwagent-ecs-prometheus-metric-for-bridge-host.yaml \
       --parameters ParameterKey=ECSClusterName,ParameterValue=$ECS_CLUSTER_NAME \
                    ParameterKey=CreateIAMRoles,ParameterValue=$CREATE_IAM_ROLES \
                    ParameterKey=ECSNetworkMode,ParameterValue=$ECS_NETWORK_MODE \
                    ParameterKey=TaskRoleName,ParameterValue=$ECS_TASK_ROLE_NAME \
                    ParameterKey=ExecutionRoleName,ParameterValue=$ECS_EXECUTION_ROLE_NAME \
       --capabilities CAPABILITY_NAMED_IAM \
       --region $AWS_REGION
   ```

## 檢視您的 Memcached 指標
<a name="ContainerInsights-Prometheus-ECS-memcached-view"></a>

此教學課程會將下列指標傳送至 CloudWatch 中的 **ECS/ContainerInsights/Prometheus** 命名空間。您可以使用 CloudWatch 主控台查看該命名空間中的指標。


| 指標名稱 | 維度 | 
| --- | --- | 
|  `memcached_current_items` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `memcached_current_connections` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `memcached_limit_bytes` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `memcached_current_bytes` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `memcached_written_bytes_total` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `memcached_read_bytes_total` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `memcached_items_evicted_total` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `memcached_items_reclaimed_total` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `memcached_commands_total` |  `ClusterName`, `TaskDefinitionFamily` `ClusterName`、TaskDefinitionFamily、命令 `ClusterName`、TaskDefinitionFamily、狀態、命令  | 

**注意**  
**command** (命令) 維度的數值可以是：`delete`、`get`、`cas`、`set`、`decr`、`touch`、`incr` 或 `flush`。  
**status** (狀態) 維度的數值可以是 `hit`、`miss` 或 `badval`。

您也可以為您的 Memcached Prometheus 指標建立 CloudWatch 儀表板。

**若要建立 Memcached Prometheus 指標的儀表板**

1. 建立環境變數，取代下面的數值，以符合您的部署。

   ```
   DASHBOARD_NAME=your_memcached_cw_dashboard_name
   ECS_TASK_DEF_FAMILY=memcached-prometheus-demo-$ECS_CLUSTER_NAME-EC2-$MEMCACHED_ECS_NETWORK_MOD
   ```

1. 輸入下列命令建立儀表板。

   ```
   curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/replica-service/cwagent-prometheus/sample_cloudwatch_dashboards/memcached/cw_dashboard_memcached.json \
   | sed "s/{{YOUR_AWS_REGION}}/$AWS_REGION/g" \
   | sed "s/{{YOUR_CLUSTER_NAME}}/$ECS_CLUSTER_NAME/g" \
   | sed "s/{{YOUR_TASK_DEF_FAMILY}}/$ECS_TASK_DEF_FAMILY/g" \
   | xargs -0 aws cloudwatch put-dashboard --dashboard-name ${DASHBOARD_NAME} --region $AWS_REGION --dashboard-body
   ```

# 在 Amazon ECS Fargate 上抓取 Redis OSS Prometheus 指標的教學課程
<a name="ContainerInsights-Prometheus-Setup-redis-ecs"></a>

本教學課程提供實作介紹，讓您在 Amazon ECS Fargate 叢集中湊集範例 Redis OSS 應用程式的 Prometheus 指標。CloudWatch 代理程式會根據容器的 Docker 標籤，自動探索 Redis OSS Prometheus 匯出工具目標，並支援 Prometheus 指標。

Redis OSS (https://redis.io/) 是一個開放原始碼 (BSD 授權)、記憶體內資料結構存儲，可用作資料庫、快取和訊息代理程式。如需詳細資訊，請參閱 [redis](https://redis.io/)。

redis\$1exporter (授權的 MIT 授權) 可用於在指定的連接埠上公開 Redis OSS Prometheus 指標 (預設：0.0.0.0:9121)。如需詳細資訊，請參閱 [redis\$1exporter](https://github.com/oliver006/redis_exporter)。

本教學課程會使用下列兩個 Docker Hub 儲存庫中的 Docker 影像：
+ [redis](https://hub.docker.com/_/redis?tab=description)
+ [redis\$1exporter](https://hub.docker.com/r/oliver006/redis_exporter)

**必要條件**

若要從 Amazon ECS 的範例 Prometheus 工作負載收集指標，您必須在叢集中執行 Container Insights。如需安裝 Container Insights 的相關資訊，請參閱 [在 Amazon ECS 上設定 Container Insights](deploy-container-insights-ECS.md)。

**Topics**
+ [設定 Amazon ECS Fargate 叢集環境變數](#ContainerInsights-Prometheus-Setup-redis-ecs-variable)
+ [設定 Amazon ECS Fargate 叢集的網路環境變數](#ContainerInsights-Prometheus-Setup-redis-ecs-variable2)
+ [安裝範例 Redis OSS 工作負載](#ContainerInsights-Prometheus-Setup-redis-ecs-install-workload)
+ [設定 CloudWatch 代理程式，以湊集 Redis OSS Prometheus 指標](#ContainerInsights-Prometheus-Setup-redis-ecs-agent)
+ [檢視 Redis OSS 指標](#ContainerInsights-Prometheus-Setup-redis-view)

## 設定 Amazon ECS Fargate 叢集環境變數
<a name="ContainerInsights-Prometheus-Setup-redis-ecs-variable"></a>

**若要設定 Amazon ECS Fargate 叢集環境變數**

1. 安裝 Amazon ECS CLI (如果您尚未安裝)。如需詳細資訊，請參閱[安裝 Amazon ECS CLI](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI_installation.html)。

1. 設定新的 Amazon ECS 叢集名稱和區域。例如：

   ```
   ECS_CLUSTER_NAME=ecs-fargate-redis-tutorial
   AWS_DEFAULT_REGION=ca-central-1
   ```

1. (選用) 如果您還沒有要在其中安裝範例 Redis OSS 工作負載和 CloudWatch 代理程式的 Amazon ECS Fargate 叢集，您可以輸入下列命令，進而建立一個叢集。

   ```
   ecs-cli up --capability-iam \
   --cluster $ECS_CLUSTER_NAME \
   --launch-type FARGATE \
   --region $AWS_DEFAULT_REGION
   ```

   此命令的預期結果如下所示：

   ```
   INFO[0000] Created cluster   cluster=ecs-fargate-redis-tutorial region=ca-central-1
   INFO[0001] Waiting for your cluster resources to be created...
   INFO[0001] Cloudformation stack status   stackStatus=CREATE_IN_PROGRESS
   VPC created: vpc-xxxxxxxxxxxxxxxxx
   Subnet created: subnet-xxxxxxxxxxxxxxxxx
   Subnet created: subnet-xxxxxxxxxxxxxxxxx
   Cluster creation succeeded.
   ```

## 設定 Amazon ECS Fargate 叢集的網路環境變數
<a name="ContainerInsights-Prometheus-Setup-redis-ecs-variable2"></a>

**若要設定 Amazon ECS Fargate 叢集的網路環境變數**

1. 設定 Amazon ECS 叢集的 VPC 和子網路 ID。如果您在先前的程序中建立了新的叢集，您會在最終命令的結果中看到這些值。否則，請使用您要與 Redis 搭配使用的現有叢集的 ID。

   ```
   ECS_CLUSTER_VPC=vpc-xxxxxxxxxxxxxxxxx
   ECS_CLUSTER_SUBNET_1=subnet-xxxxxxxxxxxxxxxxx
   ECS_CLUSTER_SUBNET_2=subnet-xxxxxxxxxxxxxxxxx
   ```

1. 在本教學課程中，我們將在 Amazon ECS 叢集 VPC 的預設安全群組中安裝 Redis OSS 應用程式和 CloudWatch 代理程式。預設安全群組允許相同安全群組內的所有網路連線，因此 CloudWatch 代理程式可以擷取 Redis OSS 容器上公開的 Prometheus 指標。在實際生產環境中，您可能想要為 Redis OSS 應用程式和 CloudWatch 代理程式建立專用安全群組，並為其設定自訂許可。

   輸入以下命令以獲取預設安全群組 ID。

   ```
   aws ec2 describe-security-groups \
   --filters Name=vpc-id,Values=$ECS_CLUSTER_VPC  \
   --region $AWS_DEFAULT_REGION
   ```

   然後，透過輸入以下命令來設定 Fargate 叢集預設 安全群組變數，將 *my-default-security-group* 取代為您從之前命令中找到的值。

   ```
   ECS_CLUSTER_SECURITY_GROUP=my-default-security-group
   ```

## 安裝範例 Redis OSS 工作負載
<a name="ContainerInsights-Prometheus-Setup-redis-ecs-install-workload"></a>

**若要安裝公開 Prometheus 指標的範例 Redis OSS 工作負載**

1. 輸入下列命令來下載 Redis OSS CloudFormation 範本。

   ```
   curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/replica-service/cwagent-prometheus/sample_traffic/redis/redis-traffic-sample.yaml
   ```

1. 輸入下列指令，設定要為 Redis OSS 建立的 IAM 角色名稱。

   ```
   REDIS_ECS_TASK_ROLE_NAME=redis-prometheus-demo-ecs-task-role-name
   REDIS_ECS_EXECUTION_ROLE_NAME=redis-prometheus-demo-ecs-execution-role-name
   ```

1. 輸入下列命令以安裝範例 Redis OSS 工作負載。

   ```
   aws cloudformation create-stack --stack-name Redis-Prometheus-Demo-ECS-$ECS_CLUSTER_NAME-fargate-awsvpc \
       --template-body file://redis-traffic-sample.yaml \
       --parameters ParameterKey=ECSClusterName,ParameterValue=$ECS_CLUSTER_NAME \
                    ParameterKey=SecurityGroupID,ParameterValue=$ECS_CLUSTER_SECURITY_GROUP \
                    ParameterKey=SubnetID,ParameterValue=$ECS_CLUSTER_SUBNET_1 \
                    ParameterKey=TaskRoleName,ParameterValue=$REDIS_ECS_TASK_ROLE_NAME \
                    ParameterKey=ExecutionRoleName,ParameterValue=$REDIS_ECS_EXECUTION_ROLE_NAME \
       --capabilities CAPABILITY_NAMED_IAM \
       --region $AWS_DEFAULT_REGION
   ```

 CloudFormation 堆疊會建立四個資源：
+ 一個 ECS 任務角色
+ 一個 ECS 任務執行角色
+ 一個 Redis OSS 任務定義
+ 一個 Redis OSS 服務

在 Redis OSS 的任務定義中，定義了兩個容器：
+ 主要容器執行簡易的 Redis OSS 應用程式，並開啟連接埠 6379 以進行存取。
+ 另一個容器會執行 Redis OSS 匯出工具程序，以公開連接埠 9121 上的 Prometheus 指標。這是由 CloudWatch 代理程式探索及湊集的容器。定義下列 Docker 標籤，以便 CloudWatch 代理程式可以基於此發現這個容器。

  ```
  ECS_PROMETHEUS_EXPORTER_PORT: 9121
  ```

## 設定 CloudWatch 代理程式，以湊集 Redis OSS Prometheus 指標
<a name="ContainerInsights-Prometheus-Setup-redis-ecs-agent"></a>

**若要設定 CloudWatch 代理程式，以湊集 Redis OSS Prometheus 指標**

1. 輸入下列命令，以下載最新版本的 `cwagent-ecs-prometheus-metric-for-awsvpc.yaml`。

   ```
   curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/ecs-task-definition-templates/deployment-mode/replica-service/cwagent-prometheus/cloudformation-quickstart/cwagent-ecs-prometheus-metric-for-awsvpc.yaml
   ```

1. 使用文字編輯器開啟檔案，然後在 `resource:CWAgentConfigSSMParameter` 區段中的 `value` 金鑰查找完整的 CloudWatch 代理程式組態。

   然後，在此處顯示的 `ecs_service_discovery` 區段，使用基於 `ECS_PROMETHEUS_EXPORTER_PORT` 的預設設定啟用 `docker_label` 型服務探索，而其會與我們在 Redis OSS ECS 任務定義中定義的 Docker 標籤相符。因此，我們不需要在本節中進行任何變更：

   ```
   ecs_service_discovery": {
     "sd_frequency": "1m",
     "sd_result_file": "/tmp/cwagent_ecs_auto_sd.yaml",
   *  "docker_label": {
     },*
     ...
   ```

   對於 `metric_declaration` 區段，預設的設定不允許任何 Redis OSS 指標。新增下列區段，以允許 Redis OSS 指標。請務必遵循現有的縮排模式。

   ```
   {
     "source_labels": ["container_name"],
     "label_matcher": "^redis-exporter-.*$",
     "dimensions": [["ClusterName","TaskDefinitionFamily"]],
     "metric_selectors": [
       "^redis_net_(in|out)put_bytes_total$",
       "^redis_(expired|evicted)_keys_total$",
       "^redis_keyspace_(hits|misses)_total$",
       "^redis_memory_used_bytes$",
       "^redis_connected_clients$"
     ]
   },
   {
     "source_labels": ["container_name"],
     "label_matcher": "^redis-exporter-.*$",
     "dimensions": [["ClusterName","TaskDefinitionFamily","cmd"]],
     "metric_selectors": [
       "^redis_commands_total$"
     ]
   },
   {
     "source_labels": ["container_name"],
     "label_matcher": "^redis-exporter-.*$",
     "dimensions": [["ClusterName","TaskDefinitionFamily","db"]],
     "metric_selectors": [
       "^redis_db_keys$"
     ]
   },
   ```

1. 如果您已在 Amazon ECS 叢集中部署 CloudWatch 代理程式 CloudFormation，您可以輸入下列命令來建立變更集。

   ```
   ECS_LAUNCH_TYPE=FARGATE
   CREATE_IAM_ROLES=True
   ECS_CLUSTER_SUBNET=$ECS_CLUSTER_SUBNET_1
   ECS_TASK_ROLE_NAME=your_selected_ecs_task_role_name
   ECS_EXECUTION_ROLE_NAME=your_selected_ecs_execution_role_name
   
   aws cloudformation create-change-set --stack-name CWAgent-Prometheus-ECS-$ECS_CLUSTER_NAME-$ECS_LAUNCH_TYPE-awsvpc \
       --template-body file://cwagent-ecs-prometheus-metric-for-awsvpc.yaml \
       --parameters ParameterKey=ECSClusterName,ParameterValue=$ECS_CLUSTER_NAME \
                    ParameterKey=CreateIAMRoles,ParameterValue=$CREATE_IAM_ROLES \
                    ParameterKey=ECSLaunchType,ParameterValue=$ECS_LAUNCH_TYPE \
                    ParameterKey=SecurityGroupID,ParameterValue=$ECS_CLUSTER_SECURITY_GROUP \
                    ParameterKey=SubnetID,ParameterValue=$ECS_CLUSTER_SUBNET \
                    ParameterKey=TaskRoleName,ParameterValue=$ECS_TASK_ROLE_NAME \
                    ParameterKey=ExecutionRoleName,ParameterValue=$ECS_EXECUTION_ROLE_NAME \
       --capabilities CAPABILITY_NAMED_IAM \
       --region ${AWS_DEFAULT_REGION} \
       --change-set-name redis-scraping-support
   ```

1. 在 https：//[https://console.aws.amazon.com/cloudformation](https://console.aws.amazon.com/cloudformation/) 開啟 CloudFormation 主控台。

1. 檢閱新建立的變更集 `redis-scraping-support`。您應該會看到一個可套用至 `CWAgentConfigSSMParameter` 資源的變更。輸入下列命令，以執行變更集並重新執行 CloudWatch 代理程式任務。

   ```
   aws ecs update-service --cluster $ECS_CLUSTER_NAME \
   --desired-count 0 \
   --service cwagent-prometheus-replica-service-$ECS_LAUNCH_TYPE-awsvpc \
   --region ${AWS_DEFAULT_REGION}
   ```

1. 請等候約 10 秒鐘，然後輸入下列命令。

   ```
   aws ecs update-service --cluster $ECS_CLUSTER_NAME \
   --desired-count 1 \
   --service cwagent-prometheus-replica-service-$ECS_LAUNCH_TYPE-awsvpc \
   --region ${AWS_DEFAULT_REGION}
   ```

1. 如果您是第一次在叢集上安裝具有 Prometheus 指標收集的 CloudWatch 代理程式，請輸入下列命令：

   ```
   ECS_LAUNCH_TYPE=FARGATE
   CREATE_IAM_ROLES=True
   ECS_CLUSTER_SUBNET=$ECS_CLUSTER_SUBNET_1
   ECS_TASK_ROLE_NAME=your_selected_ecs_task_role_name
   ECS_EXECUTION_ROLE_NAME=your_selected_ecs_execution_role_name
   
   aws cloudformation create-stack --stack-name CWAgent-Prometheus-ECS-$ECS_CLUSTER_NAME-$ECS_LAUNCH_TYPE-awsvpc \
       --template-body file://cwagent-ecs-prometheus-metric-for-awsvpc.yaml \
       --parameters ParameterKey=ECSClusterName,ParameterValue=$ECS_CLUSTER_NAME \
                    ParameterKey=CreateIAMRoles,ParameterValue=$CREATE_IAM_ROLES \
                    ParameterKey=ECSLaunchType,ParameterValue=$ECS_LAUNCH_TYPE \
                    ParameterKey=SecurityGroupID,ParameterValue=$ECS_CLUSTER_SECURITY_GROUP \
                    ParameterKey=SubnetID,ParameterValue=$ECS_CLUSTER_SUBNET \
                    ParameterKey=TaskRoleName,ParameterValue=$ECS_TASK_ROLE_NAME \
                    ParameterKey=ExecutionRoleName,ParameterValue=$ECS_EXECUTION_ROLE_NAME \
       --capabilities CAPABILITY_NAMED_IAM \
       --region ${AWS_DEFAULT_REGION}
   ```

## 檢視 Redis OSS 指標
<a name="ContainerInsights-Prometheus-Setup-redis-view"></a>

此教學課程會將下列指標傳送至 CloudWatch 中的 **ECS/ContainerInsights/Prometheus** 命名空間。您可以使用 CloudWatch 主控台查看該命名空間中的指標。


| 指標名稱 | 維度 | 
| --- | --- | 
|  `redis_net_input_bytes_total` |  ClusterName、`TaskDefinitionFamily`  | 
|  `redis_net_output_bytes_total` |  ClusterName、`TaskDefinitionFamily`  | 
|  `redis_expired_keys_total` |  ClusterName、`TaskDefinitionFamily`  | 
|  `redis_evicted_keys_total` |  ClusterName、`TaskDefinitionFamily`  | 
|  `redis_keyspace_hits_total` |  ClusterName、`TaskDefinitionFamily`  | 
|  `redis_keyspace_misses_total` |  ClusterName、`TaskDefinitionFamily`  | 
|  `redis_memory_used_bytes` |  ClusterName、`TaskDefinitionFamily`  | 
|  `redis_connected_clients` |  ClusterName、`TaskDefinitionFamily`  | 
|  `redis_commands_total` |  ` ClusterName`, `TaskDefinitionFamily`, `cmd`  | 
|  `redis_db_keys` |  `ClusterName`, `TaskDefinitionFamily`, `db`  | 

**注意**  
**cmd** 維度的數值可以是：`append`、`client`、`command`、`config`、`dbsize`、`flushall`、`get`、`incr`、`info` `latency` 或 `slowlog`。  
**db** 維度的數值可以是 `db0` 至 `db15`。

您也可以為 Redis OSS Prometheus 指標建立 CloudWatch 儀表板。

**若要建立 Redis OSS Prometheus 指標的儀表板**

1. 建立環境變數，取代下面的數值，以符合您的部署。

   ```
   DASHBOARD_NAME=your_cw_dashboard_name
   ECS_TASK_DEF_FAMILY=redis-prometheus-demo-$ECS_CLUSTER_NAME-fargate-awsvpc
   ```

1. 輸入下列命令建立儀表板。

   ```
   curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/sample_cloudwatch_dashboards/redis/cw_dashboard_redis.json \
   | sed "s/{{YOUR_AWS_REGION}}/${REGION_NAME}/g" \
   | sed "s/{{YOUR_CLUSTER_NAME}}/${CLUSTER_NAME}/g" \
   | sed "s/{{YOUR_NAMESPACE}}/${NAMESPACE}/g" \
   ```

# 在 Amazon EKS 和 Kubernetes 執行個體上安裝和設定 Prometheus 指標集合
<a name="ContainerInsights-Prometheus-install-EKS"></a>

若要從執行 Amazon EKS 或 Kubernetes 的叢集收集 Prometheus 指標，您可以使用 CloudWatch 代理程式做為收集器，或使用 AWS Distro for OpenTelemetry 收集器。如需使用 AWS Distro for OpenTelemetry 收集器的詳細資訊，請參閱 https：//[https://aws-otel.github.io/docs/getting-started/container-insights/eks-prometheus](https://aws-otel.github.io/docs/getting-started/container-insights/eks-prometheus)。

以下各節說明如何使用 CloudWatch 代理程式收集 Prometheus 指標。他們說明了如何在執行 Amazon EKS 或 Kubernetes 的叢集上安裝具有 Prometheus 監控的 CloudWatch 代理程式，以及如何設定代理程式以湊集其他目標。它們也提供選擇性的教學課程，用於設定範例工作負載，以便使用 Prometheus 監控進行測試。

**Topics**
+ [在 Amazon EKS 和 Kubernetes 叢集上安裝具有 Prometheus 指標集合的 CloudWatch 代理程式。](ContainerInsights-Prometheus-Setup.md)

# 在 Amazon EKS 和 Kubernetes 叢集上安裝具有 Prometheus 指標集合的 CloudWatch 代理程式。
<a name="ContainerInsights-Prometheus-Setup"></a>

本節說明如何在執行 Amazon EKS 或 Kubernetes 的叢集中設定具有 Prometheus 監控的 CloudWatch 代理程式。執行這項操作之後，代理程式會自動湊集和匯入該叢集中執行的下列工作負載的指標。
+ AWS App Mesh
+ NGINX
+ Memcached
+ Java/JMX
+ HAProxy
+ Fluent Bit

您也可以設定代理程式，以湊集和匯入其他 Prometheus 工作負載和來源。

在依照下列步驟安裝 CloudWatch 代理程式進行 Prometheus 指標收集之前，您必須擁有在 Amazon EKS 上執行的叢集，或是在 Amazon EC2 執行個體上執行的 Kubernetes 叢集。

**VPC 安全群組要求**

Prometheus 工作負載安全群組的輸入規則必須開啟到 CloudWatch 代理程式的 Prometheus 連接埠，以便透過私有 IP 擷取 Prometheus 指標。

CloudWatch 代理程式安全群組的輸出規則必須允許 CloudWatch 代理程式透過私有 IP 連接至 Prometheus 工作負載的連接埠。

**Topics**
+ [在 Amazon EKS 和 Kubernetes 叢集上安裝具有 Prometheus 指標集合的 CloudWatch 代理程式。](#ContainerInsights-Prometheus-Setup-roles)
+ [湊集其他 Prometheus 來源並匯入這些指標](ContainerInsights-Prometheus-Setup-configure.md)
+ [(選用) 設定範例容器化 Amazon EKS 工作負載範例進行 Prometheus 指標測試](ContainerInsights-Prometheus-Sample-Workloads.md)

## 在 Amazon EKS 和 Kubernetes 叢集上安裝具有 Prometheus 指標集合的 CloudWatch 代理程式。
<a name="ContainerInsights-Prometheus-Setup-roles"></a>

本節說明如何在執行 Amazon EKS 或 Kubernetes 的叢集中設定具有 Prometheus 監控的 CloudWatch 代理程式。執行這項操作之後，代理程式會自動湊集和匯入該叢集中執行的下列工作負載的指標。
+ AWS App Mesh
+ NGINX
+ Memcached
+ Java/JMX
+ HAProxy
+ Fluent Bit

您也可以設定代理程式，以湊集和匯入其他 Prometheus 工作負載和來源。

在依照下列步驟安裝 CloudWatch 代理程式進行 Prometheus 指標收集之前，您必須擁有在 Amazon EKS 上執行的叢集，或是在 Amazon EC2 執行個體上執行的 Kubernetes 叢集。

**VPC 安全群組要求**

Prometheus 工作負載安全群組的輸入規則必須開啟到 CloudWatch 代理程式的 Prometheus 連接埠，以便透過私有 IP 擷取 Prometheus 指標。

CloudWatch 代理程式安全群組的輸出規則必須允許 CloudWatch 代理程式透過私有 IP 連接至 Prometheus 工作負載的連接埠。

**Topics**
+ [設定 IAM 角色](#ContainerInsights-Prometheus-Setup-roles)
+ [安裝 CloudWatch 代理程式以收集 Prometheus 指標](#ContainerInsights-Prometheus-Setup-install-agent)

### 設定 IAM 角色
<a name="ContainerInsights-Prometheus-Setup-roles"></a>

第一步是在叢集中設定必要的 IAM 角色。有兩種方法：
+ 設定服務帳戶的 IAM 角色， 亦稱為*服務角色*。此方法適用於 EC2 啟動類型和 Fargate 啟動類型。
+ 將 IAM 政策新增至用於叢集的 IAM 角色。這只適用於 EC2 啟動類型。

**設定服務角色 (EC2 啟動類型和 Fargate 啟動類型)**

若要設定服務角色，請輸入下列命令。以叢集的名稱取代 *MyCluster*。

```
eksctl create iamserviceaccount \
 --name cwagent-prometheus \
--namespace amazon-cloudwatch \
 --cluster MyCluster \
--attach-policy-arn arn:aws:iam::aws:policy/CloudWatchAgentServerPolicy \
--approve \
--override-existing-serviceaccounts
```

**將政策新增至節點群組的 IAM 角色 (僅適用於 EC2 啟動類型)**

**若要在節點群組中設定 IAM 政策以獲得 Prometheus 支援**

1. 前往 [https://console.aws.amazon.com/ec2/](https://console.aws.amazon.com/ec2/) 開啟 Amazon EC2 主控台。

1. 在導覽窗格中，選擇**執行個體**。

1. 您需要找出叢集的 IAM 角色名稱的字首。若要執行此操作，請選取叢集中執行個體名稱旁的核取方塊，然後選擇**動作**、**安全性**、**修改 IAM 角色**。然後複製 IAM 角色的字首，例如 `eksctl-dev303-workshop-nodegroup`。

1. 在以下網址開啟 IAM 主控台：[https://console.aws.amazon.com/iam/](https://console.aws.amazon.com/iam/)。

1. 在導覽窗格中，選擇**角色**。

1. 使用搜尋方塊尋找您先前在此程序中複製的前綴，然後選擇該角色。

1. 選擇**連接政策**。

1. 使用搜尋方塊尋找 **CloudWatchAgentServerPolicy**。選取 **CloudWatchAgentServerPolicy** 旁的核取方塊，然後選擇 **Attach policy (連接政策)**。

### 安裝 CloudWatch 代理程式以收集 Prometheus 指標
<a name="ContainerInsights-Prometheus-Setup-install-agent"></a>

您必須在叢集中安裝 CloudWatch 代理程式，才能收集指標。如何安裝代理程式會因 Amazon EKS 叢集和 Kubernetes 叢集而有所不同。

**刪除支援 Prometheus 的舊版 CloudWatch 代理程式**

如果您已在叢集中安裝具有 Prometheus 支援的 CloudWatch 代理程式版本，則必須輸入下列命令來刪除該版本。只有具有 Prometheus 支援的舊版代理程式才需要這麼做。您不需要刪除啟用 Container Insights 但不含 Prometheus 支援的 CloudWatch 代理程式。

```
kubectl delete deployment cwagent-prometheus -n amazon-cloudwatch
```

#### 在具有 EC2 啟動類型的 Amazon EKS 叢集上安裝 CloudWatch 代理程式
<a name="ContainerInsights-Prometheus-Setup-install-agent-EKS"></a>

若要在 Amazon EKS 叢集上安裝具有 Prometheus 支援的 CloudWatch 代理程式，請依照下列步驟執行。

**若要在 Amazon EKS 叢集上安裝具有 Prometheus 支援的 CloudWatch 代理程式**

1. 輸入下列命令以檢查是否已建立 `amazon-cloudwatch` 命名空間：

   ```
   kubectl get namespace
   ```

1. 如果結果中未顯示 `amazon-cloudwatch`，請輸入下列命令來建立它：

   ```
   kubectl create namespace amazon-cloudwatch
   ```

1. 若要部署具有預設組態的代理程式，並讓它將資料傳送到其安裝所在的 AWS 區域，請輸入下列命令：

   ```
   kubectl apply -f https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/prometheus-eks.yaml
   ```

   如果要讓代理程式將資料傳送到不同的區域，請依照下列步驟執行：

   1. 輸入下列命令，以下載代理程式的 YAML 檔案：

      ```
      curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/prometheus-eks.yaml
      ```

   1. 使用文字編輯器開啟檔案，然後搜尋檔案的 `cwagentconfig.json` 區塊。

   1. 新增反白的行，指定您想要的區域：

      ```
      cwagentconfig.json: |
          {
            "agent": {
              "region": "us-east-2"
            },
            "logs": { ...
      ```

   1. 儲存檔案並使用您更新的檔案來部署代理程式。

      ```
      kubectl apply -f prometheus-eks.yaml
      ```

#### 在具有 Fargate 啟動類型的 Amazon EKS 叢集上安裝 CloudWatch 代理程式
<a name="ContainerInsights-Prometheus-Setup-install-agent-EKS-fargate"></a>

若要在具有 Fargate 啟動類型的 Amazon EKS 叢集上安裝具有 Prometheus 支援的 CloudWatch 代理程式，請依照下列步驟執行。

**若要在具有 Fargate 啟動類型的 Amazon EKS 叢集上安裝具有 Prometheus 支援的 CloudWatch 代理程式**

1. 輸入以下命令，為 CloudWatch 代理程式建立 Fargate 描述檔，以便它可以在叢集內執行。以叢集的名稱取代 *MyCluster*。

   ```
   eksctl create fargateprofile --cluster MyCluster \
   --name amazon-cloudwatch \
   --namespace amazon-cloudwatch
   ```

1. 若要安裝 CloudWatch 代理程式，請輸入以下命令。以叢集的名稱取代 *MyCluster*。此名稱會用於存放代理程式所收集之日誌事件的日誌群組名稱中，也用作為代理程式所收集之指標的維度。

   將 *region* 取代為您想要傳送指標的區域名稱。例如 `us-west-1`。

   ```
   curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/prometheus-eks-fargate.yaml | 
   sed "s/{{cluster_name}}/MyCluster/;s/{{region_name}}/region/" | 
   kubectl apply -f -
   ```

#### 在 Kubernetes 叢集上安裝 CloudWatch 代理程式
<a name="ContainerInsights-Prometheus-Setup-install-agent-Kubernetes"></a>

若要在執行 Kubernetes 的叢集上安裝具有 Prometheus 支援的 CloudWatch 代理程式，請輸入下列命令：

```
curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/prometheus-k8s.yaml | 
sed "s/{{cluster_name}}/MyCluster/;s/{{region_name}}/region/" | 
kubectl apply -f -
```

以叢集的名稱取代 *MyCluster*。此名稱會用於存放代理程式所收集之日誌事件的日誌群組名稱中，也用作為代理程式所收集之指標的維度。

將*區域*取代為 AWS 您要傳送指標的區域名稱。例如 **us-west-1**。

#### 確認代理程式正在執行中
<a name="ContainerInsights-Prometheus-Setup-install-agent-verify"></a>

在 Amazon EKS 和 Kubernetes 叢集上，您可以輸入下列命令，以確認代理程式正在執行。

```
kubectl get pod -l "app=cwagent-prometheus" -n amazon-cloudwatch
```

如果結果包含處於 `Running` 狀態的單一 CloudWatch 代理程式 pod，則表示代理程式正在執行並且正在收集 Prometheus 指標。預設情況下，CloudWatch 代理程式每分鐘會收集 App Mesh、NGINX，Memcached、Java/JMX 和 HAProxy 的指標。如需這些指標的詳細資訊，請參閱 [CloudWatch 代理程式收集的 Prometheus 指標](ContainerInsights-Prometheus-metrics.md)。如需如何在 CloudWatch 中查看 Prometheus 指標的相關指示，請參閱 [檢視 Prometheus 指標](ContainerInsights-Prometheus-viewmetrics.md)

您也可以將 CloudWatch 代理程式設定為從其他 Prometheus 匯出工具收集指標。如需詳細資訊，請參閱[湊集其他 Prometheus 來源並匯入這些指標](ContainerInsights-Prometheus-Setup-configure.md)。

# 湊集其他 Prometheus 來源並匯入這些指標
<a name="ContainerInsights-Prometheus-Setup-configure"></a>

具有 Prometheus 監控的 CloudWatch 代理程式需要兩種組態來湊集 Prometheus 指標。其中一個是 Prometheus 文件的 [<scrape\$1config>](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config) 中記錄的標準 Prometheus 湊集組態。另一個適用於 CloudWatch 代理程式組態。

對於 Amazon EKS 叢集，組態在 `prometheus-eks.yaml` (EC2 啟動類型) 或 `prometheus-eks-fargate.yaml` (Fargate 啟動類型) 中定義為兩種組態映射：
+ `name: prometheus-config` 區段包含 Prometheus 湊集的設定。
+ `name: prometheus-cwagentconfig` 區段包含 CloudWatch 代理程式的組態。您可以使用此區段來設定 CloudWatch 收集 Prometheus 指標的方式。例如，您可以將要匯入 CloudWatch 的指標列入白名單，並定義其維度。

對於在 Amazon EC2 執行個體上執行的 Kubernetes 叢集，組態在 `prometheus-k8s.yaml` YAML 檔案中定義為兩種組態映射：
+ `name: prometheus-config` 區段包含 Prometheus 湊集的設定。
+ `name: prometheus-cwagentconfig` 區段包含 CloudWatch 代理程式的組態。

若要湊集其他 Prometheus 指標來源並將這些指標匯入 CloudWatch，您可以修改 Prometheus 湊集組態和 CloudWatch 代理程式組態，然後使用更新的組態重新部署代理程式。

**VPC 安全群組要求**

Prometheus 工作負載安全群組的輸入規則必須開啟到 CloudWatch 代理程式的 Prometheus 連接埠，以便透過私有 IP 擷取 Prometheus 指標。

CloudWatch 代理程式安全群組的輸出規則必須允許 CloudWatch 代理程式透過私有 IP 連接至 Prometheus 工作負載的連接埠。

## Prometheus 湊集組態
<a name="ContainerInsights-Prometheus-Setup-config-global"></a>

CloudWatch 代理程式支援標準 Prometheus 湊集組態，如 Prometheus 文件的 [<scrape\$1config>](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config) 中所述。您可以編輯此區段來更新已存在於此檔案中的組態，並新增其他 Prometheus 湊集目標。根據預設，範例組態檔案包含下列全域組態行：

```
global:
  scrape_interval: 1m
  scrape_timeout: 10s
```
+ **scrape\$1interval**— 定義湊集目標的頻率。
+ **scrape\$1timeout**— 定義湊集請求逾時之前要等待的時間。

您也可以在任務層級為這些設定定義不同的數值，以覆寫全域設定。

### Prometheus 湊集任務
<a name="ContainerInsights-Prometheus-Setup-config-scrape"></a>

CloudWatch 代理程式 YAML 檔案已設定一些預設的湊集任務。例如，在 `prometheus-eks.yaml` 中，已在 `scrape_configs` 區段中的 `job_name` 行設定預設湊集任務。在此檔案中，下列預設 `kubernetes-pod-jmx` 區段會湊集 JMX Exporter 指標。

```
   - job_name: 'kubernetes-pod-jmx'
      sample_limit: 10000
      metrics_path: /metrics
      kubernetes_sd_configs:
      - role: pod
      relabel_configs:
      - source_labels: [__address__]
        action: keep
        regex: '.*:9404$'
      - action: labelmap
        regex: __meta_kubernetes_pod_label_(.+)
      - action: replace
        source_labels:
        - __meta_kubernetes_namespace
        target_label: Namespace
      - source_labels: [__meta_kubernetes_pod_name]
        action: replace
        target_label: pod_name
      - action: replace
        source_labels:
        - __meta_kubernetes_pod_container_name
        target_label: container_name
      - action: replace
        source_labels:
        - __meta_kubernetes_pod_controller_name
        target_label: pod_controller_name
      - action: replace
        source_labels:
        - __meta_kubernetes_pod_controller_kind
        target_label: pod_controller_kind
      - action: replace
        source_labels:
        - __meta_kubernetes_pod_phase
        target_label: pod_phase
```

會湊集這些預設目標當中的各個目標，並使用內嵌的指標格式將指標傳送到日誌事件中的 CloudWatch。如需詳細資訊，請參閱[在日誌中內嵌指標](CloudWatch_Embedded_Metric_Format.md)。

來自 Amazon EKS 和 Kubernetes 叢集的日誌事件會存放在 CloudWatch Logs 中的 **/aws/containerinsights/*cluster\$1name*/prometheus** 日誌群組。來自 Amazon ECS 叢集的日誌事件會存放在 **/aws/ecs/containerinsights/*cluster\$1name*/prometheus** 日誌群組。

每個湊集任務都包含在此日誌群組的不同日誌串流中。例如，Prometheus 湊集任務 `kubernetes-pod-appmesh-envoy` 是針對 App Mesh 所定義。來自 Amazon EKS 和 Kubernetes 叢集的所有 App Mesh Prometheus 指標都會傳送至名為 **/aws/containerinsights/*cluster\$1name*>prometheus/kubernetes-pod-appmesh-envoy/** 的日誌串流。

若要新增湊集目標，請新增 `job_name` 區段到 YAML 檔案的 `scrape_configs` 區段，然後重新啟動代理程式。如需此程序的範例，請參閱[新增 Prometheus 湊集目標的教學課程：Prometheus API 伺服器指標](#ContainerInsights-Prometheus-Setup-new-exporters)。

## Prometheus 的 CloudWatch 代理程式組態
<a name="ContainerInsights-Prometheus-Setup-cw-agent-config2"></a>

CloudWatch 代理程式組態檔案在 `metrics_collected` 下有一個 `prometheus` 區段可用於 Prometheus 湊集組態。其包含下列組態選項：
+ **cluster\$1name**— 指定要在日誌事件中新增為標籤的叢集名稱。此欄位為選用欄位。如果您省略此值，代理程式可以偵測 Amazon EKS 或 Kubernetes 叢集名稱。
+ **log\$1group\$1name**— 為湊集的 Prometheus 指標指定日誌檔案群組名稱。此欄位為選用欄位。如果您省略此值，CloudWatch 會將 **/aws/containerinsights/*cluster\$1name*/prometheus** 用於來自 Amazon EKS 和 Kubernetes 叢集的日誌。
+ **prometheus\$1config\$1path**— 指定 Prometheus 湊集組態檔案路徑。如果此欄位的值以 `env:` 為開頭，則將從容器的環境變數中擷取 Prometheus 湊集組態檔案內容。請不要變更此欄位。
+ **ecs\$1service\$1discovery**— 是指定 Amazon ECS Prometheus 服務探索組態的區段。如需詳細資訊，請參閱[在 Amazon ECS 叢集上自動探索的詳細指南](ContainerInsights-Prometheus-Setup-autodiscovery-ecs.md)。

  `ecs_service_discovery` 區段可以包含下列欄位：
  + `sd_frequency` 是發現 Prometheus Exporters 的頻率。指定數字和單位尾碼。例如：每分鐘一次 `1m` 或每 30 秒`30s`一次。有效的單位尾碼為`ns`、`us`、`ms`、`s`、`m` 以及 `h`。

    此欄位為選用欄位。預設值為 60 秒 (1 分鐘)。
  + `sd_target_cluster` 是用於自動探索的目標 Amazon ECS 叢集名稱。此欄位為選用欄位。預設是安裝 CloudWatch 代理程式的 Amazon ECS 叢集名稱。
  + `sd_cluster_region` 是目標 Amazon ECS 叢集的區域。此欄位為選用欄位。預設是安裝 CloudWatch 代理程式的 Amazon ECS 叢集區域。
  + `sd_result_file` 是 Prometheus 目標結果的 YAML 檔案路徑。Prometheus 湊集組態將參與此檔案。
  + `docker_label` 是選用區段，您可以用它來指定 Docker 標籤型服務探索的組態。如果您省略此區段，則不會使用 Docker 標籤型探索。此區段可以包含下列欄位：
    + `sd_port_label` 是容器的 Docker 標籤名稱，用於指定 Prometheus 指標的容器連接埠。預設值為 `ECS_PROMETHEUS_EXPORTER_PORT`。如果容器沒有此 Docker 標籤，CloudWatch 代理程式將略過它。
    + `sd_metrics_path_label` 是容器的 Docker 標籤名稱，用於指定 Prometheus 指標路徑。預設值為 `ECS_PROMETHEUS_METRICS_PATH`。如果容器沒有此 Docker 標籤，則代理程式會假設預設路徑 `/metrics`。
    + `sd_job_name_label` 是容器的 Docker 標籤名稱，用於指定 Prometheus 湊集任務名稱。預設值為 `job`。如果容器沒有此 Docker 標籤，CloudWatch 代理程式會在 Prometheus 湊集組態中使用任務名稱。
  + `task_definition_list` 是選用區段，您可以用它來指定任務定義型服務探索的組態。如果您省略此區段，則不會使用任務定義型探索。此區段可以包含下列欄位：
    + `sd_task_definition_arn_pattern` 是用來指定要探索的 Amazon ECS 任務定義的模式。這是規則表達式。
    + `sd_metrics_ports` 列出了 Prometheus 指標的 containerPort。使用分號分隔 containerPorts。
    + `sd_container_name_pattern` 指定了 Amazon ECS 任務容器名稱。這是規則表達式。
    + `sd_metrics_path` 指定了 Prometheus 指標路徑。如果您省略此項，代理程式會假設預設路徑 `/metrics`
    + `sd_job_name` 指定了 Prometheus 湊集任務名稱。如果您省略此欄位，CloudWatch 代理程式會使用 Prometheus 湊集組態中的任務名稱。
+ **metric\$1declaration**— 是以要產生之內嵌指標格式來指定日誌陣列的區段。根據預設，CloudWatch 代理程式匯入的每個 Prometheus 來源都有 `metric_declaration` 區段。這些區段各包括下列欄位：
  + `label_matcher` 是一個規則表達式，會檢查 `source_labels` 中列出的標籤值。符合的指標已啟用，可包含在傳送至 CloudWatch 的內嵌指標格式。

    如果您在 `source_labels` 中指定了多個標籤，我們建議您不要在 `label_matcher` 的規則表達式中使用 `^` 或 `$` 字元。
  + `source_labels` 指定由 `label_matcher` 行檢查的標籤值。
  + `label_separator` 指定要在 ` label_matcher` 行中使用的分隔符號 (如果指定多個 `source_labels`)。預設值為 `;`。您可以在下面的範例中看到 `label_matcher` 行中使用此預設值。
  + `metric_selectors` 是一個規則表達式，可指定要收集和傳送至 CloudWatch 的指標。
  + `dimensions` 是要用作為每個所選指標之 CloudWatch 維度的標籤清單。

請參閱以下 `metric_declaration` 範例。

```
"metric_declaration": [
  {
     "source_labels":[ "Service", "Namespace"],
     "label_matcher":"(.*node-exporter.*|.*kube-dns.*);kube-system",
     "dimensions":[
        ["Service", "Namespace"]
     ],
     "metric_selectors":[
        "^coredns_dns_request_type_count_total$"
     ]
  }
]
```

此範例會在符合下列條件時，設定內嵌指標格式區段，以作為日誌事件傳送：
+ `Service` 的數值包含 `node-exporter` 或 `kube-dns`。
+ `Namespace` 的值為 `kube-system`。
+ Prometheus 指標 `coredns_dns_request_type_count_total` 包含 `Service` 和 `Namespace` 標籤。

傳送的日誌事件包含下列反白顯示的區段：

```
{
   "CloudWatchMetrics":[
      {
         "Metrics":[
            {
               "Name":"coredns_dns_request_type_count_total"
            }
         ],
         "Dimensions":[
            [
               "Namespace",
               "Service"
            ]
         ],
         "Namespace":"ContainerInsights/Prometheus"
      }
   ],
   "Namespace":"kube-system",
   "Service":"kube-dns",
   "coredns_dns_request_type_count_total":2562,
   "eks_amazonaws_com_component":"kube-dns",
   "instance":"192.168.61.254:9153",
   "job":"kubernetes-service-endpoints",
   ...
}
```

## 新增 Prometheus 湊集目標的教學課程：Prometheus API 伺服器指標
<a name="ContainerInsights-Prometheus-Setup-new-exporters"></a>

Kubernetes API 伺服器預設會在端點上公開 Prometheus 指標。Kubernetes API 伺服器湊集組態的官方範例可以在 [Github](https://github.com/prometheus/prometheus/blob/main/documentation/examples/prometheus-kubernetes.yml) 上取得。

下列教學說明如何執行下列步驟，開始將 Kubernetes API 伺服器指標匯入 CloudWatch：
+ 將 Kubernetes API 伺服器的 Prometheus 湊集組態新增至 CloudWatch 代理程式 YAML 檔案。
+ 在 CloudWatch 代理程式 YAML 檔案中設定內嵌指標格式指標定義。
+ (選用) 為 Kubernetes API 伺服器指標建立 CloudWatch 儀表板。

**注意**  
Kubernetes API 伺服器會公開量測、計數器、長條圖和摘要指標。在此版本的 Prometheus 指標支援中，CloudWatch 僅會匯入具有量測計、計數器和摘要類型的指標。

**若要開始在 CloudWatch 中收集 Kubernetes API 伺服器 Prometheus 指標**

1. 輸入下列其中一個命令，以下載最新版本的 `prometheus-eks.yaml`、`prometheus-eks-fargate.yaml` 或 `prometheus-k8s.yaml` 檔案。

   對於具有 EC2 啟動類型的 Amazon EKS 叢集，請輸入下列命令：

   ```
   curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/prometheus-eks.yaml
   ```

   對於具有 Fargate 啟動類型的 Amazon EKS 叢集，請輸入下列命令：

   ```
   curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/prometheus-eks-fargate.yaml
   ```

   對於在 Amazon EC2 執行個體上執行的 Kubernetes 叢集，請輸入下列命令：

   ```
   curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/prometheus-k8s.yaml
   ```

1. 使用文字編輯器開啟檔案，找出 `prometheus-config` 區段，並在該區段內新增以下區段。儲存變更：

   ```
       # Scrape config for API servers
       - job_name: 'kubernetes-apiservers'
         kubernetes_sd_configs:
           - role: endpoints
             namespaces:
               names:
                 - default
         scheme: https
         tls_config:
           ca_file: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
           insecure_skip_verify: true
         bearer_token_file: /var/run/secrets/kubernetes.io/serviceaccount/token
         relabel_configs:
         - source_labels: [__meta_kubernetes_service_name, __meta_kubernetes_endpoint_port_name]
           action: keep
           regex: kubernetes;https
         - action: replace
           source_labels:
           - __meta_kubernetes_namespace
           target_label: Namespace
         - action: replace
           source_labels:
           - __meta_kubernetes_service_name
           target_label: Service
   ```

1. 趁文字編輯器中開啟 YAML 檔案時，找出 `cwagentconfig.json` 區段。新增下列子區段並儲存變更。此區段會將 API 伺服器指標放到 CloudWatch 代理程式允許清單上。允許清單中會新增三種類型的 API 伺服器指標：
   + etcd 物件計數
   + API 伺服器註冊控制器指標
   + API 伺服器請求指標

   ```
   {"source_labels": ["job", "resource"],
     "label_matcher": "^kubernetes-apiservers;(services|daemonsets.apps|deployments.apps|configmaps|endpoints|secrets|serviceaccounts|replicasets.apps)",
     "dimensions": [["ClusterName","Service","resource"]],
     "metric_selectors": [
     "^etcd_object_counts$"
     ]
   },
   {"source_labels": ["job", "name"],
      "label_matcher": "^kubernetes-apiservers;APIServiceRegistrationController$",
      "dimensions": [["ClusterName","Service","name"]],
      "metric_selectors": [
      "^workqueue_depth$",
      "^workqueue_adds_total$",
      "^workqueue_retries_total$"
     ]
   },
   {"source_labels": ["job","code"],
     "label_matcher": "^kubernetes-apiservers;2[0-9]{2}$",
     "dimensions": [["ClusterName","Service","code"]],
     "metric_selectors": [
      "^apiserver_request_total$"
     ]
   },
   {"source_labels": ["job"],
     "label_matcher": "^kubernetes-apiservers",
     "dimensions": [["ClusterName","Service"]],
     "metric_selectors": [
     "^apiserver_request_total$"
     ]
   },
   ```

1. 如果您已在叢集中部署具有 Prometheus 支援的 CloudWatch 代理程式，則必須輸入下列命令來刪除它：

   ```
   kubectl delete deployment cwagent-prometheus -n amazon-cloudwatch
   ```

1. 輸入下列其中一個命令，以更新的組態來部署 CloudWatch 代理程式：對於具有 EC2 啟動類型的 Amazon EKS 叢集，請輸入：

   ```
   kubectl apply -f prometheus-eks.yaml
   ```

   對於具有 Fargate 啟動類型的 Amazon EKS 叢集，請輸入下列命令。將 *MyCluster* 和 *region* 取代為可比對部署的數值。

   ```
   cat prometheus-eks-fargate.yaml \
   | sed "s/{{cluster_name}}/MyCluster/;s/{{region_name}}/region/" \
   | kubectl apply -f -
   ```

   對於 Kubernetes 叢集，請輸入下列命令。將 *MyCluster* 和 *region* 取代為可比對部署的數值。

   ```
   cat prometheus-k8s.yaml \
   | sed "s/{{cluster_name}}/MyCluster/;s/{{region_name}}/region/" \
   | kubectl apply -f -
   ```

完成此操作後，您應該在 **/aws/containerinsights/*cluster\$1name*/prometheus** 日誌群組中查看名為** kubernetes-apiservers **的新日誌串流。此日誌串流應該包含具有內嵌指標格式定義的日誌事件，如下所示：

```
{
   "CloudWatchMetrics":[
      {
         "Metrics":[
            {
               "Name":"apiserver_request_total"
            }
         ],
         "Dimensions":[
            [
               "ClusterName",
               "Service"
            ]
         ],
         "Namespace":"ContainerInsights/Prometheus"
      }
   ],
   "ClusterName":"my-cluster-name",
   "Namespace":"default",
   "Service":"kubernetes",
   "Timestamp":"1592267020339",
   "Version":"0",
   "apiserver_request_count":0,
   "apiserver_request_total":0,
   "code":"0",
   "component":"apiserver",
   "contentType":"application/json",
   "instance":"192.0.2.0:443",
   "job":"kubernetes-apiservers",
   "prom_metric_type":"counter",
   "resource":"pods",
   "scope":"namespace",
   "verb":"WATCH",
   "version":"v1"
}
```

您可以在 **ContainerInsights/Prometheus** 命名空間中的 CloudWatch 主控台中，檢視您的指標。您也可以選擇為您的 Prometheus Kubernetes API 伺服器指標建立 CloudWatch 儀表板。

### (選用) 為 Kubernetes API 伺服器指標建立儀表板。
<a name="ContainerInsights-Prometheus-Setup-KPI-dashboard"></a>

若要在儀表板中查看 Kubernetes API 伺服器指標，您必須先完成先前章節中的步驟，才能開始在 CloudWatch 中收集這些指標。

**若要建立 Kubernetes API 伺服器指標的儀表板**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 請確定您已選取正確的 AWS 區域。

1. 在導覽窗格中，選擇 **Dashboards** (儀表板)。

1. 選擇 **Create Dashboard (建立儀表板)**。輸入新儀表板的名稱，然後選擇 **Create dashboard (建立儀表板)**。

1. 在 **Add to this dashboard (新增至此儀表板)** 中，選擇 **Cancel (取消)**。

1. 選擇 **Actions (動作)**、**View/edit sources (檢視/編輯來源)**。

1. 下載下列 JSON 檔案：[Kubernetes API 儀表板來源](https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/sample_cloudwatch_dashboards/kubernetes_api_server/cw_dashboard_kubernetes_api_server.json)。

1. 使用文字編輯器開啟您下載的 JSON 檔案，然後進行下列變更：
   + 將所有 `{{YOUR_CLUSTER_NAME}}` 字串取代為您叢集的確切名稱。確定不要在文字前後加空格。
   + 將所有 `{{YOUR_AWS_REGION}}` 字串取代為收集指標的區域的名稱。例如 `us-west-2`。確定不要在文字前後加空格。

1. 複製整個 JSON blob 並將其貼入 CloudWatch 主控台的文字方塊中，取代方塊中已經存在的內容。

1. 選擇 **Update (更新)**、**Save dashboard (儲存儀表板)**。

# (選用) 設定範例容器化 Amazon EKS 工作負載範例進行 Prometheus 指標測試
<a name="ContainerInsights-Prometheus-Sample-Workloads"></a>

若要測試 CloudWatch Container Insights 中的 Prometheus 指標支援，您可以設定下列一或多個容器化工作負載。具有 Prometheus 支援的 CloudWatch 代理程式會自動從這些工作負載收集指標。若要查看預設收集的指標，請參閱 [CloudWatch 代理程式收集的 Prometheus 指標](ContainerInsights-Prometheus-metrics.md)。

在安裝這些工作負載之前，您必須先輸入下列命令來安裝 Helm 3.x：

```
brew install helm
```

如需詳細資訊，請參閱 [Helm](https://helm.sh)。

**Topics**
+ [設定 Amazon EKS 和 Kubernetes AWS App Mesh 的範例工作負載](ContainerInsights-Prometheus-Sample-Workloads-appmesh.md)
+ [在 Amazon EKS 和 Kubernetes 上使用範例流量設定 NGINX](ContainerInsights-Prometheus-Sample-Workloads-nginx.md)
+ [在 Amazon EKS 和 Kubernetes 上使用指標匯出工具設定 memcached](ContainerInsights-Prometheus-Sample-Workloads-memcached.md)
+ [設定適用於 Amazon EKS 和 Kubernetes 的 Java/JMX 範例工作負載](ContainerInsights-Prometheus-Sample-Workloads-javajmx.md)
+ [在 Amazon EKS 和 Kubernetes 上使用指標匯出工具設定 HAProxy](ContainerInsights-Prometheus-Sample-Workloads-haproxy.md)
+ [新增 Prometheus 湊集目標的教學課程：Amazon EKS 和 Kubernetes 叢集上的 Redis OSS](ContainerInsights-Prometheus-Setup-redis-eks.md)

# 設定 Amazon EKS 和 Kubernetes AWS App Mesh 的範例工作負載
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh"></a>

CloudWatch Container Insights 中的 Prometheus 支援可支援 AWS App Mesh。以下各節說明如何設定 App Mesh。

**Topics**
+ [在具有 EC2 啟動類型或 Kubernetes 叢集的 Amazon EKS 叢集上設定 AWS App Mesh 範例工作負載](ContainerInsights-Prometheus-Sample-Workloads-appmesh-EKS.md)
+ [在具有 Fargate 啟動類型的 Amazon EKS 叢集上設定 AWS App Mesh 範例工作負載](ContainerInsights-Prometheus-Sample-Workloads-appmesh-Fargate.md)

# 在具有 EC2 啟動類型或 Kubernetes 叢集的 Amazon EKS 叢集上設定 AWS App Mesh 範例工作負載
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh-EKS"></a>

如果您要在執行 Amazon EKS 且具有 EC2 啟動類型的叢集或 Kubernetes 叢集上設定 App Mesh，請使用這些指示。

## 設定 IAM 許可
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh-iam"></a>

您必須將 **AWSAppMeshFullAccess** 政策新增至您的 Amazon EKS 或 Kubernetes 節點群組的 IAM 角色。在 Amazon EKS 上，此節點群組名稱看起來類似於 `eksctl-integ-test-eks-prometheus-NodeInstanceRole-ABCDEFHIJKL`。在 Kubernetes 上，它可能看起來類似於 `nodes.integ-test-kops-prometheus.k8s.local`.

## 安裝 App Mesh
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh-install"></a>

若要安裝 App Mesh Kubernetes 控制器，請遵循 [App Mesh 控制器](https://github.com/aws/eks-charts/tree/master/stable/appmesh-controller#app-mesh-controller)中的說明進行。

## 安裝範例應用程式
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh-application"></a>

[aws-app-mesh-examples](https://github.com/aws/aws-app-mesh-examples) 包含數個 Kubernetes App Mesh 演練。在本教學課程中，您將安裝一個範例色彩應用程式，該應用程式顯示 http 路由如何使用標頭來比對傳入的請求。

**若要使用範例 App Mesh 應用程式來測試 Container Insights**

1. 使用這些指示安裝應用程式：[https://github.com/aws/aws-app-mesh-examples/tree/main/walkthroughs/howto-k8s-http-headers](https://github.com/aws/aws-app-mesh-examples/tree/main/walkthroughs/howto-k8s-http-headers)。

1. 啟動 curler pod 以產生流量：

   ```
   kubectl -n default run -it curler --image=tutum/curl /bin/bash
   ```

1. 透過變更 HTTP 標頭來 Curl 不同的端點。多次執行 curl 命令，如此處所示：

   ```
   curl -H "color_header: blue" front.howto-k8s-http-headers.svc.cluster.local:8080/; echo;
   
   curl -H "color_header: red" front.howto-k8s-http-headers.svc.cluster.local:8080/; echo;
   
   curl -H "color_header: yellow" front.howto-k8s-http-headers.svc.cluster.local:8080/; echo;
   ```

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在叢集執行的 AWS 區域中，選擇導覽窗格中**的指標**。指標位於 **ContainerInsights/Prometheus** 命名空間中。

1. 若要查看 CloudWatch Logs 事件，請在導覽窗格中選擇 **Log groups** (日誌群組)。事件位於日誌串流 `kubernetes-pod-appmesh-envoy` 中的 日誌群組 ` /aws/containerinsights/your_cluster_name/prometheus ` 中。

## 刪除 App Mesh 測試環境
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh-delete"></a>

當您使用完 App Mesh 和範例應用程式時，請使用以下命令刪除不必要的資源。輸入下列命令以刪除範例應用程式：

```
cd aws-app-mesh-examples/walkthroughs/howto-k8s-http-headers/
kubectl delete -f _output/manifest.yaml
```

輸入以下命令以刪除 App Mesh 控制器：

```
helm delete appmesh-controller -n appmesh-system
```

# 在具有 Fargate 啟動類型的 Amazon EKS 叢集上設定 AWS App Mesh 範例工作負載
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh-Fargate"></a>

如果您要在執行 Amazon EKS 且具有 Fargate 啟動類型的叢集上設定 App Mesh，請使用這些指示。

## 設定 IAM 許可
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh--fargate-iam"></a>

若要設定 IAM 許可，請輸入以下命令。將 *MyCluster* 取代為您的叢集名稱。

```
eksctl create iamserviceaccount --cluster MyCluster \
 --namespace howto-k8s-fargate \
 --name appmesh-pod \
 --attach-policy-arn arn:aws:iam::aws:policy/AWSAppMeshEnvoyAccess \
 --attach-policy-arn arn:aws:iam::aws:policy/AWSCloudMapDiscoverInstanceAccess \
 --attach-policy-arn arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess \
 --attach-policy-arn arn:aws:iam::aws:policy/CloudWatchLogsFullAccess \
 --attach-policy-arn arn:aws:iam::aws:policy/AWSAppMeshFullAccess \
 --attach-policy-arn arn:aws:iam::aws:policy/AWSCloudMapFullAccess \
 --override-existing-serviceaccounts \
 --approve
```

## 安裝 App Mesh
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh-fargate-install"></a>

若要安裝 App Mesh Kubernetes 控制器，請遵循 [App Mesh 控制器](https://github.com/aws/eks-charts/tree/master/stable/appmesh-controller#app-mesh-controller)中的說明進行。對於具有 Fargate 啟動類型的 Amazon EKS，請務必遵循指示。

## 安裝範例應用程式
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh-fargate-application"></a>

[aws-app-mesh-examples](https://github.com/aws/aws-app-mesh-examples) 包含數個 Kubernetes App Mesh 演練。在本教學課程中，您將安裝適用於具有 Fargate 啟動類型的 Amazon EKS 叢集的範例色彩應用程式。

**若要使用範例 App Mesh 應用程式來測試 Container Insights**

1. 使用這些指示安裝應用程式：[https://github.com/aws/aws-app-mesh-examples/tree/main/walkthroughs/howto-k8s-fargate](https://github.com/aws/aws-app-mesh-examples/tree/main/walkthroughs/howto-k8s-fargate)。

   這些指示假設您正在建立一個具有正確 Fargate 設定檔的新叢集。對於此示範，如果您想要使用已經設定的 Amazon EKS 叢集，可以使用下列命令來設定該叢集。將 *MyCluster* 取代為您的叢集名稱。

   ```
   eksctl create iamserviceaccount --cluster MyCluster \
    --namespace howto-k8s-fargate \
    --name appmesh-pod \
    --attach-policy-arn arn:aws:iam::aws:policy/AWSAppMeshEnvoyAccess \
    --attach-policy-arn arn:aws:iam::aws:policy/AWSCloudMapDiscoverInstanceAccess \
    --attach-policy-arn arn:aws:iam::aws:policy/AWSXRayDaemonWriteAccess \
    --attach-policy-arn arn:aws:iam::aws:policy/CloudWatchLogsFullAccess \
    --attach-policy-arn arn:aws:iam::aws:policy/AWSAppMeshFullAccess \
    --attach-policy-arn arn:aws:iam::aws:policy/AWSCloudMapFullAccess \
    --override-existing-serviceaccounts \
    --approve
   ```

   ```
   eksctl create fargateprofile --cluster MyCluster \
   --namespace howto-k8s-fargate --name howto-k8s-fargate
   ```

1. 前端應用程式部署的連接埠：

   ```
   kubectl -n howto-k8s-fargate port-forward deployment/front 8080:8080
   ```

1. Curl 前端應用程式：

   ```
   while true; do  curl -s http://localhost:8080/color; sleep 0.1; echo ; done
   ```

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在叢集執行的 AWS 區域中，選擇導覽窗格中**的指標**。指標位於 **ContainerInsights/Prometheus** 命名空間中。

1. 若要查看 CloudWatch Logs 事件，請在導覽窗格中選擇 **Log groups** (日誌群組)。事件位於日誌串流 `kubernetes-pod-appmesh-envoy` 中的 日誌群組 ` /aws/containerinsights/your_cluster_name/prometheus ` 中。

## 刪除 App Mesh 測試環境
<a name="ContainerInsights-Prometheus-Sample-Workloads-appmesh-fargate-delete"></a>

當您使用完 App Mesh 和範例應用程式時，請使用以下命令刪除不必要的資源。輸入下列命令以刪除範例應用程式：

```
cd aws-app-mesh-examples/walkthroughs/howto-k8s-fargate/
kubectl delete -f _output/manifest.yaml
```

輸入以下命令以刪除 App Mesh 控制器：

```
helm delete appmesh-controller -n appmesh-system
```

# 在 Amazon EKS 和 Kubernetes 上使用範例流量設定 NGINX
<a name="ContainerInsights-Prometheus-Sample-Workloads-nginx"></a>

NGINX 是一部 Web 伺服器，可同時用作為負載平衡器和反向代理。如需如何使用 NGINX 進行擷取的詳細資訊，請參閱 [kubernetes/ingress-nginx](https://github.com/kubernetes/ingress-nginx)。

**使用範例流量服務安裝 Ingress-NGINX 以測試 Container Insights Prometheus 支援**

1. 輸入以下命令來新增 Helm ingress-nginx 儲存庫：

   ```
   helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
   ```

1. 輸入下列命令：

   ```
   kubectl create namespace nginx-ingress-sample
   
   helm install my-nginx ingress-nginx/ingress-nginx \
   --namespace nginx-ingress-sample \
   --set controller.metrics.enabled=true \
   --set-string controller.metrics.service.annotations."prometheus\.io/port"="10254" \
   --set-string controller.metrics.service.annotations."prometheus\.io/scrape"="true"
   ```

1. 請輸入下列命令，檢查服務是否已正確啟動：

   ```
   kubectl get service -n nginx-ingress-sample
   ```

   這個命令的輸出應該會顯示數欄，包括一個 `EXTERNAL-IP` 欄。

1. 將 `EXTERNAL-IP` 變數設定為 NGINX 傳入控制器一行中 `EXTERNAL-IP` 欄的數值。

   ```
   EXTERNAL_IP=your-nginx-controller-external-ip
   ```

1. 輸入以下命令啟動一些範例 NGINX 流量。

   ```
   SAMPLE_TRAFFIC_NAMESPACE=nginx-sample-traffic
   curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/sample_traffic/nginx-traffic/nginx-traffic-sample.yaml | 
   sed "s/{{external_ip}}/$EXTERNAL_IP/g" | 
   sed "s/{{namespace}}/$SAMPLE_TRAFFIC_NAMESPACE/g" | 
   kubectl apply -f -
   ```

1. 輸入下列命令以確認三個 pod 全都處於 `Running` 狀態。

   ```
   kubectl get pod -n $SAMPLE_TRAFFIC_NAMESPACE
   ```

   如果它們正在執行，您應該很快就會在 **ContainerInsights/Prometheus** 命名空間中看到指標。

**解除安裝 NGINX 和範例流量應用程式**

1. 輸入下列命令以刪除範例流量服務：

   ```
   kubectl delete namespace $SAMPLE_TRAFFIC_NAMESPACE
   ```

1. 刪除 Helm 發行版本名稱的 NGINX egress。

   ```
   helm uninstall my-nginx --namespace nginx-ingress-sample
   kubectl delete namespace nginx-ingress-sample
   ```

# 在 Amazon EKS 和 Kubernetes 上使用指標匯出工具設定 memcached
<a name="ContainerInsights-Prometheus-Sample-Workloads-memcached"></a>

memcached 是一個開放原始碼記憶體物件快取系統。如需詳細資訊，請參閱[什麼是 Memcached？](https://www.memcached.org)。

如果您在具有 Fargate 啟動類型的叢集上執行 memcached，則需要在執行此程序中的步驟之前設定 Fargate 描述檔。若要設定描述檔，請輸入下列命令。將 *MyCluster* 取代為您的叢集名稱。

```
eksctl create fargateprofile --cluster MyCluster \
--namespace memcached-sample --name memcached-sample
```

**使用指標匯出工具安裝 memcached，以測試 Container Insights Prometheus 支援**

1. 輸入以下命令來新增儲存庫：

   ```
   helm repo add bitnami https://charts.bitnami.com/bitnami
   ```

1. 輸入以下命令來建立新的命名空間：

   ```
   kubectl create namespace memcached-sample
   ```

1. 輸入下列命令以安裝 Memcached

   ```
   helm install my-memcached bitnami/memcached --namespace memcached-sample \
   --set metrics.enabled=true \
   --set-string serviceAnnotations.prometheus\\.io/port="9150" \
   --set-string serviceAnnotations.prometheus\\.io/scrape="true"
   ```

1. 輸入下列命令以確認執行中服務的註釋：

   ```
   kubectl describe service my-memcached-metrics -n memcached-sample
   ```

   您應該會看到下列兩個註釋：

   ```
   Annotations:   prometheus.io/port: 9150
                  prometheus.io/scrape: true
   ```

**解除安裝 memcached**
+ 輸入下列命令：

  ```
  helm uninstall my-memcached --namespace memcached-sample
  kubectl delete namespace memcached-sample
  ```

# 設定適用於 Amazon EKS 和 Kubernetes 的 Java/JMX 範例工作負載
<a name="ContainerInsights-Prometheus-Sample-Workloads-javajmx"></a>

JMX Exporter 是官方的 Prometheus 匯出工具，可以湊集 JMX mBeans 並將其公開為 Prometheus 指標。如需詳細資訊，請參閱 [prometheus/jmx\$1exporter](https://github.com/prometheus/jmx_exporter)。

Container Insights 可以使用 JMX Exporter，從 Java 虛擬機器 (JVM)、Java 和 Tomcat (Catalina) 收集預先定義的 Prometheus 指標。

## 預設 Prometheus 湊集組態
<a name="ContainerInsights-Prometheus-Sample-Workloads-javajmx-default"></a>

根據預設，具有 Prometheus 支援的 CloudWatch 代理程式會從 Amazon EKS 或 Kubernetes 叢集中的每個 pod 上的 `http://CLUSTER_IP:9404/metrics` 湊集 Java/JMX Prometheus 指標。這是透過會由 Prometheus `kubernetes_sd_config` 的 `role: pod` 探索的。9404 是 Prometheus 為 JMX Exporter 配置的預設連接埠。如需 `role: pod` 探索的詳細資訊，請參閱 [pod](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#pod)。您可以設定 JMX Exporter 在不同的連接埠或 metrics\$1path 上公開指標。如果您確實變更連接埠或路徑，請更新 CloudWatch 代理程式組態映射中的預設 jmx scrape\$1config。請執行下列命令以取得目前的 CloudWatch 代理程式 Prometheus 組態：

```
kubectl describe cm prometheus-config -n amazon-cloudwatch
```

要變更的欄位為 `/metrics` 和 `regex: '.*:9404$'` 欄位，如下列範例中反白所示。

```
job_name: 'kubernetes-jmx-pod'
sample_limit: 10000
metrics_path: /metrics
kubernetes_sd_configs:
- role: pod
relabel_configs:
- source_labels: [__address__]
  action: keep
  regex: '.*:9404$'
- action: replace
  regex: (.+)
  source_labels:
```

## 其他 Prometheus 湊集組態
<a name="ContainerInsights-Prometheus-Sample-Workloads-javajmx-other"></a>

如果您透過 Kubernetes Service 使用 Java/JMX Prometheus 匯出工具公開在一組 Pod 上執行的應用程式，則還可以切換到使用 `role: service` 探索或 Prometheus `kubernetes_sd_config` 的 `role: endpoint` 探索。如需這些探索方法的詳細資訊，請參閱[服務](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#service)、[端點](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#endpoints)和 [<kubernetes\$1sd\$1config>](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#kubernetes_sd_config)。

這兩種服務探索模式提供了多個中繼標籤，而這可能對您建置 CloudWatch 指標維度非常有用。例如，您可以重新標記 `__meta_kubernetes_service_name` 至 `Service`，並將其包含在您的指標維度中。如需自訂 CloudWatch 指標及其維度的詳細資訊，請參閱 [Prometheus 的 CloudWatch 代理程式組態](ContainerInsights-Prometheus-Setup-configure-ECS.md#ContainerInsights-Prometheus-Setup-cw-agent-config)。

## Docker 影像與 JMX Exporter
<a name="ContainerInsights-Prometheus-Sample-Workloads-javajmx-docker"></a>

下一步：建置 Docker 影像 下列各節提供兩個範例 Dockerfile。

當您建置映像後，請將它載入 Amazon EKS 或 Kubernetes，然後執行下列命令，以確認 `JMX_EXPORTER` 是在連接埠 9404 上公開 Prometheus 指標。將 *\$1JAR\$1SAMPLE\$1TRAFFIC\$1POD* 取代為執行中的 pod 名稱，並將 *\$1JAR\$1SAMPLE\$1TRAFFIC\$1NAMESPACE* 取代為您的應用程式命名空間。

如果您在具有 Fargate 啟動類型的叢集上執行 JMX Exporter，則還需要在執行此程序中的步驟之前設定 Fargate 描述檔。若要設定描述檔，請輸入下列命令。將 *MyCluster* 取代為您的叢集名稱。

```
eksctl create fargateprofile --cluster MyCluster \
--namespace $JAR_SAMPLE_TRAFFIC_NAMESPACE\
 --name $JAR_SAMPLE_TRAFFIC_NAMESPACE
```

```
kubectl exec $JAR_SAMPLE_TRAFFIC_POD -n $JARCAT_SAMPLE_TRAFFIC_NAMESPACE -- curl http://localhost:9404
```

## 範例：具有 Prometheus 指標的 Apache Tomcat Docker 影像
<a name="ContainerInsights-Prometheus-Sample-Workloads-javajmx-tomcat"></a>

Apache Tomcat 伺服器預設會公開 JMX mBeans。您可以將 JMX Exporter 與 Tomcat 整合，以將 JMX mBeans 公開為 Prometheus 指標。下列範例 Dockerfile 顯示建置測試映像的步驟：

```
# From Tomcat 9.0 JDK8 OpenJDK 
FROM tomcat:9.0-jdk8-openjdk 

RUN mkdir -p /opt/jmx_exporter

COPY ./jmx_prometheus_javaagent-0.12.0.jar /opt/jmx_exporter
COPY ./config.yaml /opt/jmx_exporter
COPY ./setenv.sh /usr/local/tomcat/bin 
COPY your web application.war /usr/local/tomcat/webapps/

RUN chmod  o+x /usr/local/tomcat/bin/setenv.sh

ENTRYPOINT ["catalina.sh", "run"]
```

下列清單解釋了這個 Dockerfile 的四個 `COPY` 行。
+ 從 [https://github.com/prometheus/jmx\$1exporter](https://github.com/prometheus/jmx_exporter) 下載最新的 JMX Exporter jar 檔案。
+ `config.yaml` 是 JMX Exporter 組態檔。如需詳細資訊，請參閱 [https://github.com/prometheus/jmx\$1exporter\$1Configuration](https://github.com/prometheus/jmx_exporter#Configuration )。

  以下是 Java 和 Tomcat 的範例組態檔：

  ```
  lowercaseOutputName: true
  lowercaseOutputLabelNames: true
  
  rules:
  - pattern: 'java.lang<type=OperatingSystem><>(FreePhysicalMemorySize|TotalPhysicalMemorySize|FreeSwapSpaceSize|TotalSwapSpaceSize|SystemCpuLoad|ProcessCpuLoad|OpenFileDescriptorCount|AvailableProcessors)'
    name: java_lang_OperatingSystem_$1
    type: GAUGE
  
  - pattern: 'java.lang<type=Threading><>(TotalStartedThreadCount|ThreadCount)'
    name: java_lang_threading_$1
    type: GAUGE
  
  - pattern: 'Catalina<type=GlobalRequestProcessor, name=\"(\w+-\w+)-(\d+)\"><>(\w+)'
    name: catalina_globalrequestprocessor_$3_total
    labels:
      port: "$2"
      protocol: "$1"
    help: Catalina global $3
    type: COUNTER
  
  - pattern: 'Catalina<j2eeType=Servlet, WebModule=//([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), name=([-a-zA-Z0-9+/$%~_-|!.]*), J2EEApplication=none, J2EEServer=none><>(requestCount|maxTime|processingTime|errorCount)'
    name: catalina_servlet_$3_total
    labels:
      module: "$1"
      servlet: "$2"
    help: Catalina servlet $3 total
    type: COUNTER
  
  - pattern: 'Catalina<type=ThreadPool, name="(\w+-\w+)-(\d+)"><>(currentThreadCount|currentThreadsBusy|keepAliveCount|pollerThreadCount|connectionCount)'
    name: catalina_threadpool_$3
    labels:
      port: "$2"
      protocol: "$1"
    help: Catalina threadpool $3
    type: GAUGE
  
  - pattern: 'Catalina<type=Manager, host=([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), context=([-a-zA-Z0-9+/$%~_-|!.]*)><>(processingTime|sessionCounter|rejectedSessions|expiredSessions)'
    name: catalina_session_$3_total
    labels:
      context: "$2"
      host: "$1"
    help: Catalina session $3 total
    type: COUNTER
  
  - pattern: ".*"
  ```
+ `setenv.sh` 是一個 Tomcat 啟動指令碼，用於啟動 JMX Exporter 和 Tomcat，並在 localhost 的連接埠 9404 上公開 Prometheus 指標。它還為 JMX Exporter 提供了 `config.yaml` 檔案路徑。

  ```
  $ cat setenv.sh 
  export JAVA_OPTS="-javaagent:/opt/jmx_exporter/jmx_prometheus_javaagent-0.12.0.jar=9404:/opt/jmx_exporter/config.yaml $JAVA_OPTS"
  ```
+ 您的 Web 應用程式 .war 是您要由 Tomcat 載入的 Web 應用程式 `war` 檔案。

使用此組態建置一個 Docker 影像並將其上傳到映像儲存庫。

## 範例：具有 Prometheus 指標的 Java Jar 應用程式 Docker 影像
<a name="ContainerInsights-Prometheus-Sample-Workloads-javajmx-jar"></a>

下列範例 Dockerfile 顯示建置測試映像的步驟：

```
# Alpine Linux with OpenJDK JRE
FROM openjdk:8-jre-alpine

RUN mkdir -p /opt/jmx_exporter

COPY ./jmx_prometheus_javaagent-0.12.0.jar /opt/jmx_exporter
COPY ./SampleJavaApplication-1.0-SNAPSHOT.jar /opt/jmx_exporter
COPY ./start_exporter_example.sh /opt/jmx_exporter
COPY ./config.yaml /opt/jmx_exporter

RUN chmod -R o+x /opt/jmx_exporter
RUN apk add curl

ENTRYPOINT exec /opt/jmx_exporter/start_exporter_example.sh
```

下列清單解釋了這個 Dockerfile 的四個 `COPY` 行。
+ 從 [https://github.com/prometheus/jmx\$1exporter](https://github.com/prometheus/jmx_exporter) 下載最新的 JMX Exporter jar 檔案。
+ `config.yaml` 是 JMX Exporter 組態檔。如需詳細資訊，請參閱 [https://github.com/prometheus/jmx\$1exporter\$1Configuration](https://github.com/prometheus/jmx_exporter#Configuration )。

  以下是 Java 和 Tomcat 的範例組態檔：

  ```
  lowercaseOutputName: true
  lowercaseOutputLabelNames: true
  
  rules:
  - pattern: 'java.lang<type=OperatingSystem><>(FreePhysicalMemorySize|TotalPhysicalMemorySize|FreeSwapSpaceSize|TotalSwapSpaceSize|SystemCpuLoad|ProcessCpuLoad|OpenFileDescriptorCount|AvailableProcessors)'
    name: java_lang_OperatingSystem_$1
    type: GAUGE
  
  - pattern: 'java.lang<type=Threading><>(TotalStartedThreadCount|ThreadCount)'
    name: java_lang_threading_$1
    type: GAUGE
  
  - pattern: 'Catalina<type=GlobalRequestProcessor, name=\"(\w+-\w+)-(\d+)\"><>(\w+)'
    name: catalina_globalrequestprocessor_$3_total
    labels:
      port: "$2"
      protocol: "$1"
    help: Catalina global $3
    type: COUNTER
  
  - pattern: 'Catalina<j2eeType=Servlet, WebModule=//([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), name=([-a-zA-Z0-9+/$%~_-|!.]*), J2EEApplication=none, J2EEServer=none><>(requestCount|maxTime|processingTime|errorCount)'
    name: catalina_servlet_$3_total
    labels:
      module: "$1"
      servlet: "$2"
    help: Catalina servlet $3 total
    type: COUNTER
  
  - pattern: 'Catalina<type=ThreadPool, name="(\w+-\w+)-(\d+)"><>(currentThreadCount|currentThreadsBusy|keepAliveCount|pollerThreadCount|connectionCount)'
    name: catalina_threadpool_$3
    labels:
      port: "$2"
      protocol: "$1"
    help: Catalina threadpool $3
    type: GAUGE
  
  - pattern: 'Catalina<type=Manager, host=([-a-zA-Z0-9+&@#/%?=~_|!:.,;]*[-a-zA-Z0-9+&@#/%=~_|]), context=([-a-zA-Z0-9+/$%~_-|!.]*)><>(processingTime|sessionCounter|rejectedSessions|expiredSessions)'
    name: catalina_session_$3_total
    labels:
      context: "$2"
      host: "$1"
    help: Catalina session $3 total
    type: COUNTER
  
  - pattern: ".*"
  ```
+ `start_exporter_example.sh` 是使用匯出的 Prometheus 指標來啟動 JAR 應用程式的指令碼。它還為 JMX Exporter 提供了 `config.yaml` 檔案路徑。

  ```
  $ cat start_exporter_example.sh 
  java -javaagent:/opt/jmx_exporter/jmx_prometheus_javaagent-0.12.0.jar=9404:/opt/jmx_exporter/config.yaml -cp  /opt/jmx_exporter/SampleJavaApplication-1.0-SNAPSHOT.jar com.gubupt.sample.app.App
  ```
+ SampleJavaApplication-1.0-SNAPSHOT.jar 是範例 Java 應用程式 jar 檔案。將其取代為您要監控的 Java 應用程式。

使用此組態建置一個 Docker 影像並將其上傳到映像儲存庫。

# 在 Amazon EKS 和 Kubernetes 上使用指標匯出工具設定 HAProxy
<a name="ContainerInsights-Prometheus-Sample-Workloads-haproxy"></a>

HAProxy 是一個開放程式碼代理應用程式。如需詳細資訊，請參閱 [HAProxy](https://www.haproxy.org)。

如果您在具有 Fargate 啟動類型的叢集上執行 HAProxy，則需要在執行此程序中的步驟之前設定 Fargate 描述檔。若要設定描述檔，請輸入下列命令。將 *MyCluster* 取代為您的叢集名稱。

```
eksctl create fargateprofile --cluster MyCluster \
--namespace haproxy-ingress-sample --name haproxy-ingress-sample
```

**使用指標匯出工具安裝 HAProxy，以測試 Container Insights Prometheus 支援**

1. 輸入下列命令以新增 Helm incubator 儲存庫：

   ```
   helm repo add haproxy-ingress https://haproxy-ingress.github.io/charts
   ```

1. 輸入以下命令來建立新的命名空間：

   ```
   kubectl create namespace haproxy-ingress-sample
   ```

1. 輸入下列命令來安裝 HAProxy：

   ```
   helm install haproxy haproxy-ingress/haproxy-ingress \
   --namespace haproxy-ingress-sample \
   --set defaultBackend.enabled=true \
   --set controller.stats.enabled=true \
   --set controller.metrics.enabled=true \
   --set-string controller.metrics.service.annotations."prometheus\.io/port"="9101" \
   --set-string controller.metrics.service.annotations."prometheus\.io/scrape"="true"
   ```

1. 輸入下列命令以確認服務的註釋：

   ```
   kubectl describe service haproxy-haproxy-ingress-metrics -n haproxy-ingress-sample
   ```

   您應該會看到下列註釋。

   ```
   Annotations:   prometheus.io/port: 9101
                  prometheus.io/scrape: true
   ```

**解除安裝 HAProxy**
+ 輸入下列命令：

  ```
  helm uninstall haproxy --namespace haproxy-ingress-sample
  kubectl delete namespace haproxy-ingress-sample
  ```

# 新增 Prometheus 湊集目標的教學課程：Amazon EKS 和 Kubernetes 叢集上的 Redis OSS
<a name="ContainerInsights-Prometheus-Setup-redis-eks"></a>

本教學課程提供實作介紹，讓您在 Amazon EKS 和 Kubernetes 上湊集範例 Redis OSS 應用程式的 Prometheus 指標。Redis OSS (https://redis.io/) 是一個開放原始碼 (BSD 授權)、記憶體內資料結構存儲，可用作資料庫、快取和訊息代理程式。如需詳細資訊，請參閱 [redis](https://redis.io/)。

redis\$1exporter (授權的 MIT 授權) 可用於在指定的連接埠上公開 Redis OSS Prometheus 指標 (預設：0.0.0.0:9121)。如需詳細資訊，請參閱 [redis\$1exporter](https://github.com/oliver006/redis_exporter)。

本教學課程會使用下列兩個 Docker Hub 儲存庫中的 Docker 影像：
+ [redis](https://hub.docker.com/_/redis?tab=description)
+ [redis\$1exporter](https://hub.docker.com/r/oliver006/redis_exporter)

**若要安裝公開 Prometheus 指標的範例 Redis OSS 工作負載**

1. 設定範例 Redis OSS 工作負載的命名空間。

   ```
   REDIS_NAMESPACE=redis-sample
   ```

1. 如果您在具有 Fargate 啟動類型的叢集上執行 Redis OSS，則需要設定 Fargate 描述檔。若要設定描述檔，請輸入下列命令。將 *MyCluster* 取代為您的叢集名稱。

   ```
   eksctl create fargateprofile --cluster MyCluster \
   --namespace $REDIS_NAMESPACE --name $REDIS_NAMESPACE
   ```

1. 輸入下列命令以安裝範例 Redis OSS 工作負載。

   ```
   curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/sample_traffic/redis/redis-traffic-sample.yaml \
   | sed "s/{{namespace}}/$REDIS_NAMESPACE/g" \
   | kubectl apply -f -
   ```

1. 此安裝包含名為 `my-redis-metrics` 的服務，而該服務會在連接埠 9121 上公開 Redis OSS Prometheus 指標。請輸入下列命令，以取得服務的詳細資訊：

   ```
   kubectl describe service/my-redis-metrics  -n $REDIS_NAMESPACE
   ```

   在結果的 `Annotations` 區段中，您會看到兩個符合 CloudWatch 代理程式 Prometheus 刮取組態的註釋，以便它可以自動探索工作負載：

   ```
   prometheus.io/port: 9121
   prometheus.io/scrape: true
   ```

   相關的 Prometheus 湊集組態可以在 `kubernetes-eks.yaml` 或 `kubernetes-k8s.yaml` 的 `- job_name: kubernetes-service-endpoints` 區段找到。

**若要開始在 CloudWatch 中收集 Redis OSS Prometheus 指標**

1. 輸入下列其中一個命令，以下載最新版本的 `kubernetes-eks.yaml` 或 `kubernetes-k8s.yaml` 檔案。對於具有 EC2 啟動類型的 Amazon EKS 叢集，請輸入此命令。

   ```
   curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/prometheus-eks.yaml
   ```

   對於具有 Fargate 啟動類型的 Amazon EKS 叢集，請輸入此命令。

   ```
   curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/prometheus-eks-fargate.yaml
   ```

   對於在 Amazon EC2 執行個體上執行的 Kubernetes 叢集，請輸入下列命令。

   ```
   curl -O https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/prometheus-k8s.yaml
   ```

1. 使用文字編輯器開啟檔案，然後找出 `cwagentconfig.json` 區段。新增下列子區段並儲存變更。請務必遵循現有的縮排模式。

   ```
   {
     "source_labels": ["pod_name"],
     "label_matcher": "^redis-instance$",
     "dimensions": [["Namespace","ClusterName"]],
     "metric_selectors": [
       "^redis_net_(in|out)put_bytes_total$",
       "^redis_(expired|evicted)_keys_total$",
       "^redis_keyspace_(hits|misses)_total$",
       "^redis_memory_used_bytes$",
       "^redis_connected_clients$"
     ]
   },
   {
     "source_labels": ["pod_name"],
     "label_matcher": "^redis-instance$",
     "dimensions": [["Namespace","ClusterName","cmd"]],
     "metric_selectors": [
       "^redis_commands_total$"
     ]
   },
   {
     "source_labels": ["pod_name"],
     "label_matcher": "^redis-instance$",
     "dimensions": [["Namespace","ClusterName","db"]],
     "metric_selectors": [
       "^redis_db_keys$"
     ]
   },
   ```

   您新增的區段會將 Redis OSS 指標放到 CloudWatch 代理程式允許清單中。如需了解這些指標的清單，請參閱下列章節。

1. 如果您已在此叢集中部署具有 Prometheus 支援的 CloudWatch 代理程式，則必須輸入下列命令來刪除它。

   ```
   kubectl delete deployment cwagent-prometheus -n amazon-cloudwatch
   ```

1. 輸入下列其中一個命令，以更新的組態來部署 CloudWatch 代理程式：將 *MyCluster* 和 *region* 取代為可比對設定的數值。

   對於具有 EC2 啟動類型的 Amazon EKS 叢集，請輸入此命令。

   ```
   kubectl apply -f prometheus-eks.yaml
   ```

   對於具有 Fargate 啟動類型的 Amazon EKS 叢集，請輸入此命令。

   ```
   cat prometheus-eks-fargate.yaml \
   | sed "s/{{cluster_name}}/MyCluster/;s/{{region_name}}/region/" \
   | kubectl apply -f -
   ```

   對於 Kubernetes 叢集，請輸入此命令。

   ```
   cat prometheus-k8s.yaml \
   | sed "s/{{cluster_name}}/MyCluster/;s/{{region_name}}/region/" \
   | kubectl apply -f -
   ```

## 檢視 Redis OSS Prometheus 指標
<a name="ContainerInsights-Prometheus-Setup-redis-eks-view"></a>

此教學課程會將下列指標傳送至 CloudWatch 中的 **ContainerInsights/Prometheus** 命名空間。您可以使用 CloudWatch 主控台查看該命名空間中的指標。


| 指標名稱 | 維度 | 
| --- | --- | 
|  `redis_net_input_bytes_total` |  ClusterName、`Namespace`  | 
|  `redis_net_output_bytes_total` |  ClusterName、`Namespace`  | 
|  `redis_expired_keys_total` |  ClusterName、`Namespace`  | 
|  `redis_evicted_keys_total` |  ClusterName、`Namespace`  | 
|  `redis_keyspace_hits_total` |  ClusterName、`Namespace`  | 
|  `redis_keyspace_misses_total` |  ClusterName、`Namespace`  | 
|  `redis_memory_used_bytes` |  ClusterName、`Namespace`  | 
|  `redis_connected_clients` |  ClusterName、`Namespace`  | 
|  `redis_commands_total` |  ClusterName、`Namespace`、cmd  | 
|  `redis_db_keys` |  ClusterName、`Namespace`、db  | 

**注意**  
**cmd** 維度的數值可以是：`append`、`client`、`command`、`config`、`dbsize`、`flushall`、`get`、`incr`、`info` `latency` 或 `slowlog`。  
**db** 維度的數值可以是 `db0` 至 `db15`。

您也可以為 Redis OSS Prometheus 指標建立 CloudWatch 儀表板。

**若要建立 Redis OSS Prometheus 指標的儀表板**

1. 建立環境變數，取代下面的數值，以符合您的部署。

   ```
   DASHBOARD_NAME=your_cw_dashboard_name
   REGION_NAME=your_metric_region_such_as_us-east-1
   CLUSTER_NAME=your_k8s_cluster_name_here
   NAMESPACE=your_redis_service_namespace_here
   ```

1. 輸入下列命令建立儀表板。

   ```
   curl https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/sample_cloudwatch_dashboards/redis/cw_dashboard_redis.json \
   | sed "s/{{YOUR_AWS_REGION}}/${REGION_NAME}/g" \
   | sed "s/{{YOUR_CLUSTER_NAME}}/${CLUSTER_NAME}/g" \
   | sed "s/{{YOUR_NAMESPACE}}/${NAMESPACE}/g" \
   ```

# CloudWatch 代理程式的 Prometheus 指標類型轉換
<a name="ContainerInsights-Prometheus-metrics-conversion"></a>

Prometheus 用戶端程式庫提供四種核心指標類型：
+ 計數器
+ 量測計
+ 摘要
+ 直方圖

CloudWatch 代理程式支援計數器、量測計和摘要指標類型。

 CloudWatch 代理程式會捨棄具有不支援長條圖指標類型的 Prometheus 指標。如需詳細資訊，請參閱[記錄日誌已捨棄 Prometheus 指標](ContainerInsights-Prometheus-troubleshooting-EKS.md#ContainerInsights-Prometheus-troubleshooting-droppedmetrics)。

**量測計指標**

Prometheus 量測計指標是一種可代表能任意上下的單一數值的指標。CloudWatch 代理程式會湊集計量指標，並直接將這些數值傳送出去。

**計數器指標**

Prometheus 計數器指標是累積度量，可代表單一單調增加計數器，且其值只能增加或重設為零。CloudWatch 代理程式會從先前湊集計算差異，並將差異值作為日誌事件中的指標值進行傳送。因此，CloudWatch 代理程式將從第二次湊集開始產生一個日誌事件，並繼續進行後續湊集 (如有)。

**摘要指標**

Prometheus 摘要指標是一種複雜的指標類型，且由多個資料點表示。它提供了觀察值的總計數和所有觀察值的總和。它會計算在滑動時段的可設定分位數。

摘要指標的總和和計數是累計的，但分數不是。下列範例顯示分位數的差異。

```
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 7.123e-06
go_gc_duration_seconds{quantile="0.25"} 9.204e-06
go_gc_duration_seconds{quantile="0.5"} 1.1065e-05
go_gc_duration_seconds{quantile="0.75"} 2.8731e-05
go_gc_duration_seconds{quantile="1"} 0.003841496
go_gc_duration_seconds_sum 0.37630427
go_gc_duration_seconds_count 9774
```

CloudWatch 代理程式會以與處理計數器指標相同的方式處理摘要指標，如上一節所述。CloudWatch 代理程式會保留原先報告的分位數值。

# CloudWatch 代理程式收集的 Prometheus 指標
<a name="ContainerInsights-Prometheus-metrics"></a>

具有 Prometheus 支援的 CloudWatch 代理程式會自動從多個服務和工作負載收集指標。預設收集的指標列於下列各節中。您也可以將代理程式設定為從這些服務收集更多指標，以及從其他應用程式和服務收集 Prometheus 指標。如需更多有關收集其他指標詳細資訊，請參閱 [Prometheus 的 CloudWatch 代理程式組態](ContainerInsights-Prometheus-Setup-configure-ECS.md#ContainerInsights-Prometheus-Setup-cw-agent-config)。

從 Amazon EKS 和 Kubernetes 叢集收集的所有 Prometheus 指標，均收集在 **ContainerInsights/Prometheus** 命名空間中。從 Amazon ECS 叢集收集的所有 Prometheus 指標，均收集在 **ECS/ContainerInsights/Prometheus** 命名空間中。

**Topics**
+ [App Mesh 的 Prometheus 指標](#ContainerInsights-Prometheus-metrics-appmesh)
+ [NGINX 的 Prometheus 指標](#ContainerInsights-Prometheus-metrics-nginx)
+ [memcached 的 Prometheus 指標](#ContainerInsights-Prometheus-metrics-memcached)
+ [Java/JMX 的 Prometheus 指標](#ContainerInsights-Prometheus-metrics-jmx)
+ [HAProxy 的 Prometheus 指標](#ContainerInsights-Prometheus-metrics-haproxy)

## App Mesh 的 Prometheus 指標
<a name="ContainerInsights-Prometheus-metrics-appmesh"></a>

系統會從 App Mesh 自動收集下列指標。

**Amazon EKS 和 Kubernetes 叢集上 App Mesh 的 Prometheus 指標**


| 指標名稱 | 維度 | 
| --- | --- | 
|  `envoy_http_downstream_rq_total` |  ClusterName、`Namespace`  | 
|  `envoy_http_downstream_rq_xx` |  ClusterName、`Namespace` ClusterName、`Namespace`、envoy\$1http\$1conn\$1manager\$1prefix、envoy\$1response\$1code\$1class  | 
|  `envoy_cluster_upstream_cx_rx_bytes_total` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_cx_tx_bytes_total` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_membership_healthy` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_membership_total` |  ClusterName、`Namespace`  | 
|  `envoy_server_memory_heap_size` |  ClusterName、`Namespace`  | 
|  `envoy_server_memory_allocated` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_cx_connect_timeout` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_rq_pending_failure_eject` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_rq_pending_overflow` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_rq_timeout` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_rq_try_per_timeout` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_rq_rx_reset` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_cx_destroy_local_with_active_rq` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_cx_destroy_remote_active_rq` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_rq_maintenance_mode` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_flow_control_paused_reading_total` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_flow_control_resumed_reading_total` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_flow_control_backed_up_total` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_flow_control_drained_total` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_rq_retry` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_rq_retry_success` |  ClusterName、`Namespace`  | 
|  `envoy_cluster_upstream_rq_retry_overflow` |  ClusterName、`Namespace`  | 
|  `envoy_server_live` |  ClusterName、`Namespace`  | 
|  `envoy_server_uptime` |  ClusterName、`Namespace`  | 

**Amazon ECS 叢集上 App Mesh 的 Prometheus 指標**


| 指標名稱 | 維度 | 
| --- | --- | 
|  `envoy_http_downstream_rq_total` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_http_downstream_rq_xx` |  ClusterName、`TaskDefinitionFamily` | 
|  `envoy_cluster_upstream_cx_rx_bytes_total` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_cx_tx_bytes_total` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_membership_healthy` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_membership_total` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_server_memory_heap_size` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_server_memory_allocated` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_cx_connect_timeout` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_rq_pending_failure_eject` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_rq_pending_overflow` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_rq_timeout` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_rq_try_per_timeout` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_rq_rx_reset` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_cx_destroy_local_with_active_rq` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_cx_destroy_remote_active_rq` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_rq_maintenance_mode` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_flow_control_paused_reading_total` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_flow_control_resumed_reading_total` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_flow_control_backed_up_total` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_flow_control_drained_total` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_rq_retry` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_rq_retry_success` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_cluster_upstream_rq_retry_overflow` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_server_live` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_server_uptime` |  ClusterName、`TaskDefinitionFamily`  | 
|  `envoy_http_downstream_rq_xx` |  ClusterName、TaskDefinitionFamily、envoy\$1http\$1conn\$1manager\$1prefix、envoy\$1response\$1code\$1class ClusterName、TaskDefinitionFamily、envoy\$1response\$1code\$1class | 

**注意**  
`TaskDefinitionFamily` 是 mesh 的 Kubernetes 命名空間。  
`envoy_http_conn_manager_prefix` 的值可以是 `ingress`、`egress` 或 `admin`。  
`envoy_response_code_class` 的值可以是 `1` (代表 `1xx`)、`2` 代表 (`2xx`)、`3` (代表 `3xx`)、`4` (代表 `4xx`) 或 `5` (代表`5xx`)。

## NGINX 的 Prometheus 指標
<a name="ContainerInsights-Prometheus-metrics-nginx"></a>

系統會 Amazon EKS 和 Kubernetes 叢集上的 NGINX 自動收集下列指標。


| 指標名稱 | 維度 | 
| --- | --- | 
|  `nginx_ingress_controller_nginx_process_cpu_seconds_total` |  ClusterName、`Namespace`、服務  | 
|  `nginx_ingress_controller_success` |  ClusterName、`Namespace`、服務  | 
|  `nginx_ingress_controller_requests` |  ClusterName、`Namespace`、服務  | 
|  `nginx_ingress_controller_nginx_process_connections` |  ClusterName、`Namespace`、服務  | 
|  `nginx_ingress_controller_nginx_process_connections_total` |  ClusterName、`Namespace`、服務  | 
|  `nginx_ingress_controller_nginx_process_resident_memory_bytes` |  ClusterName、`Namespace`、服務  | 
|  `nginx_ingress_controller_config_last_reload_successful` |  ClusterName、`Namespace`、服務  | 
|  `nginx_ingress_controller_requests` |  ClusterName、`Namespace`、服務、狀態  | 

## memcached 的 Prometheus 指標
<a name="ContainerInsights-Prometheus-metrics-memcached"></a>

系統會 Amazon EKS 和 Kubernetes 叢集上的 Memcached 自動收集下列指標。


| 指標名稱 | 維度 | 
| --- | --- | 
|  `memcached_current_items` |  ClusterName、`Namespace`、服務  | 
|  `memcached_current_connections` |  ClusterName、`Namespace`、服務  | 
|  `memcached_limit_bytes` |  ClusterName、`Namespace`、服務  | 
|  `memcached_current_bytes` |  ClusterName、`Namespace`、服務  | 
|  `memcached_written_bytes_total` |  ClusterName、`Namespace`、服務  | 
|  `memcached_read_bytes_total` |  ClusterName、`Namespace`、服務  | 
|  `memcached_items_evicted_total` |  ClusterName、`Namespace`、服務  | 
|  `memcached_items_reclaimed_total` |  ClusterName、`Namespace`、服務  | 
|  `memcached_commands_total` |  ClusterName、`Namespace`、服務 ClusterName、`Namespace`、服務、命令 ClusterName、`Namespace`、服務、狀態、命令  | 

## Java/JMX 的 Prometheus 指標
<a name="ContainerInsights-Prometheus-metrics-jmx"></a>

**在 Amazon EKS 和 Kubernetes 叢集上收集的指標**

在 Amazon EKS 和 Kubernetes 叢集上，Container Insights 可以使用 JMX Exporter，從 Java 虛擬機器 (JVM)、Java 和 Tomcat (Catalina) 收集下列預先定義的 Prometheus 指標。如需詳細資訊，請參閱 Github 上的 [prometheus/jmx\$1exporter](https://github.com/prometheus/jmx_exporter)。

**Amazon EKS 和 Kubernetes 叢集上的 Java/JMX**


| 指標名稱 | 維度 | 
| --- | --- | 
|  `jvm_classes_loaded` |  `ClusterName`, `Namespace`  | 
|  `jvm_threads_current` |  `ClusterName`, `Namespace`  | 
|  `jvm_threads_daemon` |  `ClusterName`, `Namespace`  | 
|  `java_lang_operatingsystem_totalswapspacesize` |  `ClusterName`, `Namespace`  | 
|  `java_lang_operatingsystem_systemcpuload` |  `ClusterName`, `Namespace`  | 
|  `java_lang_operatingsystem_processcpuload` |  `ClusterName`, `Namespace`  | 
|  `java_lang_operatingsystem_freeswapspacesize` |  `ClusterName`, `Namespace`  | 
|  `java_lang_operatingsystem_totalphysicalmemorysize` |  `ClusterName`, `Namespace`  | 
|  `java_lang_operatingsystem_freephysicalmemorysize` |  `ClusterName`, `Namespace`  | 
|  `java_lang_operatingsystem_openfiledescriptorcount` |  `ClusterName`, `Namespace`  | 
|  `java_lang_operatingsystem_availableprocessors` |  `ClusterName`, `Namespace`  | 
|  `jvm_memory_bytes_used` |  `ClusterName`、`Namespace`、區域  | 
|  `jvm_memory_pool_bytes_used` |  `ClusterName`、`Namespace`、集區  | 

**注意**  
`area` 維度的數值可以是 `heap` 或 `nonheap`。  
`pool` 維度的數值可以是 `Tenured Gen`、`Compress Class Space`、`Survivor Space`、`Eden Space`、`Code Cache` 或 `Metaspace`。

**Amazon EKS 和 Kubernetes 叢集上的 Tomcat/JMX**

除了上表中的 Java/JMX 指標之外，也會收集 Tomcat 工作負載的下列指標。


| 指標名稱 | 維度 | 
| --- | --- | 
|  `catalina_manager_activesessions` |  `ClusterName`, `Namespace`  | 
|  `catalina_manager_rejectedsessions` |  `ClusterName`, `Namespace`  | 
|  `catalina_globalrequestprocessor_bytesreceived` |  `ClusterName`, `Namespace`  | 
|  `catalina_globalrequestprocessor_bytessent` |  `ClusterName`, `Namespace`  | 
|  `catalina_globalrequestprocessor_requestcount` |  `ClusterName`, `Namespace`  | 
|  `catalina_globalrequestprocessor_errorcount` |  `ClusterName`, `Namespace`  | 
|  `catalina_globalrequestprocessor_processingtime` |  `ClusterName`, `Namespace`  | 

**Amazon ECS 叢集上的 Java/JMX**


| 指標名稱 | 維度 | 
| --- | --- | 
|  `jvm_classes_loaded` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `jvm_threads_current` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `jvm_threads_daemon` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `java_lang_operatingsystem_totalswapspacesize` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `java_lang_operatingsystem_systemcpuload` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `java_lang_operatingsystem_processcpuload` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `java_lang_operatingsystem_freeswapspacesize` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `java_lang_operatingsystem_totalphysicalmemorysize` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `java_lang_operatingsystem_freephysicalmemorysize` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `java_lang_operatingsystem_openfiledescriptorcount` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `java_lang_operatingsystem_availableprocessors` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `jvm_memory_bytes_used` |  `ClusterName`、TaskDefinitionFamily、區域  | 
|  `jvm_memory_pool_bytes_used` |  `ClusterName`、TaskDefinitionFamily、集區  | 

**注意**  
`area` 維度的數值可以是 `heap` 或 `nonheap`。  
`pool` 維度的數值可以是 `Tenured Gen`、`Compress Class Space`、`Survivor Space`、`Eden Space`、`Code Cache` 或 `Metaspace`。

**Amazon ECS 叢集上的 Tomcat/JMX**

除了上表中的 Java/JMX 指標之外，也會收集 Amazon ECS 叢集上的 Tomcat 工作負載的下列指標。


| 指標名稱 | 維度 | 
| --- | --- | 
|  `catalina_manager_activesessions` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `catalina_manager_rejectedsessions` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `catalina_globalrequestprocessor_bytesreceived` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `catalina_globalrequestprocessor_bytessent` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `catalina_globalrequestprocessor_requestcount` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `catalina_globalrequestprocessor_errorcount` |  `ClusterName`, `TaskDefinitionFamily`  | 
|  `catalina_globalrequestprocessor_processingtime` |  `ClusterName`, `TaskDefinitionFamily`  | 

## HAProxy 的 Prometheus 指標
<a name="ContainerInsights-Prometheus-metrics-haproxy"></a>

系統會從 Amazon EKS 和 Kubernetes 叢集 上的 HAProxy 自動收集下列指標。

收集的指標取決於您所使用的 HAProxy Ingress 的版本。如需 HAProxy Ingress 及其版本的詳細資訊，請參閱 [haproxy-ingress](https://artifacthub.io/packages/helm/haproxy-ingress/haproxy-ingress)。


| 指標名稱 | 維度 | 可用性 | 
| --- | --- | --- | 
|  `haproxy_backend_bytes_in_total` |  `ClusterName`、`Namespace`、服務  | HAProxy Ingress 的所有版本 | 
|  `haproxy_backend_bytes_out_total` |  `ClusterName`、`Namespace`、服務  | HAProxy Ingress 的所有版本 | 
|  `haproxy_backend_connection_errors_total` |  `ClusterName`、`Namespace`、服務  | HAProxy Ingress 的所有版本 | 
|  `haproxy_backend_connections_total` |  `ClusterName`、`Namespace`、服務  | HAProxy Ingress 的所有版本 | 
|  `haproxy_backend_current_sessions` |  `ClusterName`、`Namespace`、服務  | HAProxy Ingress 的所有版本 | 
|  `haproxy_backend_http_responses_total` |  `ClusterName`、`Namespace`、服務、程式碼、後端  | HAProxy Ingress 的所有版本 | 
|  `haproxy_backend_status` |  `ClusterName`、`Namespace`、服務  |  只有 HAProxy Ingress 的 0.10 版或更新版本  | 
|  `haproxy_backend_up` |  `ClusterName`、`Namespace`、服務  |  只有 HAProxy Ingress 的 0.10 版  | 
|  `haproxy_frontend_bytes_in_total` |  `ClusterName`、`Namespace`、服務  | HAProxy Ingress 的所有版本 | 
|  `haproxy_frontend_bytes_out_total` |  `ClusterName`、`Namespace`、服務  | HAProxy Ingress 的所有版本 | 
|  `haproxy_frontend_connections_total` |  `ClusterName`、`Namespace`、服務  | HAProxy Ingress 的所有版本 | 
|  `haproxy_frontend_current_sessions` |  `ClusterName`、`Namespace`、服務  | HAProxy Ingress 的所有版本 | 
|  `haproxy_frontend_http_requests_total` |  `ClusterName`、`Namespace`、服務  | HAProxy Ingress 的所有版本 | 
|  `haproxy_frontend_http_responses_total` |  `ClusterName`、`Namespace`、服務、程式碼、前端  | HAProxy Ingress 的所有版本 | 
|  `haproxy_frontend_request_errors_total` |  `ClusterName`、`Namespace`、服務  | HAProxy Ingress 的所有版本 | 
|  `haproxy_frontend_requests_denied_total` |  `ClusterName`、`Namespace`、服務  | HAProxy Ingress 的所有版本 | 

**注意**  
`code` 維度的數值可以是 `1xx`、`2xx`、`3xx`、`4xx`、`5xx` 或 `other`。  
`backend` 維度的數值可以是：  
適用於 HAProxy Ingress 0.0.27 版或更早版本的 `http-default-backend`、`http-shared-backend` 或 `httpsback-shared-backend`。
適用於 HAProxy Ingress 0.0.27 以上版本的 `_default_backend`。
`frontend` 維度的數值可以是：  
適用於 HAProxy Ingress 0.0.27 版或更早版本的 `httpfront-default-backend`、`httpfront-shared-frontend` 或 `httpfronts`。
適用於 HAProxy Ingress 0.0.27 以上版本的 `_front_http` 或 `_front_https`。

# 檢視 Prometheus 指標
<a name="ContainerInsights-Prometheus-viewmetrics"></a>

您可以對所有 Prometheus 指標進行監控和警示，包括來自 App Mesh、NGINX、JavaA/JMX、Memcached 和 HAProxy，以及您可能已新增之任何其他手動設定的 Prometheus 匯出工具等經策管的預先彙總指標。如需從其他 Prometheus 匯出工具收集指標的詳細資訊，請參閱[新增 Prometheus 湊集目標的教學課程：Prometheus API 伺服器指標](ContainerInsights-Prometheus-Setup-configure.md#ContainerInsights-Prometheus-Setup-new-exporters)。

在 CloudWatch 主控台中，Container Insights 會提供下列預先建置的報告：
+ 對於 Amazon EKS 和 Kubernetes 叢集，有針對 App Mesh、NGINX、HAPROXY、Memcached 和 Java/JMX 預先建置的報告。
+ 對於 Amazon ECS 叢集，有適用於 App Mesh 和 Java/JMX 的預先建置報告。

Container Insights 也會針對 Container Insights 從中收集經策管指標的每個工作負載提供自訂儀表板。您可以從 GitHub 下載這些儀表板 

**查看所有 Prometheus 指標**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

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

1. 在命名空間清單中，選擇 **ContainerInsights/Prometheus** 或 **ECS/ContainerInsights/Prometheus**。

1. 在下列清單中選擇其中一組維度。然後選取您要查看的指標旁邊的核取方塊。

**查看有關 Prometheus 指標的預先建置報告**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇 **Performance Monitoring (效能監控)**。

1. 在靠近頁面頂端的下拉式方塊中，選擇任意一個 Prometheus 選項。

   在另一個下拉式方塊中，選擇要檢視的叢集

我們還為 NGINX、App Mesh、Memcached、HAProxy 和 Java/JMX 提供了自訂儀表板。

**使用 Amazon 提供的自訂儀表板**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇 **Dashboards** (儀表板)。

1. 選擇 **Create Dashboard (建立儀表板)**。輸入新儀表板的名稱，然後選擇 **Create dashboard (建立儀表板)**。

1. 在 **Add to this dashboard (新增至此儀表板)** 中，選擇 **Cancel (取消)**。

1. 選擇 **Actions (動作)**、**View/edit sources (檢視/編輯來源)**。

1. 下載下列其中一個 JSON 檔案：
   + [Github 上的 NGINX 自訂儀表板來源](https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/sample_cloudwatch_dashboards/nginx-ingress/cw_dashboard_nginx_ingress_controller.json)。
   + [Github 上的 App Mesh 自訂儀表板來源](https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/sample_cloudwatch_dashboards/appmesh/cw_dashboard_awsappmesh.json)。
   + [Github 上的 Memcached 自訂儀表板來源](https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/sample_cloudwatch_dashboards/memcached/cw_dashboard_memcached.json)
   + [Github 上的 HAProxy-Ingress 自訂儀表板來源](https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/sample_cloudwatch_dashboards/haproxy-ingress/cw_dashboard_haproxy_ingress.json)
   + [Github 上的 Java/JMX 自訂儀表板來源](https://raw.githubusercontent.com/aws-samples/amazon-cloudwatch-container-insights/latest/k8s-deployment-manifest-templates/deployment-mode/service/cwagent-prometheus/sample_cloudwatch_dashboards/javajmx/cw_dashboard_javajmx.json)。

1. 使用文字編輯器開啟您下載的 JSON 檔案，然後進行下列變更：
   + 將所有 `{{YOUR_CLUSTER_NAME}}` 字串取代為您叢集的確切名稱。確定不要在文字前後加空格。
   + 將所有`{{YOUR_REGION}}`字串取代為叢集執行所在的 AWS 區域。例如，**us-west-1** 確定不要在文字前後加空格。
   + 將所有 `{{YOUR_NAMESPACE}}` 字串取代為您工作負載的確切命名空間。
   + 將所有 `{{YOUR_SERVICE_NAME}}` 字串取代為您工作負載的確切服務名稱。例如 **haproxy-haproxy-ingress-controller-metrics**

1. 複製整個 JSON blob 並將其貼入 CloudWatch 主控台的文字方塊中，取代方塊中已經存在的內容。

1. 選擇 **Update (更新)**、**Save dashboard (儲存儀表板)**。

# Prometheus 指標故障診斷
<a name="ContainerInsights-Prometheus-troubleshooting"></a>

本節提供對 Prometheus 指標設定進行故障診斷的說明。

**Topics**
+ [Amazon ECS 上的 Prometheus 指標故障診斷](ContainerInsights-Prometheus-troubleshooting-ECS.md)
+ [Amazon EKS 和 Kubernetes 叢集上的 Prometheus 指標故障診斷](ContainerInsights-Prometheus-troubleshooting-EKS.md)

# Amazon ECS 上的 Prometheus 指標故障診斷
<a name="ContainerInsights-Prometheus-troubleshooting-ECS"></a>

本節提供對 Amazon ECS 叢集上的 Prometheus 指標設定進行故障診斷的說明。

## 我看不到傳送至 CloudWatch Logs 的 Prometheus 指標
<a name="ContainerInsights-Prometheus-troubleshooting-ECS-nometrics"></a>

Prometheus 指標應在日誌群組 **/aws/ecs/containerinsights/cluster-name/Prometheus** 中擷取為日誌事件。如果未建立日誌群組，或者 Prometheus 指標未傳送至日誌群組，您必須先檢查 CloudWatch 代理程式是否已成功搜索到 Prometheus 目標。接下來檢查 CloudWatch 代理程式的安全群組和許可設定。下列步驟會引導您執行偵錯。

**步驟 1：啟用 CloudWatch 代理程式偵錯模式**

首先，將下列粗體行新增至 CloudFormation 範本檔案，`cwagent-ecs-prometheus-metric-for-bridge-host.yaml`或 ，將 CloudWatch 代理程式變更為偵錯模式`cwagent-ecs-prometheus-metric-for-awsvpc.yaml`。接著儲存檔案。

```
cwagentconfig.json: |
    {
      "agent": {
        "debug": true
      },
      "logs": {
        "metrics_collected": {
```

針對現有堆疊建立新的 CloudFormation 變更集。將變更集的其他參數設定為與現有 CloudFormation 堆疊相同的值。下列範例適用於使用 EC2 啟動類型和橋接網路模式在 Amazon ECS 叢集中安裝的 CloudWatch 代理程式。

```
ECS_NETWORK_MODE=bridge
 CREATE_IAM_ROLES=True
ECS_TASK_ROLE_NAME=your_selected_ecs_task_role_name
ECS_EXECUTION_ROLE_NAME=your_selected_ecs_execution_role_name
NEW_CHANGESET_NAME=your_selected_ecs_execution_role_name

aws cloudformation create-change-set --stack-name CWAgent-Prometheus-ECS-${ECS_CLUSTER_NAME}-EC2-${ECS_NETWORK_MODE} \
    --template-body file://cwagent-ecs-prometheus-metric-for-bridge-host.yaml \
    --parameters ParameterKey=ECSClusterName,ParameterValue=$ECS_CLUSTER_NAME \
                 ParameterKey=CreateIAMRoles,ParameterValue=$CREATE_IAM_ROLES \
                 ParameterKey=ECSNetworkMode,ParameterValue=$ECS_NETWORK_MODE \
                 ParameterKey=TaskRoleName,ParameterValue=$ECS_TASK_ROLE_NAME \
                 ParameterKey=ExecutionRoleName,ParameterValue=$ECS_EXECUTION_ROLE_NAME \
    --capabilities CAPABILITY_NAMED_IAM \
    --region $AWS_REGION \
    --change-set-name $NEW_CHANGESET_NAME
```

前往 CloudFormation 主控台以檢閱新的變更集 `$NEW_CHANGESET_NAME`。應該會看到一個可套用至 **CWAgentConfigSSMParameter** 資源的變更。輸入下列命令，以執行變更集並重新執行 CloudWatch 代理程式任務。

```
aws ecs update-service --cluster $ECS_CLUSTER_NAME \
--desired-count 0 \
--service your_service_name_here \
--region $AWS_REGION
```

請等候約 10 秒鐘，然後輸入下列命令。

```
aws ecs update-service --cluster $ECS_CLUSTER_NAME \
--desired-count 1 \
--service your_service_name_here \
--region $AWS_REGION
```

**步驟 2：檢查 ECS 服務探索日誌**

根據預設，CloudWatch 代理程式的 ECS 任務定義會啟用以下區段中的日誌。日誌會傳送日誌群組 **/ecs/ecs-cwagent-prometheus** 中的 CloudWatch Logs。

```
LogConfiguration:
  LogDriver: awslogs
    Options:
      awslogs-create-group: 'True'
      awslogs-group: "/ecs/ecs-cwagent-prometheus"
      awslogs-region: !Ref AWS::Region
      awslogs-stream-prefix: !Sub 'ecs-${ECSLaunchType}-awsvpc'
```

依字串 `ECS_SD_Stats` 篩選日誌，以取得與 ECS 服務探索相關的指標，如以下範例所示。

```
2020-09-1T01:53:14Z D! ECS_SD_Stats: AWSCLI_DescribeContainerInstances: 1
2020-09-1T01:53:14Z D! ECS_SD_Stats: AWSCLI_DescribeInstancesRequest: 1
2020-09-1T01:53:14Z D! ECS_SD_Stats: AWSCLI_DescribeTaskDefinition: 2
2020-09-1T01:53:14Z D! ECS_SD_Stats: AWSCLI_DescribeTasks: 1
2020-09-1T01:53:14Z D! ECS_SD_Stats: AWSCLI_ListTasks: 1
2020-09-1T01:53:14Z D! ECS_SD_Stats: Exporter_DiscoveredTargetCount: 1
2020-09-1T01:53:14Z D! ECS_SD_Stats: LRUCache_Get_EC2MetaData: 1
2020-09-1T01:53:14Z D! ECS_SD_Stats: LRUCache_Get_TaskDefinition: 2
2020-09-1T01:53:14Z D! ECS_SD_Stats: LRUCache_Size_ContainerInstance: 1
2020-09-1T01:53:14Z D! ECS_SD_Stats: LRUCache_Size_TaskDefinition: 2
2020-09-1T01:53:14Z D! ECS_SD_Stats: Latency: 43.399783ms
```

特定 ECS 服務探索週期的每個指標的含義如下：
+ **AWSCLI\$1DescribeContainerInstances** – 進行的 `ECS::DescribeContainerInstances` API 呼叫數目。
+ **AWSCLI\$1DescribeInstancesRequest** – 進行的 `ECS::DescribeInstancesRequest` API 呼叫數目。
+ **AWSCLI\$1DescribeTaskDefinition** – 進行的 `ECS::DescribeTaskDefinition` API 呼叫數目。
+ **AWSCLI\$1DescribeTasks** – 進行的 `ECS::DescribeTasks` API 呼叫數目。
+ **AWSCLI\$1ListTasks** – 進行的 `ECS::ListTasks` API 呼叫數目。
+ **ExporterDiscoveredTargetCount** – 已搜索到並成功匯出至容器內目標結果檔案中的 Prometheus 目標數目。
+ **LRUCache\$1Get\$1EC2MetaData** – 從快取擷取容器執行個體中繼資料的次數。
+ **LRUCache\$1Get\$1TaskDefinition** – 從快取擷取 ECS 任務定義中繼資料的次數。
+ **LRUCache\$1Size\$1ContainerInstance** – 在記憶體中快取的唯一容器執行個體的中繼資料數目。
+ **LRUCache\$1Size\$1TaskDefinition** – 在記憶體中快取的唯一 ECS 任務定義數目。
+ **Latency** (延遲) – 服務探索週期所需的時間。

檢查 `ExporterDiscoveredTargetCount` 的數值，查看已搜索到 Prometheus 目標是否符合您的期望。如果沒有，可能的原因如下：
+ ECS 服務探索的組態可能不符合應用程式的設定。對於 Docker 型標籤服務探索，您的目標容器可能沒有在 CloudWatch 代理程式中設定必要的 Docker 標籤來自動發現它們。對於 ECS 任務定義 ARN 規則表達式型服務探索，CloudWatch 代理程式中的 regex 設定可能與應用程式的任務定義不相符。
+ CloudWatch 代理程式的 ECS 任務角色可能沒有擷取 ECS 任務中繼資料的許可。檢查 CloudWatch 代理程式是否已授與下列唯讀許可：
  + `ec2:DescribeInstances`
  + `ecs:ListTasks`
  + `ecs:DescribeContainerInstances`
  + `ecs:DescribeTasks`
  + `ecs:DescribeTaskDefinition`

**步驟 3：檢查網路連線和 ECS 任務角色政策**

如果仍然沒有任何日誌事件傳送至目標 CloudWatch Logs 日誌群組，即使 `Exporter_DiscoveredTargetCount` 的數值表示有已搜索到 Prometheus 目標，而這可能由以下其中一項造成的：
+ CloudWatch 代理程式可能無法連接至 Prometheus 目標連接埠。檢查 CloudWatch 代理程式背後的安全群組設定。私有 IP 應該允許 CloudWatch 代理程式連線至 Prometheus 匯出工具連接埠。
+ CloudWatch 代理程式的 ECS 任務角色可能沒有 **CloudWatchAgentServerPolicy** 受管政策。CloudWatch 代理程式的 ECS 任務角色必須具備此政策，才能將 Prometheus 指標作為日誌事件進行傳送。如果您使用範例 CloudFormation 範本自動建立 IAM 角色，則會授予 ECS 任務角色和 ECS 執行角色執行 Prometheus 監控的最低權限。

# Amazon EKS 和 Kubernetes 叢集上的 Prometheus 指標故障診斷
<a name="ContainerInsights-Prometheus-troubleshooting-EKS"></a>

本節提供對 Amazon EKS 和 Kubernetes 叢集上的 Prometheus 指標設定進行故障診斷的說明。

## Amazon EKS 上的一般故障診斷步驟
<a name="ContainerInsights-Prometheus-troubleshooting-general"></a>

若要確認 CloudWatch 代理程式正在執行中，請輸入下列命令：

```
kubectl get pod -n amazon-cloudwatch
```

輸出應該在 `NAME` 欄中包含 `cwagent-prometheus-id` 一行和 `STATUS column.` 中包含 `Running` 一行

若要顯示有關執行中 pod 的詳細資訊，請輸入下列命令。將 *pod-name* 取代為 pod 的完整名稱，即以 `cw-agent-prometheus` 為開頭的名稱。

```
kubectl describe pod pod-name -n amazon-cloudwatch
```

如果您已安裝 CloudWatch Container Insights，則可以使用 CloudWatch Logs Insights 查詢來自收集 Prometheus 指標之 CloudWatch 代理程式的日誌。

**查詢應用程式日誌**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇 **CloudWatch Logs Insights**。

1. 選取應用程式日誌的日誌群組，**/aws/containerinsights/*cluster-name*/application**

1. 以下列查詢取代搜尋查詢表達式，然後選擇 **Run query (執行查詢)**

   ```
   fields ispresent(kubernetes.pod_name) as haskubernetes_pod_name, stream, kubernetes.pod_name, log | 
   filter haskubernetes_pod_name and kubernetes.pod_name like /cwagent-prometheus
   ```

您也可以確認 Prometheus 指標和中繼資料正擷取為 CloudWatch Logs 事件。

**確認 Prometheus 資料正擷取中**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇 **CloudWatch Logs Insights**。

1. 選擇 **/aws/containerinsights/*cluster-name*/prometheus**

1. 以下列查詢取代搜尋查詢表達式，然後選擇 **Run query (執行查詢)**

   ```
   fields @timestamp, @message | sort @timestamp desc | limit 20
   ```

## 記錄日誌已捨棄 Prometheus 指標
<a name="ContainerInsights-Prometheus-troubleshooting-droppedmetrics"></a>

此版本不會收集長條圖類型的 Prometheus 指標。您可以使用 CloudWatch 代理程式來檢查是否有任何 Prometheus 指標是因為屬於長條圖指標而遭到捨棄。您也可以記錄前 500 個因為是長條圖指標而遭到捨棄且未傳送到 CloudWatch 的 Prometheus 指標清單。

若要查看是否有任何指標遭到捨棄，請輸入下列命令：

```
kubectl logs -l "app=cwagent-prometheus" -n amazon-cloudwatch --tail=-1
```

如果有任何指標遭到捨棄，您會在 `/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log` 檔案中看到以下各行。

```
I! Drop Prometheus metrics with unsupported types. Only Gauge, Counter and Summary are supported.
I! Please enable CWAgent debug mode to view the first 500 dropped metrics
```

如果您看到這些行，而且想要知道哪些指標遭到捨棄，請使用下列步驟。

**記錄捨棄的 Prometheus 指標量清單**

1. 將下列粗體行新增至您的 `prometheus-eks.yaml` 或 `prometheus-k8s.yaml` 檔案，將 CloudWatch 代理程式變更為偵錯模式，然後儲存該檔案。

   ```
   {
         "agent": {
           "debug": true
         },
   ```

   檔案的這個區段看起來應該像這樣：

   ```
   cwagentconfig.json: |
       {
         "agent": {
           "debug": true
         },
         "logs": {
           "metrics_collected": {
   ```

1. 輸入下列命令，重新安裝 CloudWatch 代理程式以啟動偵錯模式：

   ```
   kubectl delete deployment cwagent-prometheus -n amazon-cloudwatch
   kubectl apply -f prometheus.yaml
   ```

   捨棄的指標會記錄在 CloudWatch 代理程式 pod 中。

1. 若要從 CloudWatch 代理程式 pod 擷取日誌，請輸入下列命令：

   ```
   kubectl logs -l "app=cwagent-prometheus" -n amazon-cloudwatch --tail=-1
   ```

   或者，如果您已安裝 Container Insights Fluentd 日誌記錄，則日誌也會儲存在 CloudWatch Logs 日誌群組 **/aws/containerinsights/*cluster\$1name*/application** 中。

   若要查詢這些日誌，您可以遵循[Amazon EKS 上的一般故障診斷步驟](#ContainerInsights-Prometheus-troubleshooting-general)中的步驟查詢應用程式日誌。

## Prometheus 指標擷取為 CloudWatch Logs 日誌事件的位置在哪裡？
<a name="ContainerInsights-Prometheus-troubleshooting-metrics_ingested"></a>

CloudWatch 代理程式會為每個 Prometheus 湊集任務組態建立日誌串流。例如，在 `prometheus-eks.yaml` 和 `prometheus-k8s.yaml` 檔案中，`job_name: 'kubernetes-pod-appmesh-envoy'` 一行會湊集 App Mesh 指標。Prometheus 目標會定義為 `kubernetes-pod-appmesh-envoy`。因此，所有 App Mesh Prometheus 指標都會在名為 **/aws/containerinsights/cluster-name/Prometheus** 的日誌群組下的日誌串流 **kubernetes-pod-appmesh-envoy** 中擷取為 CloudWatch Logs 事件。

## 我在 CloudWatch 指標中看不到 Amazon EKS 或 Kubernetes Prometheus 指標
<a name="ContainerInsights-Prometheus-troubleshooting-no-metrics"></a>

首先，請確定 Prometheus 指標在日誌群組 **/aws/containerinsights/cluster-name/Prometheus** 中擷取為日誌事件。使用 [Prometheus 指標擷取為 CloudWatch Logs 日誌事件的位置在哪裡？](#ContainerInsights-Prometheus-troubleshooting-metrics_ingested) 中的資訊來協助您檢查目標日誌串流。如果未建立日誌串流，或是日誌串流中沒有新的日誌事件，請檢查下列項目：
+ 檢查 Prometheus 指標匯出工具端點是否已正確設定
+ 檢查 CloudWatch 代理程式 YAML 檔案 `config map: cwagent-prometheus` 區段中的 Prometheus 湊集組態是否正確。該組態應該與 Prometheus 組態檔中的組態相同。如需詳細資訊，請參閱 Prometheus 文件中的 [<scrape\$1config>](https://prometheus.io/docs/prometheus/latest/configuration/configuration/#scrape_config)。

如果 Prometheus 指標正確擷取為日誌事件，請檢查內嵌指標格式設定是否已新增至日誌事件，以產生 CloudWatch 指標。

```
"CloudWatchMetrics":[
   {
      "Metrics":[
         {
            "Name":"envoy_http_downstream_cx_destroy_remote_active_rq"
         }
      ],
      "Dimensions":[
         [
            "ClusterName",
            "Namespace"
         ]
      ],
      "Namespace":"ContainerInsights/Prometheus"
   }
],
```

如需內嵌指標格式的詳細資訊，請參閱[規格：內嵌指標格式](CloudWatch_Embedded_Metric_Format_Specification.md)。

如果日誌事件中沒有內嵌指標格式，請檢查 CloudWatch 代理程式安裝 YAML 檔案 `config map: prometheus-cwagentconfig` 區段中的 `metric_declaration` 區段設定是否正確。如需詳細資訊，請參閱[新增 Prometheus 湊集目標的教學課程：Prometheus API 伺服器指標](ContainerInsights-Prometheus-Setup-configure.md#ContainerInsights-Prometheus-Setup-new-exporters)。

# 與 Application Insights 整合
<a name="container-insights-appinsights"></a>

Amazon CloudWatch Application Insights 協助您監控應用程式，並會識別和設定金鑰指標、日誌，並在您所有的應用程式資源和技術堆疊中發出警示。如需詳細資訊，請參閱[偵測常見的 CloudWatch Application Insights 應用程式問題](cloudwatch-application-insights.md)。

您可以啟用 Application Insights，從您的容器化應用程式和微型服務收集額外資料。如果尚未這樣做，您可以透過選擇 Container Insights 儀表板中效能檢視下方的 **Auto-configure Application Insights** (自動設定 Application Insights) 來啟用。

如果您已設定 CloudWatch Application Insights 來監控您的容器化應用程式，Application Insights 儀表板會出現在 Container Insights 儀表板下方。

如需 Application Insights 和容器化應用程式的詳細資訊，請參閱 [啟用 Application Insights 進行 Amazon ECS 和 Amazon EKS 資源監控](appinsights-setting-up-console.md#appinsights-container-insights)。

# 在 Container Insights 中檢視 Amazon ECS 生命週期事件
<a name="container-insights-ECS-lifecycle-events"></a>

您可以在 Container Insights 主控台中檢視 Amazon ECS 生命週期事件。這有助於您在單一檢視中關聯容器指標、日誌和事件，以便更全面地了解相關操作。

事件包括容器執行個體狀態變更事件、任務狀態變更事件和服務動作事件。Amazon ECS 會自動將這些事件傳送至 Amazon EventBridge，並且還會將其以事件日誌格式收集在 CloudWatch 中。如需有關這些事件的詳細資訊，請參閱 [Amazon ECS 事件](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_cwe_events.html)。

Standard Container Insights 定價適用於 Amazon ECS 生命週期事件。如需詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

若要設定生命週期事件資料表並為叢集建立規則，您必須具有 `events:PutRule`、`events:PutTargets` 以及 `logs:CreateLogGroup` 許可。您還必須確保建立一項資源政策，可讓 EventBridge 建立日誌串流，並將日誌傳送至 CloudWatch Logs。如果此資源政策不存在，您可輸入下列命令來建立該政策：

------
#### [ JSON ]

****  

```
{
  "Version":"2012-10-17",		 	 	 
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogStream",
        "logs:PutLogEvents"
      ],
      "Principal": {
        "Service": ["events.amazonaws.com", "delivery.logs.amazonaws.com"]
      },
      "Resource": "arn:aws:logs:us-east-1:111122223333:log-group:/aws/events/ecs/containerinsights/*:*",
      "Condition": {
        "StringEquals": {
        "aws:SourceAccount": "111122223333"
        },
        "ArnLike": {
        "aws:SourceArn": "arn:aws:events:us-east-1:111122223333:rule/eventsToLog*"
        }
      },
      "Sid": "TrustEventBridgeToStoreECSLifecycleLogEvents"
    }
  ]
}
```

------

您可使用下列命令來檢查是否已建立此政策，並確認附接的政策是否正常運作。

```
aws logs describe-resource-policies --region region --output json
```

若要檢視生命週期事件資料表，您必須具有 `events:DescribeRule`、`events:ListTargetsByRule` 以及 `logs:DescribeLogGroups` 許可。

**在 CloudWatch Container Insights 主控台中檢視 Amazon ECS 生命週期事件**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 依次選擇 **Insights**、**Container Insights**。

1. 選擇**檢視效能儀表板**。

1. 在下一個下拉式方塊中，選擇 **ECS Clusters** (ECS 叢集)、**ECS Services** (ECS 服務) 或 **ECS Tasks** (ECS 任務)。

1. 如果您在上一步中選擇 **ECS Services** (ECS 服務) 或 **ECS Tasks** (ECS 任務)，請選擇 **Lifecycle events** (生命週期事件) 索引標籤。

1. 如果頁面底部顯示 **Configure lifecycle events** (設定生命週期事件)，請選擇它為叢集建立 EventBridge 規則。

   這些事件會顯示在 Container Insights 窗格下方以及 Application Insights 區段上方。若要對這些事件執行額外的分析並建立其他視覺化效果，請在 Lifecycle Events (生命週期事件) 資料表中選擇 **View in Logs Insights** (在 Logs Insights 中檢視)。

# 針對容器洞見進行故障診斷
<a name="ContainerInsights-troubleshooting"></a>

若您在使用容器洞見時發生問題，下列各節可協助您。

## 在 Amazon EKS 或 Kubernetes 上部署失敗
<a name="ContainerInsights-setup-EKS-troubleshooting-general"></a>

若代理程式無法正確地在 Kubernetes 叢集上進行部署，請嘗試以下作業：
+ 執行以下命令來取得 Pod 清單。

  ```
  kubectl get pods -n amazon-cloudwatch
  ```
+ 執行以下命令和檢查輸出底部的事件。

  ```
  kubectl describe pod pod-name -n amazon-cloudwatch
  ```
+ 執行以下命令來檢查日誌。

  ```
  kubectl logs pod-name -n amazon-cloudwatch
  ```

## 未經授權的緊急事件：無法從 kubelet 擷取 cadvisor 資料
<a name="ContainerInsights-setup-EKS-troubleshooting-permissions"></a>

如果部署失敗，並出現錯誤 `Unauthorized panic: Cannot retrieve cadvisor data from kubelet`，您的 kubelet 可能還沒有啟用 Webhook 授權模式。容器洞見需要使用此模式。如需詳細資訊，請參閱[在 CloudWatch 中驗證 Container Insights 的先決條件](Container-Insights-prerequisites.md)。

## 在 Amazon ECS 上已刪除和重新建立的叢集上部署 Container Insights
<a name="ContainerInsights-troubleshooting-recreate"></a>

若您刪除未啟用 Container Insights 的現有 Amazon ECS 叢集，且您使用相同的名稱將其重新建立，則您無法在重新建立此新叢集時在其上啟用 Container Insights。您可以透過重新建立它，然後輸入以下命令來進行啟用：

```
aws ecs update-cluster-settings --cluster myCICluster --settings name=container Insights,value=enabled
```

## 無效端點錯誤
<a name="ContainerInsights-setup-invalid-endpoint"></a>

如果您看到類似以下的錯誤訊息，請檢查確認您已將您使用的命令中的所有預留位置 (例如 *cluster-name* 和 *region-name*) 取代為部署專用的正確資訊。

```
"log": "2020-04-02T08:36:16Z E! cloudwatchlogs: code: InvalidEndpointURL, message: invalid endpoint uri, original error: &url.Error{Op:\"parse\", URL:\"https://logs.{{region_name}}.amazonaws.com/\", Err:\"{\"}, &awserr.baseError{code:\"InvalidEndpointURL\", message:\"invalid endpoint uri\", errs:[]error{(*url.Error)(0xc0008723c0)}}\n",
```

## 指標沒有出現在主控台
<a name="ContainerInsights-setup-EKS-troubleshooting-nometrics"></a>

如果您在 中看不到任何 Container Insights 指標 AWS 管理主控台，請確定您已完成 Container Insights 的設定。在完整設定容器洞見前指標都不會出現。如需詳細資訊，請參閱[設定 Container Insights](deploy-container-insights.md)。

## 升級叢集後，Amazon EKS 或 Kubernetes 上的 Pod 指標遺失
<a name="ContainerInsights-troubleshooting-podmetrics-missing"></a>

如果您將 CloudWatch 代理程式作為 daemonset 部署在新叢集或升級的叢集上後，遺失了全部或部分 Pod 指標，或者您看到包含訊息 `W! No pod metric collected` 的錯誤日誌。

這些錯誤可能是由容器執行時間中的變更造成的，例如 containerd 或 Docker systemd cgroup 驅動程式。您通常可以透過更新部署資訊清單來解決這個問題，以便從主機的 containerd 套接字掛載到容器中。請參閱下列範例：

```
# For full example see https://github.com/aws-samples/amazon-cloudwatch-container-insights/blob/latest/k8s-deployment-manifest-templates/deployment-mode/daemonset/container-insights-monitoring/cwagent/cwagent-daemonset.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: cloudwatch-agent
  namespace: amazon-cloudwatch
spec:
  template:
    spec:
      containers:
        - name: cloudwatch-agent
# ...
          # Don't change the mountPath
          volumeMounts:
# ...
            - name: dockersock
              mountPath: /var/run/docker.sock
              readOnly: true
            - name: varlibdocker
              mountPath: /var/lib/docker
              readOnly: true
            - name: containerdsock # NEW mount
              mountPath: /run/containerd/containerd.sock
              readOnly: true
# ...
      volumes:
# ...
        - name: dockersock
          hostPath:
            path: /var/run/docker.sock
        - name: varlibdocker
          hostPath:
            path: /var/lib/docker
        - name: containerdsock # NEW volume
          hostPath:
            path: /run/containerd/containerd.sock
```

## 使用 Bottlerocket for Amazon EKS 時，沒有 Pod 指標
<a name="ContainerInsights-troubleshooting-bottlerocket"></a>

Bottlerocket 是以 Linux 為基礎的開源作業系統，由 AWS 為特定用途而建置，用於執行容器。

Bottlerocket 使用主機上的不同 `containerd` 路徑，因此您需要將磁碟區變更為其位置。如果不提供，您會在日誌中看到錯誤，其中包括 `W! No pod metric collected`。請參閱以下範例。

```
volumes:
  # ... 
    - name: containerdsock
      hostPath:
        # path: /run/containerd/containerd.sock
        # bottlerocket does not mount containerd sock at normal place
        # https://github.com/bottlerocket-os/bottlerocket/commit/91810c85b83ff4c3660b496e243ef8b55df0973b
        path: /run/dockershim.sock
```

## 使用 Amazon EKS 或 Kubernetes 的 containerd 執行時間時，沒有容器檔案系統指標
<a name="ContainerInsights-troubleshooting-containerd"></a>

這是已知問題，社群貢獻者正在處理。如需詳細資訊，請參閱 GitHub 上的 [containerd 的硬碟使用量](https://github.com/google/cadvisor/issues/2785)和 [cadvisor for containerd 不支援容器檔案系統指標](https://github.com/aws/amazon-cloudwatch-agent/issues/192)。

## 收集 Prometheus 指標時，CloudWatch 代理程式的未預期日誌量增加
<a name="ContainerInsights-troubleshooting-log-volume-increase"></a>

這是 CloudWatch 代理程式版本 1.247347.6b250880 中推出的迴歸功能。此迴歸功能已在代理程式的更新版本中予以修正。其影響僅限於客戶收集 CloudWatch 代理程式本身的日誌，並且也在使用 Prometheus 的案例。如需詳細資訊，請參閱 GitHub 上的[[prometheus] 代理程式正在列印日誌中的所有湊集指標](https://github.com/aws/amazon-cloudwatch-agent/issues/209)。

## 在 Dockerhub 中找不到版本備註中提到的最新 Docker 影像
<a name="ContainerInsights-troubleshooting-docker-image"></a>

在我們內部開始實際發佈之前，我們在 Github 上更新發佈說明和標籤。在 Github 上增加版本編號後，通常需要 1-2 週的時間才能在登錄檔上查看最新的 Docker 影像。CloudWatch 代理程式容器映像並不會每晚發佈。您可以在下列位置直接從來源建置映像：https：//[https://github.com/aws/amazon-cloudwatch-agent/tree/main/amazon-cloudwatch-container-insights/cloudwatch-agent-dockerfile](https://github.com/aws/amazon-cloudwatch-agent/tree/main/amazon-cloudwatch-container-insights/cloudwatch-agent-dockerfile)

## CloudWatch 代理程式上的 CrashLoopBackoff 錯誤
<a name="ContainerInsights-troubleshooting-crashloopbackoff"></a>

若您看到 CloudWatch 代理程式的 `CrashLoopBackOff` 錯誤，請確認您已正確設定您的 IAM 許可。如需詳細資訊，請參閱[在 CloudWatch 中驗證 Container Insights 的先決條件](Container-Insights-prerequisites.md)。

## CloudWatch 代理程式或 Fluentd Pod 卡在擱置中狀態
<a name="ContainerInsights-troubleshooting-pending"></a>

若您的 CloudWatch 代理程式或 Fluentd Pod 卡在 `Pending` 狀態或出現 `FailedScheduling` 錯誤，請根據核心數和代理程式所需的 RAM 數量來判斷您的節點是否具有足夠的運算資源。輸入以下命令來描述 Pod：

```
kubectl describe pod cloudwatch-agent-85ppg -n amazon-cloudwatch
```

# 建置您自己的 CloudWatch 代理程式 Docker 影像
<a name="ContainerInsights-build-docker-image"></a>

您可以參考位於 https：// 的 Dockerfile 來建置自己的 CloudWatch 代理程式 Docker 映像。 [ https://github.com/aws-samples/amazon-cloudwatch-container-insights/blob/latest/cloudwatch-agent-dockerfile/Dockerfile](https://github.com/aws-samples/amazon-cloudwatch-container-insights/blob/latest/cloudwatch-agent-dockerfile/Dockerfile)

Dockerfile 支援直接使用 `docker buildx` 建置多架構映像。

# 在容器中部署其他 CloudWatch 代理程式功能
<a name="ContainerInsights-other-agent-features"></a>

您可以使用 CloudWatch 代理程式在容器中部署其他監控功能。重要功能如下所示：
+ **內嵌指標格式**— 如需詳細資訊，請參閱 [在日誌中內嵌指標](CloudWatch_Embedded_Metric_Format.md)。
+ **StatsD**— 如需詳細資訊，請參閱 [使用 StatsD 擷取自訂指標](CloudWatch-Agent-custom-metrics-statsd.md)。

指示和必要的檔案位於 GitHub 上的以下位置：
+ 如需 Amazon ECS 容器，請參閱[根據部署模式的範例 Amazon ECS 任務定義](https://github.com/aws-samples/amazon-cloudwatch-container-insights/tree/latest/ecs-task-definition-templates/deployment-mode)。
+ 如需 Amazon EKS 和 Kubernetes 容器，請參閱[根據部署模式的 Kubernetes YAML 檔案範例](https://github.com/aws-samples/amazon-cloudwatch-container-insights/tree/latest/k8s-deployment-manifest-templates/deployment-mode)。

# Lambda Insights
<a name="Lambda-Insights"></a>

CloudWatch Lambda Insights 是一個監控與故障排除解決方案，適用於在 AWS Lambda上執行的無伺服器應用程式。此解決方案會收集、彙總和摘要系統層級的指標，包括 CPU 時間、記憶體、磁碟和網路。它也會收集、彙總和摘要診斷資訊，例如冷啟動和 Lambda 工作人員關閉，協助您隔離 Lambda 函數問題並快速加以解決。

Lambda Insights 使用新的 CloudWatch Lambda 延伸，提供它作為一個 Lambda 層。當您在 Lambda 函數上安裝此延伸時，它會收集系統層級指標，並對 Lambda 函數的每個叫用發出單一效能日誌事件。CloudWatch 使用內嵌的指標格式，從日誌事件中擷取指標。

**注意**  
僅在使用 Amazon Linux 2 和 Amazon Linux 2023 的 Lambda 執行時期上支援 Lambda Insights 代理程式。

如需 Lambda 延伸模組的詳細資訊，請參閱[使用 AWS Lambda 延伸模組](https://docs.aws.amazon.com/lambda/latest/dg/using-extensions.html)。如需內嵌指標格式的詳細資訊，請參閱[在日誌中內嵌指標](CloudWatch_Embedded_Metric_Format.md)。

您可以使用 Lambda Insights 搭配任何 Lambda 函數，其中該函數使用了可支援 Lambda 延伸的 Lambda 執行時間。如需這些執行時間的清單，請參閱 [Lambda Extensions API](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-extensions-api.html)。

**定價**

對於為 Lambda Insights 啟用的每個 Lambda 函數，您只需為指標和日誌的使用量付費。如需定價範例，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

您需支付 Lambda 延伸所耗用的執行時間 (以 1 毫秒為單位遞增)。如需 Lambda 定價的詳細資訊，請參閱 [AWS Lambda 定價](https://aws.amazon.com/lambda/pricing/)。

# 開始使用 Lambda Insights
<a name="Lambda-Insights-Getting-Started"></a>

若要在 Lambda 函數上啟用 Lambda Insights，您可以在 Lambda 主控台中使用一鍵切換。或者，您可以使用 AWS CLI、 CloudFormation、 CLI AWS Serverless Application Model 或 AWS Cloud Development Kit (AWS CDK)。

以下各節提供完成這些步驟的詳細說明。

**Topics**
+ [Lambda Insights 延伸的可用版本](Lambda-Insights-extension-versions.md)
+ [使用主控台在現有的 Lambda 函數上啟用 Lambda Insights](Lambda-Insights-Getting-Started-console.md)
+ [使用 AWS CLI 在現有的 Lambda 函數上啟用 Lambda Insights](Lambda-Insights-Getting-Started-cli.md)
+ [使用 AWS SAM CLI 在現有的 Lambda 函數上啟用 Lambda Insights](Lambda-Insights-Getting-Started-SAM-CLI.md)
+ [使用 CloudFormation 在現有的 Lambda 函數上啟用 Lambda Insights](Lambda-Insights-Getting-Started-cloudformation.md)
+ [使用 AWS CDK 在現有的 Lambda 函數上啟用 Lambda Insights](Lambda-Insights-Getting-Started-clouddevelopmentkit.md)
+ [使用 Serverless Framework 在現有的 Lambda 函式上啟用 Lambda Insights](Lambda-Insights-Getting-Started-serverless.md)
+ [在 Lambda 容器映像部署上啟用 Lambda Insights](Lambda-Insights-Getting-Started-docker.md)
+ [更新函式上的 Lambda Insights 延伸模組版本](Lambda-Insights-Update-Extension.md)

# Lambda Insights 延伸的可用版本
<a name="Lambda-Insights-extension-versions"></a>

本節列出 Lambda Insights 延伸模組版本，以及每個 AWS 區域中用於這些延伸模組的 ARNs。

**Topics**
+ [x86-64 平台](Lambda-Insights-extension-versionsx86-64.md)
+ [ARM64 平台](Lambda-Insights-extension-versionsARM.md)

# x86-64 平台
<a name="Lambda-Insights-extension-versionsx86-64"></a>

本節列出 x86-64 平台的 Lambda Insights 擴充功能版本，以及每個 AWS 區域中用於這些擴充功能的 ARNs。

**重要**  
Lambda Insights 延伸模組 1.0.317.0 及更高版本不支援 Amazon Linux 1。

## 1.0.660.0
<a name="Lambda-Insights-extension-1.0.660.0"></a>

1.0.660.0 版包含 Lambda Insights 延伸支援在 Lambda 受管執行個體上執行的 Lambda 函數。對於在 Lambda 受管執行個體上執行的函數，延伸項目每分鐘會傳送一次 EMF 日誌事件，以一分鐘的精細程度建立 12 個 CloudWatch 指標。

**1.0.660.0 版ARNs **

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:64`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:64`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:64`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:64`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:56`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:56`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension:38`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension:40`  | 
|  亞太地區 (馬來西亞) |  `arn:aws:lambda:ap-southeast-5:590183865173:layer:LambdaInsightsExtension:13`  | 
|  亞太地區 (墨爾本) |  `arn:aws:lambda:ap-southeast-4:158895979263:layer:LambdaInsightsExtension:33`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:62`  | 
|  亞太區域 (紐西蘭) |  `arn:aws:lambda:ap-southeast-6:727646510379:layer:LambdaInsightsExtension:6`  | 
|  亞太地區 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension:45`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:63`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:64`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:64`  | 
|  亞太區域 (台北) |  `arn:aws:lambda:ap-east-2:145023102084:layer:LambdaInsightsExtension:13`  | 
|  亞太區域 (泰國) |  `arn:aws:lambda:ap-southeast-7:761018874580:layer:LambdaInsightsExtension:13`  | 
|  亞太地區 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:91`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:63`  | 
|  加拿大西部 (卡加利) |  `arn:aws:lambda:ca-west-1:946466191631:layer:LambdaInsightsExtension:25`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:51`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:51`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:64`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:64`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:64`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:56`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:63`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension:40`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:61`  | 
|  歐洲 (蘇黎世) |  `arn:aws:lambda:eu-central-2:033019950311:layer:LambdaInsightsExtension:39`  | 
|  以色列 (特拉維夫) |  `arn:aws:lambda:il-central-1:459530977127:layer:LambdaInsightsExtension:33`  | 
|  墨西哥 (中部) |  `arn:aws:lambda:mx-central-1:879381266642:layer:LambdaInsightsExtension:13`  | 
|  Middle East (Bahrain) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:56`  | 
|  中東 (阿拉伯聯合大公國) |  `arn:aws:lambda:me-central-1:732604637566:layer:LambdaInsightsExtension:39`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:63`  | 
|  AWS GovCloud （美國東部） |  `arn:aws-us-gov:lambda:us-gov-east-1:122132214140:layer:LambdaInsightsExtension:24`  | 
|  AWS GovCloud （美國西部） |  `arn:aws-us-gov:lambda:us-gov-west-1:751350123760:layer:LambdaInsightsExtension:24`  | 

## 1.0.498.0
<a name="Lambda-Insights-extension-1.0.498.0"></a>

包括錯誤修正和效能改進的版本 1.0.498.0。

**1.0.498.0 版ARNs **

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:60`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:60`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:60`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:60`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:52`  | 
|  亞太區域 (泰國) |  `arn:aws:lambda:ap-southeast-7:761018874580:layer:LambdaInsightsExtension:8`  | 
|  亞太區域 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:52`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension:34`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension:36`  | 
|  亞太地區 (馬來西亞) |  `arn:aws:lambda:ap-southeast-5:590183865173:layer:LambdaInsightsExtension:9`  | 
|  亞太地區 (墨爾本) |  `arn:aws:lambda:ap-southeast-4:158895979263:layer:LambdaInsightsExtension:29`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:58`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension:41`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:59`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:60`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:60`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:87`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:59`  | 
|  加拿大西部 (卡加利) |  `arn:aws:lambda:ca-west-1:946466191631:layer:LambdaInsightsExtension:21`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:48`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:48`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:60`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:60`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:60`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:52`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:59`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension:36`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:57`  | 
|  歐洲 (蘇黎世) |  `arn:aws:lambda:eu-central-2:033019950311:layer:LambdaInsightsExtension:35`  | 
|  以色列 (特拉維夫) |  `arn:aws:lambda:il-central-1:459530977127:layer:LambdaInsightsExtension:29`  | 
|  墨西哥 (中部) |  `arn:aws:lambda:mx-central-1:879381266642:layer:LambdaInsightsExtension:8`  | 
|  Middle East (Bahrain) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:52`  | 
|  中東 (阿拉伯聯合大公國) |  `arn:aws:lambda:me-central-1:732604637566:layer:LambdaInsightsExtension:35`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:59`  | 
|  AWS GovCloud （美國東部） |  `arn:aws-us-gov:lambda:us-gov-east-1:122132214140:layer:LambdaInsightsExtension:24`  | 
|  AWS GovCloud （美國西部） |  `arn:aws-us-gov:lambda:us-gov-west-1:751350123760:layer:LambdaInsightsExtension:24`  | 
|  亞太區域 (紐西蘭) |  `arn:aws:lambda:ap-southeast-6:727646510379:layer:LambdaInsightsExtension:1`  | 
|  亞太區域 (台北) |  `arn:aws:lambda:ap-east-2:145023102084:layer:LambdaInsightsExtension:8`  | 

## 1.0.404.0
<a name="Lambda-Insights-extension-1.0.404.0"></a>

版本 1.0.404.0 將 Lambda Insights 延伸模組的二進位大小從 \$110MB 縮減至 \$16MB，然後將 Lambda Insights 延伸模組圖層的 zip 檔案大小從 \$14MB 縮減至 \$12.7MB。同時將代理程式的整體記憶體消耗量從 \$110MB 縮減至 \$17MB。

**1.0.404.0 版ARNs **

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:56`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:56`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:56`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:56`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:47`  | 
|  亞太區域 (泰國) |  `arn:aws:lambda:ap-southeast-7:761018874580:layer:LambdaInsightsExtension:3`  | 
|  亞太區域 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:47`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension:29`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension:33`  | 
|  亞太地區 (馬來西亞) |  `arn:aws:lambda:ap-southeast-5:590183865173:layer:LambdaInsightsExtension:4`  | 
|  亞太地區 (墨爾本) |  `arn:aws:lambda:ap-southeast-4:158895979263:layer:LambdaInsightsExtension:24`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:54`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension:37`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:55`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:56`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:56`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:83`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:55`  | 
|  加拿大西部 (卡加利) |  `arn:aws:lambda:ca-west-1:946466191631:layer:LambdaInsightsExtension:16`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:46`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:46`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:56`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:56`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:56`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:47`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:55`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension:31`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:53`  | 
|  歐洲 (蘇黎世) |  `arn:aws:lambda:eu-central-2:033019950311:layer:LambdaInsightsExtension:30`  | 
|  以色列 (特拉維夫) |  `arn:aws:lambda:il-central-1:459530977127:layer:LambdaInsightsExtension:23`  | 
|  墨西哥 (中部) |  `arn:aws:lambda:mx-central-1:879381266642:layer:LambdaInsightsExtension:3`  | 
|  Middle East (Bahrain) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:47`  | 
|  中東 (阿拉伯聯合大公國) |  `arn:aws:lambda:me-central-1:732604637566:layer:LambdaInsightsExtension:30`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:55`  | 
|  AWS GovCloud （美國東部） |  `arn:aws-us-gov:lambda:us-gov-east-1:122132214140:layer:LambdaInsightsExtension:24`  | 
|  AWS GovCloud （美國西部） |  `arn:aws-us-gov:lambda:us-gov-west-1:751350123760:layer:LambdaInsightsExtension:24`  | 

## 1.0.391.0
<a name="Lambda-Insights-extension-1.0.391.0"></a>

**重要**  
版本 1.0.391.0 變更了 Lambda Insights 收集與回報執行緒使用情況的方式。在舊版延伸模組中，`threads_max` 指標回報程序 ID 為 1 的程序中，正在執行的執行緒數上限。從版本 1.0.391.0 開始，此指標回報函式執行期間，在執行環境中的所有程序內，於任意時間點同時執行的執行緒數上限。這包括 Lambda 函式的程序、延伸模組的程序、系統/執行時期特定程序等。這可讓 `threads_max` 指標在評估剩餘可用執行緒時更為全面。如需執行緒和程序配額的詳細資訊，請參閱 [Lambda 配額](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html)。

版本 1.0.391.0 也新增了對亞太區域 (泰國) 和墨西哥 (中部) 區域的支援。

**1.0.391.0 版ARNs **

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:55`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:55`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:55`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:55`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:46`  | 
|  亞太區域 (泰國) |  `arn:aws:lambda:ap-southeast-7:761018874580:layer:LambdaInsightsExtension:2`  | 
|  亞太區域 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:46`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension:28`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension:32`  | 
|  亞太地區 (馬來西亞) |  `arn:aws:lambda:ap-southeast-5:590183865173:layer:LambdaInsightsExtension:3`  | 
|  亞太地區 (墨爾本) |  `arn:aws:lambda:ap-southeast-4:158895979263:layer:LambdaInsightsExtension:23`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:53`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension:36`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:54`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:55`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:55`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:82`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:54`  | 
|  加拿大西部 (卡加利) |  `arn:aws:lambda:ca-west-1:946466191631:layer:LambdaInsightsExtension:15`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:45`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:45`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:55`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:55`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:55`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:46`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:54`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension:30`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:52`  | 
|  歐洲 (蘇黎世) |  `arn:aws:lambda:eu-central-2:033019950311:layer:LambdaInsightsExtension:29`  | 
|  以色列 (特拉維夫) |  `arn:aws:lambda:il-central-1:459530977127:layer:LambdaInsightsExtension:23`  | 
|  墨西哥 (中部) |  `arn:aws:lambda:mx-central-1:879381266642:layer:LambdaInsightsExtension:2`  | 
|  Middle East (Bahrain) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:46`  | 
|  中東 (阿拉伯聯合大公國) |  `arn:aws:lambda:me-central-1:732604637566:layer:LambdaInsightsExtension:29`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:54`  | 
|  AWS GovCloud （美國東部） |  `arn:aws-us-gov:lambda:us-gov-east-1:122132214140:layer:LambdaInsightsExtension:23`  | 
|  AWS GovCloud （美國西部） |  `arn:aws-us-gov:lambda:us-gov-west-1:751350123760:layer:LambdaInsightsExtension:23`  | 

## 1.0.333.0
<a name="Lambda-Insights-extension-1.0.333.0"></a>

版本 1.0.333.0 包含錯誤修正。

**1.0.333.0 版ARNs **

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:53`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:53`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:53`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:53`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:44`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:44`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension:26`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension:30`  | 
|  亞太地區 (馬來西亞) |  `arn:aws:lambda:ap-southeast-5:590183865173:layer:LambdaInsightsExtension:1`  | 
|  亞太地區 (墨爾本) |  `arn:aws:lambda:ap-southeast-4:158895979263:layer:LambdaInsightsExtension:21`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:51`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension:34`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:52`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:53`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:53`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:80`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:52`  | 
|  加拿大西部 (卡加利) |  `arn:aws:lambda:ca-west-1:946466191631:layer:LambdaInsightsExtension:13`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:43`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:43`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:53`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:53`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:53`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:44`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:52`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension:28`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:50`  | 
|  歐洲 (蘇黎世) |  `arn:aws:lambda:eu-central-2:033019950311:layer:LambdaInsightsExtension:27`  | 
|  以色列 (特拉維夫) |  `arn:aws:lambda:il-central-1:459530977127:layer:LambdaInsightsExtension:21`  | 
|  Middle East (Bahrain) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:44`  | 
|  中東 (阿拉伯聯合大公國) |  `arn:aws:lambda:me-central-1:732604637566:layer:LambdaInsightsExtension:27`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:52`  | 
|  AWS GovCloud （美國東部） |  `arn:aws-us-gov:lambda:us-gov-east-1:122132214140:layer:LambdaInsightsExtension:21`  | 
|  AWS GovCloud （美國西部） |  `arn:aws-us-gov:lambda:us-gov-west-1:751350123760:layer:LambdaInsightsExtension:21`  | 

## 1.0.317.0
<a name="Lambda-Insights-extension-1.0.317.0"></a>

版本 1.0.317.0 移除了對 Amazon Linux 1 平台的支援，並包含錯誤修正。它還包含對 AWS GovCloud (US) 區域的支援。

**1.0.317.0 版ARNs **

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:52`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:52`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:52`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:52`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:43`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:43`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension:25`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension:29`  | 
|  亞太地區 (墨爾本) |  `arn:aws:lambda:ap-southeast-4:158895979263:layer:LambdaInsightsExtension:20`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:50`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension:33`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:51`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:52`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:52`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:79`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:51`  | 
|  加拿大西部 (卡加利) |  `arn:aws:lambda:ca-west-1:946466191631:layer:LambdaInsightsExtension:12`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:42`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:42`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:52`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:52`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:52`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:43`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:51`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension:27`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:49`  | 
|  歐洲 (蘇黎世) |  `arn:aws:lambda:eu-central-2:033019950311:layer:LambdaInsightsExtension:26`  | 
|  以色列 (特拉維夫) |  `arn:aws:lambda:il-central-1:459530977127:layer:LambdaInsightsExtension:20`  | 
|  Middle East (Bahrain) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:43`  | 
|  中東 (阿拉伯聯合大公國) |  `arn:aws:lambda:me-central-1:732604637566:layer:LambdaInsightsExtension:26`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:51`  | 
|  AWS GovCloud （美國東部） |  `arn:aws-us-gov:lambda:us-gov-east-1:122132214140:layer:LambdaInsightsExtension:19`  | 
|  AWS GovCloud （美國西部） |  `arn:aws-us-gov:lambda:us-gov-west-1:751350123760:layer:LambdaInsightsExtension:19`  | 

## 1.0.295.0
<a name="Lambda-Insights-extension-1.0.295.0"></a>

版本 1.0.295.0 包含所有相容執行時期的相依項更新。

**1.0.295.0 版ARNs **

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:51`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:51`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:51`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:51`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:42`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:42`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension:24`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension:28`  | 
|  亞太地區 (墨爾本) |  `arn:aws:lambda:ap-southeast-4:158895979263:layer:LambdaInsightsExtension:19`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:49`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension:32`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:50`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:51`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:51`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:78`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:50`  | 
|  加拿大西部 (卡加利) |  `arn:aws:lambda:ca-west-1:946466191631:layer:LambdaInsightsExtension:11`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:41`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:41`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:51`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:51`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:51`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:42`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:50`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension:26`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:48`  | 
|  歐洲 (蘇黎世) |  `arn:aws:lambda:eu-central-2:033019950311:layer:LambdaInsightsExtension:25`  | 
|  以色列 (特拉維夫) |  `arn:aws:lambda:il-central-1:459530977127:layer:LambdaInsightsExtension:19`  | 
|  Middle East (Bahrain) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:42`  | 
|  中東 (阿拉伯聯合大公國) |  `arn:aws:lambda:me-central-1:732604637566:layer:LambdaInsightsExtension:25`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:50`  | 

## 1.0.275.0
<a name="Lambda-Insights-extension-1.0.275.0"></a>

版本 1.0.275.0 包含所有相容執行時期的重要相依項更新。

**1.0.275.0 版ARNs **

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:49`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:49`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:49`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:49`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:40`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:40`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension:22`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension:26`  | 
|  亞太地區 (墨爾本) |  `arn:aws:lambda:ap-southeast-4:158895979263:layer:LambdaInsightsExtension:17`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:47`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension:30`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:48`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:49`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:49`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:76`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:48`  | 
|  加拿大西部 (卡加利) |  `arn:aws:lambda:ca-west-1:946466191631:layer:LambdaInsightsExtension:9`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:39`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:39`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:49`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:49`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:49`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:40`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:48`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension:24`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:46`  | 
|  歐洲 (蘇黎世) |  `arn:aws:lambda:eu-central-2:033019950311:layer:LambdaInsightsExtension:23`  | 
|  以色列 (特拉維夫) |  `arn:aws:lambda:il-central-1:459530977127:layer:LambdaInsightsExtension:17`  | 
|  Middle East (Bahrain) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:40`  | 
|  中東 (阿拉伯聯合大公國) |  `arn:aws:lambda:me-central-1:732604637566:layer:LambdaInsightsExtension:23`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:48`  | 

## 1.0.273.0
<a name="Lambda-Insights-extension-1.0.273.0"></a>

版本 1.0.273.0 包含所有相容執行時期的重要錯誤修正，並新增對加拿大西部 (卡加利) 區域的支援。

**1.0.273.0 版ARNs **

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:45`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:45`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:45`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:45`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:35`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:35`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension:17`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension:21`  | 
|  亞太地區 (墨爾本) |  `arn:aws:lambda:ap-southeast-4:158895979263:layer:LambdaInsightsExtension:12`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:43`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension:26`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:44`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:45`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:45`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:72`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:44`  | 
|  加拿大西部 (卡加利) |  `arn:aws:lambda:ca-west-1:946466191631:layer:LambdaInsightsExtension:4`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:36`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:36`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:45`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:45`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:45`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:35`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:44`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension:19`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:42`  | 
|  歐洲 (蘇黎世) |  `arn:aws:lambda:eu-central-2:033019950311:layer:LambdaInsightsExtension:17`  | 
|  以色列 (特拉維夫) |  `arn:aws:lambda:il-central-1:459530977127:layer:LambdaInsightsExtension:12`  | 
|  Middle East (Bahrain) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:35`  | 
|  中東 (阿拉伯聯合大公國) |  `arn:aws:lambda:me-central-1:732604637566:layer:LambdaInsightsExtension:18`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:44`  | 

## 1.0.229.0
<a name="Lambda-Insights-extension-1.0.229.0"></a>

1.0.229.0 版包括所有相容執行期的重要錯誤修正，並新增對以色列 (特拉維夫) 區域的支援。

**1.0.229.0 版的 ARN**

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:38`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:38`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:38`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:38`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:28`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:28`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension:10`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension:14`  | 
|  亞太地區 (墨爾本) |  `arn:aws:lambda:ap-southeast-4:158895979263:layer:LambdaInsightsExtension:5`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:36`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension:19`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:37`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:38`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:38`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:60`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:37`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:29`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:29`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:38`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:38`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:38`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:28`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:37`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension:12`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:35`  | 
|  歐洲 (蘇黎世) |  `arn:aws:lambda:eu-central-2:033019950311:layer:LambdaInsightsExtension:11`  | 
|  以色列 (特拉維夫) |  `arn:aws:lambda:il-central-1:459530977127:layer:LambdaInsightsExtension:5`  | 
|  Middle East (Bahrain) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:28`  | 
|  中東 (阿拉伯聯合大公國) |  `arn:aws:lambda:me-central-1:732604637566:layer:LambdaInsightsExtension:11`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:37`  | 

## 1.0.178.0
<a name="Lambda-Insights-extension-1.0.178.0"></a>

1.0.178.0 版新增了對下列 AWS 區域的支援。
+ 亞太地區 (海德拉巴)
+ 亞太地區 (雅加達)
+ 歐洲 (西班牙)
+ 歐洲 (蘇黎世)
+ 中東 (阿拉伯聯合大公國)

**1.0.178.0 版的 ARN**

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:35`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:33`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:33`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:33`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:25`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:25`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension:8`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension:11`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:31`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension:2`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:32`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:33`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:33`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:50`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:32`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:26`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:26`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:35`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:33`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:33`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:25`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:32`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension:10`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:30`  | 
|  歐洲 (蘇黎世) |  `arn:aws:lambda:eu-central-2:033019950311:layer:LambdaInsightsExtension:7`  | 
|  Middle East (Bahrain) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:25`  | 
|  中東 (阿拉伯聯合大公國) |  `arn:aws:lambda:me-central-1:732604637566:layer:LambdaInsightsExtension:9`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:32`  | 

## 1.0.143.0
<a name="Lambda-Insights-extension-1.0.143.0"></a>

1.0.143.0 版修正了與 Python 3.7 和 Go 1.x 的相容性錯誤。Python 3.6 Lambda 執行階段已被棄用。如需詳細資訊，請參閱 [Lambda 執行階段](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html)。

**1.0.143.0 版的 ARN**

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:21`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:21`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:20`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:21`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:13`  | 
|  亞太區域 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:13`  | 
|  亞太區域 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:21`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension:2`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:20`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:21`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:21`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:32`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:20`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:14`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:14`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:21`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:21`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:21`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:13`  | 
|  歐洲 (巴黎) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:20`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:20`  | 
|  中東 (巴林) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:13`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:20`  | 

## 1.0.135.0
<a name="Lambda-Insights-extension-1.0.135.0"></a>

1.0.135.0 版包含 Lambda Insights 如何收集和報告磁碟和檔案描述項使用情況的錯誤修復。在之前版本的延伸中，`tmp_free` 指標報告了運行函數時 `/tmp` 目錄的最大可用空間。此版本改為將指標變更為報告最小值，使其在評估磁碟使用情況時更有用。如需有關 `tmp` 目錄儲存配額的詳細資訊，請參 [Lambda 配額](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html)。

1.0.135.0 版現在還報告檔案描述項使用情況 (`fd_use` 和 `fd_max`) 作為跨程序的最大值，而不是報告作業系統層級。

**適用於 1.0.135.0 版的 ARN**

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:18`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:18`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:18`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:18`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:11`  | 
|  亞太區域 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:11`  | 
|  亞太區域 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:18`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension:1`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:18`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:18`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:18`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:25`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:18`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:11`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:11`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:18`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:18`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:18`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:11`  | 
|  歐洲 (巴黎) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:18`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:18`  | 
|  中東 (巴林) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:11`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:18`  | 

## 1.0.119.0
<a name="Lambda-Insights-extension-1.0.119.0"></a>

**適用於版本 1.0.119.0 的 ARN**

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:16`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:16`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:16`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:16`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:9`  | 
|  亞太區域 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:9`  | 
|  Asia Pacific (Mumbai) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:16`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:16`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:16`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:16`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:23`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:16`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:9`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:9`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:16`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:16`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:16`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:9`  | 
|  歐洲 (巴黎) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:16`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:16`  | 
|  中東 (巴林) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:9`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:16`  | 

## 1.0.98.0
<a name="Lambda-Insights-extension-1.0.98.0"></a>

此版本會移除不必要的日誌記錄，同時還解決了 AWS Serverless Application Model CLI 本機呼叫的問題。如需這個問題的詳細資訊，請參閱[使用 'sam local invoke' 新增 LambdaInsightsExtension 可能導致逾時](https://github.com/aws/aws-sam-cli/issues/2469)。

**1.0.98.0 版的 ARN**

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:14`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:14`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:14`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:14`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension:8`  | 
|  亞太區域 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension:8`  | 
|  Asia Pacific (Mumbai) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:14`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:14`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:14`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:14`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:14`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:14`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension:8`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension:8`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:14`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:14`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:14`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension:8`  | 
|  歐洲 (巴黎) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:14`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:14`  | 
|  中東 (巴林) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension:8`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:14`  | 

## 1.0.89.0
<a name="Lambda-Insights-extension-1.0.89.0"></a>

此版本修正了效能事件時間戳記，以始終表示函數叫用的開始。

**1.0.89.0 版的 ARN**

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:12`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:12`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:12`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:12`  | 
|  亞太區域 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:12`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:12`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:12`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:12`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:12`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:12`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:12`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:12`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:12`  | 
|  歐洲 (巴黎) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:12`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:12`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:12`  | 

## 1.0.86.0
<a name="Lambda-Insights-extension-1.0.86.0"></a>

在 1.0.54.0 版中，記憶體指標有時報告不正確，有時候高於 100%。1.0.86.0 版使用與 Lambda 平台指標相同的事件資料，藉此修正記憶體測量問題。這表示您可能會看到記錄的記憶體指標值出現顯著變更。這可藉由使用新的 Lambda Logs API 來予以達成。這可以更準確地測量 Lambda 沙盒記憶體用量。不過，需要注意的是，如果函數沙盒逾時且隨後減速，Lambda Logs API 就無法傳遞平台報告事件。在此案例中。Lambda Insights 無法記錄叫用指標。如需 Lambda Logs API 的詳細資訊，請參閱 [AWS Lambda Logs API](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-logs-api.html)。

**1.0.86.0 版中的新功能**
+ 使用 Lambda Logs API 來糾正記憶體指標。這就解決了之前的記憶體統計資料大於 100% 的問題。
+ 將 `Init Duration` 作為新的 CloudWatch 指標予以推薦。
+ 使用叫用 ARN 為別名和叫用版本新增 **version** 維度。如果您使用 Lambda 別名或版本來達成增量改進部署 (例如藍綠色部署)，則可以根據叫用的別名檢視指標。如果函數未使用別名或版本，則不會套用 **version** 維度。如需詳細資訊，請參閱 [Lambda 函數別名](https://docs.aws.amazon.com/lambda/latest/dg/configuration-aliases.html)。
+ 將 `billed_mb_ms field` 新增至效能事件，以顯示每次叫用的成本。這不會考慮與佈建並行相關聯的任何成本。
+ 將 `billed_duration` 和 `duration` 欄位新增至效能事件。

**1.0.86.0 版的 ARN**

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:11`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:11`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:11`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:11`  | 
|  亞太區域 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:11`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:11`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:11`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:11`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:11`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:11`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:11`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:11`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:11`  | 
|  歐洲 (巴黎) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:11`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:11`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:11`  | 

## 1.0.54.0
<a name="Lambda-Insights-extension-1.0.54.0"></a>

1.0.54.0 版是 Lambda Insights 延伸的初始發行版本。

**1.0.54.0 版的 ARN**

下表列出每個可用 AWS 區域中此擴充功能版本的 ARNs。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension:2`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension:2`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:2`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension:2`  | 
|  亞太區域 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension:2`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension:2`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension:2`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension:2`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension:2`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension:2`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension:2`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension:2`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension:2`  | 
|  歐洲 (巴黎) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension:2`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension:2`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension:2`  | 

# ARM64 平台
<a name="Lambda-Insights-extension-versionsARM"></a>

本節列出 ARM64 平台的 Lambda Insights 延伸模組版本，以及每個 AWS 區域中用於這些延伸模組的 ARNs。

**重要**  
Lambda Insights 延伸模組 1.0.317.0 及更高版本不支援 Amazon Linux 1。

## 1.0.660.0
<a name="Lambda-Insights-extension-ARM-1.0.660.0"></a>

1.0.660.0 版包含 Lambda Insights 延伸支援在 Lambda 受管執行個體上執行的 Lambda 函數。對於在 Lambda 受管執行個體上執行的函數，延伸項目每分鐘會傳送一次 EMF 日誌事件，以一分鐘的精細程度建立 12 個 CloudWatch 指標。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:31`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension-Arm64:33`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:29`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:31`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension-Arm64:30`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension-Arm64:30`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension-Arm64:18`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension-Arm64:30`  | 
|  亞太地區 (馬來西亞) |  `arn:aws:lambda:ap-southeast-5:590183865173:layer:LambdaInsightsExtension-Arm64:7`  | 
|  亞太地區 (墨爾本) |  `arn:aws:lambda:ap-southeast-4:158895979263:layer:LambdaInsightsExtension-Arm64:7`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension-Arm64:33`  | 
|  亞太區域 (紐西蘭) |  `arn:aws:lambda:ap-southeast-6:727646510379:layer:LambdaInsightsExtension-Arm64:165`  | 
|  亞太地區 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension-Arm64:28`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:30`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:31`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:31`  | 
|  亞太區域 (台北) |  `arn:aws:lambda:ap-east-2:145023102084:layer:LambdaInsightsExtension-Arm64:7`  | 
|  亞太區域 (泰國) |  `arn:aws:lambda:ap-southeast-7:761018874580:layer:LambdaInsightsExtension-Arm64:7`  | 
|  亞太地區 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:42`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:29`  | 
|  加拿大西部 (卡加利) |  `arn:aws:lambda:ca-west-1:946466191631:layer:LambdaInsightsExtension-Arm64:7`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension-Arm64:4`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension-Arm64:4`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:31`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:31`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:31`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension-Arm64:30`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension-Arm64:29`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension-Arm64:18`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension-Arm64:29`  | 
|  歐洲 (蘇黎世) |  `arn:aws:lambda:eu-central-2:033019950311:layer:LambdaInsightsExtension-Arm64:7`  | 
|  以色列 (特拉維夫) |  `arn:aws:lambda:il-central-1:459530977127:layer:LambdaInsightsExtension-Arm64:7`  | 
|  墨西哥 (中部) |  `arn:aws:lambda:mx-central-1:879381266642:layer:LambdaInsightsExtension-Arm64:7`  | 
|  Middle East (Bahrain) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension-Arm64:30`  | 
|  中東 (阿拉伯聯合大公國) |  `arn:aws:lambda:me-central-1:732604637566:layer:LambdaInsightsExtension-Arm64:7`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:29`  | 
|  AWS GovCloud （美國東部） |  `arn:aws-us-gov:lambda:us-gov-east-1:122132214140:layer:LambdaInsightsExtension-Arm64:6`  | 
|  AWS GovCloud （美國西部） |  `arn:aws-us-gov:lambda:us-gov-west-1:751350123760:layer:LambdaInsightsExtension-Arm64:6`  | 

## 1.0.498.0
<a name="Lambda-Insights-extension-ARM-1.0.498.0"></a>

包括錯誤修正和效能改進的版本 1.0.498.0。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:27`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension-Arm64:29`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:25`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:27`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension-Arm64:26`  | 
|  亞太區域 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension-Arm64:26`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension-Arm64:29`  | 
|  亞太地區 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension-Arm64:14`  | 
|  亞太地區 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:27`  | 
|  亞太地區 (悉尼) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:27`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension-Arm64:26`  | 
|  亞太地區 (墨爾本) |  `arn:aws:lambda:ap-southeast-4:158895979263:layer:LambdaInsightsExtension-Arm64:3`  | 
|  亞太區域 (馬來西亞) |  `arn:aws:lambda:ap-southeast-5:590183865173:layer:LambdaInsightsExtension-Arm64:3`  | 
|  亞太區域 (泰國) |  `arn:aws:lambda:ap-southeast-7:761018874580:layer:LambdaInsightsExtension-Arm64:2`  | 
|  亞太地區 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:38`  | 
|  亞太地區 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:26`  | 
|  亞太地區 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension-Arm64:24`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:25`  | 
|  加拿大西部 (卡加利) |  `arn:aws:lambda:ca-west-1:946466191631:layer:LambdaInsightsExtension-Arm64:3`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:27`  | 
|  歐洲 (蘇黎世) |  `arn:aws:lambda:eu-central-2:033019950311:layer:LambdaInsightsExtension-Arm64:3`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:27`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:27`  | 
|  歐洲 (巴黎) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension-Arm64:25`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension-Arm64:25`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension-Arm64:26`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension-Arm64:14`  | 
|  以色列 (特拉維夫) |  `arn:aws:lambda:il-central-1:459530977127:layer:LambdaInsightsExtension-Arm64:3`  | 
|  墨西哥 (中部) |  `arn:aws:lambda:mx-central-1:879381266642:layer:LambdaInsightsExtension-Arm64:2`  | 
|  Middle East (Bahrain) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension-Arm64:26`  | 
|  中東 (阿拉伯聯合大公國) |  `arn:aws:lambda:me-central-1:732604637566:layer:LambdaInsightsExtension-Arm64:3`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:25`  | 
|  中國 (北京) |  `arn:aws-cn:lambda:cn-north-1:488211338238:layer:LambdaInsightsExtension-Arm64:1`  | 
|  中國 (寧夏) |  `arn:aws-cn:lambda:cn-northwest-1:488211338238:layer:LambdaInsightsExtension-Arm64:1`  | 
|  AWS GovCloud （美國東部） |  `arn:aws-us-gov:lambda:us-gov-east-1:122132214140:layer:LambdaInsightsExtension-Arm64:6`  | 
|  AWS GovCloud （美國西部） |  `arn:aws-us-gov:lambda:us-gov-west-1:751350123760:layer:LambdaInsightsExtension-Arm64:6`  | 

## 1.0.404.0
<a name="Lambda-Insights-extension-ARM-1.0.404.0"></a>

版本 1.0.404.0 將 Lambda Insights 延伸模組的二進位大小從 \$19MB 縮減至 \$15MB，然後將 Lambda Insights 延伸模組圖層的 zip 檔案大小從 \$13.7MB 縮減至 \$12.5MB。同時將代理程式的整體記憶體消耗量從 \$111MB 縮減至 \$17MB。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:23`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension-Arm64:25`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:21`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:23`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension-Arm64:21`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension-Arm64:21`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension-Arm64:9`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension-Arm64:21`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension-Arm64:25`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension-Arm64:20`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:22`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:23`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:23`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:34`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:21`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:23`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:23`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:23`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension-Arm64:21`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension-Arm64:21`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension-Arm64:9`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension-Arm64:21`  | 
|  中東 (巴林) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension-Arm64:21`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:21`  | 
|  AWS GovCloud （美國東部） |  `arn:aws-us-gov:lambda:us-gov-east-1:122132214140:layer:LambdaInsightsExtension-Arm64:6`  | 
|  AWS GovCloud （美國西部） |  `arn:aws-us-gov:lambda:us-gov-west-1:751350123760:layer:LambdaInsightsExtension-Arm64:6`  | 

## 1.0.391.0
<a name="Lambda-Insights-extension-ARM-1.0.391.0"></a>

**重要**  
版本 1.0.391.0 變更了 Lambda Insights 收集與回報執行緒使用情況的方式。在舊版延伸模組中，`threads_max` 指標回報程序 ID 為 1 的程序中，正在執行的執行緒數上限。從版本 1.0.391.0 開始，此指標回報函式執行期間，在執行環境中的所有程序內，於任意時間點同時執行的執行緒數上限。這包括 Lambda 函式的程序、延伸模組的程序、系統/執行時期特定程序等。這可讓 `threads_max` 指標在評估剩餘可用執行緒時更為全面。如需執行緒和程序配額的詳細資訊，請參閱 [Lambda 配額](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html)。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:22`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension-Arm64:24`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:20`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:22`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension-Arm64:20`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension-Arm64:20`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension-Arm64:8`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension-Arm64:20`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension-Arm64:24`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension-Arm64:19`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:21`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:22`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:22`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:33`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:20`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:22`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:22`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:22`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension-Arm64:20`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension-Arm64:20`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension-Arm64:8`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension-Arm64:20`  | 
|  中東 (巴林) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension-Arm64:20`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:20`  | 
|  AWS GovCloud （美國東部） |  `arn:aws-us-gov:lambda:us-gov-east-1:122132214140:layer:LambdaInsightsExtension-Arm64:5`  | 
|  AWS GovCloud （美國西部） |  `arn:aws-us-gov:lambda:us-gov-west-1:751350123760:layer:LambdaInsightsExtension-Arm64:5`  | 

## 1.0.333.0
<a name="Lambda-Insights-extension-ARM-1.0.333.0"></a>

版本 1.0.333.0 包含錯誤修正。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:20`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension-Arm64:22`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:20`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension-Arm64:18`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension-Arm64:18`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension-Arm64:6`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension-Arm64:18`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension-Arm64:22`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension-Arm64:17`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:19`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:20`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:20`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:31`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:20`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:20`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:20`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension-Arm64:18`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension-Arm64:6`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  中東 (巴林) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension-Arm64:18`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  AWS GovCloud （美國東部） |  `arn:aws-us-gov:lambda:us-gov-east-1:122132214140:layer:LambdaInsightsExtension-Arm64:3`  | 
|  AWS GovCloud （美國西部） |  `arn:aws-us-gov:lambda:us-gov-west-1:751350123760:layer:LambdaInsightsExtension-Arm64:3`  | 

## 1.0.317.0
<a name="Lambda-Insights-extension-ARM-1.0.317.0"></a>

版本 1.0.317.0 移除了對 Amazon Linux 1 平台的支援，並包含錯誤修正。它還包含對 AWS GovCloud (US) 區域的支援。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:19`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension-Arm64:21`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:17`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:19`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension-Arm64:17`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension-Arm64:17`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension-Arm64:5`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension-Arm64:17`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension-Arm64:21`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension-Arm64:16`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:19`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:19`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:30`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:17`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:19`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:19`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:19`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension-Arm64:17`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension-Arm64:17`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension-Arm64:5`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension-Arm64:17`  | 
|  中東 (巴林) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension-Arm64:17`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:17`  | 
|  AWS GovCloud （美國東部） |  `arn:aws-us-gov:lambda:us-gov-east-1:122132214140:layer:LambdaInsightsExtension-Arm64:1`  | 
|  AWS GovCloud （美國西部） |  `arn:aws-us-gov:lambda:us-gov-west-1:751350123760:layer:LambdaInsightsExtension-Arm64:1`  | 

## 1.0.295.0
<a name="Lambda-Insights-extension-ARM-1.0.295.0"></a>

版本 1.0.295.0 包含所有相容執行時期的相依項更新。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension-Arm64:20`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:16`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension-Arm64:16`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension-Arm64:16`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension-Arm64:4`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension-Arm64:16`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension-Arm64:20`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension-Arm64:15`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:17`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:29`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:16`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension-Arm64:16`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension-Arm64:16`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension-Arm64:4`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension-Arm64:16`  | 
|  中東 (巴林) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension-Arm64:16`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:16`  | 

## 1.0.275.0
<a name="Lambda-Insights-extension-ARM-1.0.275.0"></a>

版本 1.0.275.0 包含所有相容執行時期的錯誤修正，以及對歐洲 (西班牙) 和亞太區域 (海德拉巴) 區域的支援。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:16`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:14`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:16`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension-Arm64:14`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension-Arm64:14`  | 
|  亞太區域 (海德拉巴) |  `arn:aws:lambda:ap-south-2:891564319516:layer:LambdaInsightsExtension-Arm64:2`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension-Arm64:14`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension-Arm64:18`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension-Arm64:13`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:15`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:16`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:16`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:27`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:14`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:16`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:16`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:16`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension-Arm64:14`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension-Arm64:14`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-2:352183217350:layer:LambdaInsightsExtension-Arm64:2`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension-Arm64:14`  | 
|  中東 (巴林) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension-Arm64:14`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:14`  | 

## 1.0.273.0
<a name="Lambda-Insights-extension-ARM-1.0.273.0"></a>

版本 1.0.273.0 包含所有相容執行時期的錯誤修正。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:12`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension-Arm64:14`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:9`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:12`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension-Arm64:9`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension-Arm64:9`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension-Arm64:9`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension-Arm64:14`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension-Arm64:9`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:11`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:12`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:12`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:23`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:10`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:12`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:12`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:12`  | 
|  歐洲 (米蘭) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension-Arm64:9`  | 
|  歐洲 (巴黎) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension-Arm64:10`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension-Arm64:10`  | 
|  中東 (巴林) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension-Arm64:9`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:10`  | 

## 1.0.229.0
<a name="Lambda-Insights-extension-ARM-1.0.229.0"></a>

1.0.229.0 版包括所有相容執行期的錯誤修正。同時新增對下列區域的支援：
+ 美國西部 (加利佛尼亞北部)
+ 非洲 (開普敦)
+ 亞太地區 (香港)
+ 亞太地區 (雅加達)
+ 亞太地區 (大阪)
+ 亞太地區 (首爾)
+ 加拿大 (中部)
+ Europe (Milan)
+ 歐洲 (巴黎)
+ 歐洲 (斯德哥爾摩)
+ 中東 (巴林)
+ 南美洲 (聖保羅)


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:5`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension-Arm64:7`  | 
|  美國西部 (加利佛尼亞北部) |  `arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:3`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:5`  | 
|  非洲 (開普敦) |  `arn:aws:lambda:af-south-1:012438385374:layer:LambdaInsightsExtension-Arm64:2`  | 
|  亞太地區 (香港) |  `arn:aws:lambda:ap-east-1:519774774795:layer:LambdaInsightsExtension-Arm64:2`  | 
|  亞太地區 (雅加達) |  `arn:aws:lambda:ap-southeast-3:439286490199:layer:LambdaInsightsExtension-Arm64:2`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension-Arm64:7`  | 
|  亞太區域 (大阪) |  `arn:aws:lambda:ap-northeast-3:194566237122:layer:LambdaInsightsExtension-Arm64:2`  | 
|  亞太區域 (首爾) |  `arn:aws:lambda:ap-northeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:4`  | 
|  亞太區域 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:5`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:5`  | 
|  亞太區域 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:11`  | 
|  加拿大 (中部) |  `arn:aws:lambda:ca-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:3`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:5`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:5`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:5`  | 
|  歐洲 (西班牙) |  `arn:aws:lambda:eu-south-1:339249233099:layer:LambdaInsightsExtension-Arm64:2`  | 
|  Europe (Paris) |  `arn:aws:lambda:eu-west-3:580247275435:layer:LambdaInsightsExtension-Arm64:3`  | 
|  歐洲 (斯德哥爾摩) |  `arn:aws:lambda:eu-north-1:580247275435:layer:LambdaInsightsExtension-Arm64:3`  | 
|  中東 (巴林) |  `arn:aws:lambda:me-south-1:285320876703:layer:LambdaInsightsExtension-Arm64:2`  | 
|  南美洲 (聖保羅) |  `arn:aws:lambda:sa-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:3`  | 

## 1.0.135.0
<a name="Lambda-Insights-extension-ARM-1.0.135.0"></a>

1.0.135.0 版包含 Lambda Insights 如何收集和報告磁碟和檔案描述項使用情況的錯誤修復。在之前版本的延伸中，`tmp_free` 指標報告了運行函數時 `/tmp` 目錄的最大可用空間。此版本改為將指標變更為報告最小值，使其在評估磁碟使用情況時更有用。如需有關 `tmp` 目錄儲存配額的詳細資訊，請參 [Lambda 配額](https://docs.aws.amazon.com/lambda/latest/dg/gettingstarted-limits.html)。

1.0.135.0 版現在還報告檔案描述項使用情況 (`fd_use` 和 `fd_max`) 作為跨程序的最大值，而不是報告作業系統層級。


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:2`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension-Arm64:2`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:2`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension-Arm64:2`  | 
|  亞太地區 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:2`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:2`  | 
|  亞太地區 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:2`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:2`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:2`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:2`  | 

## 1.0.119.0
<a name="Lambda-Insights-extension-ARM-1.0.119.0"></a>


| 區域 | ARN | 
| --- | --- | 
|  美國東部 (維吉尼亞北部) |  `arn:aws:lambda:us-east-1:580247275435:layer:LambdaInsightsExtension-Arm64:1`  | 
|  美國東部 (俄亥俄) |  `arn:aws:lambda:us-east-2:580247275435:layer:LambdaInsightsExtension-Arm64:1`  | 
|  美國西部 (奧勒岡) |  `arn:aws:lambda:us-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:1`  | 
|  亞太地區 (孟買) |  `arn:aws:lambda:ap-south-1:580247275435:layer:LambdaInsightsExtension-Arm64:1`  | 
|  亞太地區 (新加坡) |  `arn:aws:lambda:ap-southeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:1`  | 
|  亞太地區 (雪梨) |  `arn:aws:lambda:ap-southeast-2:580247275435:layer:LambdaInsightsExtension-Arm64:1`  | 
|  亞太地區 (東京) |  `arn:aws:lambda:ap-northeast-1:580247275435:layer:LambdaInsightsExtension-Arm64:1`  | 
|  歐洲 (法蘭克福) |  `arn:aws:lambda:eu-central-1:580247275435:layer:LambdaInsightsExtension-Arm64:1`  | 
|  歐洲 (愛爾蘭) |  `arn:aws:lambda:eu-west-1:580247275435:layer:LambdaInsightsExtension-Arm64:1`  | 
|  歐洲 (倫敦) |  `arn:aws:lambda:eu-west-2:580247275435:layer:LambdaInsightsExtension-Arm64:1`  | 

# 使用主控台在現有的 Lambda 函數上啟用 Lambda Insights
<a name="Lambda-Insights-Getting-Started-console"></a>

 在 Lambda 主控台中遵循這些步驟，以在現有的 Lambda 函數上啟用 Lambda Insights。

**若要在 Lambda 函數上啟用 Lambda Insights**

1. 在 https：//[https://console.aws.amazon.com/lambda/](https://console.aws.amazon.com/lambda/) 開啟 AWS Lambda 主控台。

1.  選擇函數的名稱，然後選取接下來畫面上的 **Configuration** (組態) 索引標籤。

1.  在**組態**索引標籤下方，選擇左側導覽選單中的**監控工具**，然後選擇**編輯**。

    您將被導向到可以編輯監控工具的畫面。

1. 透過 **Lambda Insights 增強型監控**，選擇**編輯**。

1. 在 **CloudWatch Lambda Insights** 下，啟用**增強型監控**，然後選擇**儲存**。

# 使用 AWS CLI 在現有的 Lambda 函數上啟用 Lambda Insights
<a name="Lambda-Insights-Getting-Started-cli"></a>

請依照下列步驟，使用 AWS CLI 在現有的 Lambda 函數上啟用 Lambda Insights。

**步驟 1：更新函數許可**

**若要更新函數的許可**
+ 輸入下列命令，將 **CloudWatchLambdaInsightsExecutionRolePolicy** 受管 IAM 政策連接至函數的執行角色。

  ```
  aws iam attach-role-policy \
  --role-name function-execution-role \
  --policy-arn "arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy"
  ```

**步驟 2：安裝 Lambda 延伸模組**

輸入下列命令，安裝 Lambda 延伸。將 `layers` 參數的 ARN 值取代為與您的區域和您要使用的延伸相符的 ARN。如需詳細資訊，請參閱[Lambda Insights 延伸的可用版本](Lambda-Insights-extension-versions.md)。

```
aws lambda update-function-configuration \
   --function-name function-name \
   --layers "arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:14"
```

**步驟 3：啟用 CloudWatch Logs VPC 端點**

此步驟僅適用於在沒有網際網路存取的私有子網路中執行的函數，以及您尚未設定 CloudWatch Logs Virtual Private Cloud (VPC) 端點時才需要。

如果您需要執行此步驟，請輸入下列指令，以 VPC 的資訊取代預留位置。

如需詳細資訊，請參閱[搭配介面 VPC 端點使用 CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/cloudwatch-logs-and-interface-VPC.html)。

```
aws ec2 create-vpc-endpoint \
--vpc-id vpcId \
--vpc-endpoint-type Interface \
--service-name com.amazonaws.region.logs \
--subnet-id subnetId 
--security-group-id securitygroupId
```

# 使用 AWS SAM CLI 在現有的 Lambda 函數上啟用 Lambda Insights
<a name="Lambda-Insights-Getting-Started-SAM-CLI"></a>

請依照下列步驟，使用 AWS SAM AWS CLI 在現有的 Lambda 函數上啟用 Lambda Insights。

如果您尚未安裝最新版本的 AWS SAM CLI，您必須先安裝或升級它。如需詳細資訊，請參閱[安裝 AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html)。

**步驟 1：安裝層**

若要讓 Lambda Insights 延伸可供您所有的 Lambda 函數使用，請使用 Lambda Insights 層的 ARN 將 `Layers` 屬性新增至 SAM 範本的 `Globals` 區段。下面的範例使用 Lambda Insights 的初始版本層。如需 Lambda Insights 延伸層的最新版本，請參閱 [Lambda Insights 延伸的可用版本](Lambda-Insights-extension-versions.md)。

```
Globals:
  Function:
    Layers:
      - !Sub "arn:aws:lambda:${AWS::Region}:580247275435:layer:LambdaInsightsExtension:14"
```

若要僅針對單一函數啟用此層，請將 `Layers` 屬性新增至函數，如此範例所示。

```
Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Layers:
        - !Sub "arn:aws:lambda:${AWS::Region}:580247275435:layer:LambdaInsightsExtension:14"
```

**步驟 2：新增受管政策**

對於每個函數，新增 **CloudWatchLambdaInsightsExecutionRolePolicy** IAM 政策。

AWS SAM 不支援全域政策，因此您必須在每個函數上個別啟用這些政策，如本範例所示。如需全域的詳細資訊，請參閱[全域區段](https://github.com/aws/serverless-application-model/blob/master/docs/globals.rst)。

```
Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Policies:
        - CloudWatchLambdaInsightsExecutionRolePolicy
```

**本機叫用**

CLI AWS SAM 支援 Lambda 延伸模組。不過，每個本機執行的叫用都會重設執行階段環境。本地叫用將無法獲得 Lambda Insights 資料，因為執行時間會在沒有關機事件的情況下重新啟動。如需詳細資訊，請參閱 [ 1.6.0 版 - 新增 AWS Lambda 擴充功能的本機測試支援。](https://github.com/aws/aws-sam-cli/releases/tag/v1.6.0)

**疑難排解**

若要對您的 Lambda Insights 安裝進行疑難排解，請將下列環境變數新增至 Lambda 函數，以啟用偵錯日誌記錄。

```
Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Environment:
        Variables:
          LAMBDA_INSIGHTS_LOG_LEVEL: info
```

# 使用 CloudFormation 在現有的 Lambda 函數上啟用 Lambda Insights
<a name="Lambda-Insights-Getting-Started-cloudformation"></a>

請依照下列步驟使用 CloudFormation 在現有的 Lambda 函數上啟用 Lambda Insights。

**步驟 1：安裝層**

將 Lambda Insights 層新增至 Lambda Insights 層 ARN 內的 `Layers` 屬性。下面的範例使用 Lambda Insights 的初始版本層。如需 Lambda Insights 延伸層的最新版本，請參閱 [Lambda Insights 延伸的可用版本](Lambda-Insights-extension-versions.md)。

```
Resources:
  MyFunction:
    Type: AWS::Lambda::Function
    Properties:
      Layers:
        - !Sub "arn:aws:lambda:${AWS::Region}:580247275435:layer:LambdaInsightsExtension:14"
```

**步驟 2：新增受管政策**

將 **CloudWatchLambdaInsightsExecutionRolePolicy** IAM 政策新增至您的函數執行角色中。

```
Resources:
  MyFunctionExecutionRole:
    Type: 'AWS::IAM::Role'
    Properties:
      ManagedPolicyArns:
        - 'arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy'
```

**步驟 3：(選用) 新增 VPC 端點**

此步驟僅適用於在沒有網際網路存取的私有子網路中執行的函數，以及您尚未設定 CloudWatch Logs Virtual Private Cloud (VPC) 端點時才需要。如需詳細資訊，請參閱[搭配界面 VPC 端點使用 CloudWatch Logs](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/cloudwatch-logs-and-interface-VPC.html)。

```
Resources:
  CloudWatchLogsVpcPrivateEndpoint:
    Type: AWS::EC2::VPCEndpoint
    Properties:
      PrivateDnsEnabled: 'true'
      VpcEndpointType: Interface
      VpcId: !Ref: VPC
      ServiceName: !Sub com.amazonaws.${AWS::Region}.logs
      SecurityGroupIds:
        - !Ref InterfaceVpcEndpointSecurityGroup
      SubnetIds:
        - !Ref PublicSubnet01
        - !Ref PublicSubnet02
        - !Ref PublicSubnet03
```

# 使用 AWS CDK 在現有的 Lambda 函數上啟用 Lambda Insights
<a name="Lambda-Insights-Getting-Started-clouddevelopmentkit"></a>

請依照下列步驟，使用 AWS CDK 在現有的 Lambda 函數上啟用 Lambda Insights。若要使用這些步驟，您必須已經使用 AWS CDK 來管理您的 資源。

在本節中的命令是在 TypeScript。

首先，更新函數許可。

```
executionRole.addManagedPolicy(
 ManagedPolicy.fromAwsManagedPolicyName('CloudWatchLambdaInsightsExecutionRolePolicy')
);
```

接下來，在 Lambda 函數上安裝延伸。將 `layerArn` 參數的 ARN 值取代為與您的區域和您要使用的延伸相符的 ARN。如需詳細資訊，請參閱[Lambda Insights 延伸的可用版本](Lambda-Insights-extension-versions.md)。

```
import lambda = require('@aws-cdk/aws-lambda');
const layerArn = 'arn:aws:lambda:us-west-1:580247275435:layer:LambdaInsightsExtension:14';
const layer = lambda.LayerVersion.fromLayerVersionArn(this, 'LayerFromArn', layerArn);
```

如有必要，為 CloudWatch Logs 啟用 Virtual Private Cloud (VPC) 端點。此步驟僅適用於在沒有網際網路存取的私有子網路中執行的函數，以及您尚未設定 CloudWatch Logs VPC 端點時才需要。

```
const cloudWatchLogsEndpoint = vpc.addInterfaceEndpoint('cwl-gateway', {
  service: InterfaceVpcEndpointAwsService.CLOUDWATCH_LOGS,
});

cloudWatchLogsEndpoint.connections.allowDefaultPortFromAnyIpv4();
```

# 使用 Serverless Framework 在現有的 Lambda 函式上啟用 Lambda Insights
<a name="Lambda-Insights-Getting-Started-serverless"></a>

使用無伺服器架構在現有的 Lambda 函數上啟用 Lambda Insights 如需無伺服器架構的詳細資訊，請參閱 [serverless.com](https://www.serverless.com/)。

這是透過無伺服器的 Lambda Insights 外掛程式完成的。如需詳細資訊，請參閱 [serverless-plugin-lambda-insights](https://www.npmjs.com/package/serverless-plugin-lambda-insights)。

如果您尚未安裝最新版本的無伺服器命令列介面，您必須先進行安裝或升級。如需詳細資訊，請參閱[開始使用無伺服器架構開放原始碼 & AWS](https://www.serverless.com/framework/docs/getting-started/)。

**若要使用無伺服器架構在現有的 Lambda 函數上啟用 Lambda Insights 函數**

1. 在無伺服器目錄中執行下列命令，以安裝 Lambda Insights 的無伺服器外掛程式：

   ```
   npm install --save-dev serverless-plugin-lambda-insights
   ```

1. 在您的 `serverless.yml` 檔案中，將外掛程式新增至 `plugins` 區段，如下所示：

   ```
   provider:
     name: aws
   plugins:
     - serverless-plugin-lambda-insights
   ```

1. 啟用 Lambda Insights。
   + 您可以將下列屬性新增至無伺服器 .yml 檔案，個別啟用每個函數的 Lambda Insights

     ```
     functions:
       myLambdaFunction:
         handler: src/app/index.handler
         lambdaInsights: true #enables Lambda Insights for this function
     ```
   + 您可以新增以下自訂區段，從而為 `serverless.yml` 檔案內的所有函數啟用 Lambda Insights：

     ```
     custom:
       lambdaInsights:
         defaultLambdaInsights: true #enables Lambda Insights for all functions
     ```

1. 輸入下列命令，重新部署無伺服器服務：

   ```
   serverless deploy
   ```

   這會重新部署所有函數，並針對您指定的那些函數啟用 Lambda Insights。其會新增 Lambda Insights 層並使用 `arn:aws:iam::aws:policy/CloudWatchLambdaInsightsExecutionRolePolicy` IAM 政策連接必要的許可，進而啟用 Lambda Insights。

# 在 Lambda 容器映像部署上啟用 Lambda Insights
<a name="Lambda-Insights-Getting-Started-docker"></a>

若要在部署為容器映像的 Lambda 函數上啟用 Lambda Insights，請在您的 Dockerfile 中新增行。這些行會將 Lambda Insights 代理程式安裝為容器映像中的延伸。x86-64 容器和 ARM64 容器要新增的行不同。

**注意**  
僅在使用 Amazon Linux 2 和 Amazon Linux 2023 的 Lambda 執行時期上支援 Lambda Insights 代理程式。

**Topics**
+ [x86-64 容器映像部署](#Lambda-Insights-Getting-Started-docker-x86-64)
+ [ARM64 容器映像部署](#Lambda-Insights-Getting-Started-docker-ARM64)

## x86-64 容器映像部署
<a name="Lambda-Insights-Getting-Started-docker-x86-64"></a>

若要在部署為在 x86-64 容器上執行之容器映像的 Lambda 函數上，啟用 Lambda Insights，請在您的 Dockerfile 中新增下列行。這些行會將 Lambda Insights 代理程式安裝為容器映像中的延伸。

```
RUN curl -O https://lambda-insights-extension.s3-ap-northeast-1.amazonaws.com/amazon_linux/lambda-insights-extension.rpm && \
    rpm -U lambda-insights-extension.rpm && \
    rm -f lambda-insights-extension.rpm
```

建立 Lambda 函數之後，請將 **CloudWatchLambdaInsightsExecutionRolePolicy** IAM 政策設定為函數的執行角色，並且在容器映像型 Lambda 函數上啟用 Lambda Insights。

**注意**  
若要使用較舊版本的 Lambda Insights 延伸，請將先前命令中的 URL 取代為此 URL：`https://lambda-insights-extension.s3-ap-northeast-1.amazonaws.com/amazon_linux/lambda-insights-extension.1.0.111.0.rpm`。如需詳細資訊，請參閱[Lambda Insights 延伸的可用版本](Lambda-Insights-extension-versions.md)。

**若要在 Linux 伺服器上驗證 Lambda Insights 代理程式套件的簽章**

1. 輸入下列命令，以下載公有金鑰。

   ```
   shell$ wget https://lambda-insights-extension.s3-ap-northeast-1.amazonaws.com/lambda-insights-extension.gpg
   ```

1. 輸入下列命令，將公有金鑰匯入至您的 keyring。

   ```
   shell$ gpg --import lambda-insights-extension.gpg
   ```

   輸出會類似下列內容：請記下 `key` 值，在後續步驟您將會用到它。在此範例輸出中，索引鍵值為 `848ABDC8`。

   ```
   gpg: key 848ABDC8: public key "Amazon Lambda Insights Extension" imported
   gpg: Total number processed: 1
   gpg: imported: 1  (RSA: 1)
   ```

1. 執行下列命令，驗證指紋。將 `key-value` 取代為上述步驟中的索引鍵值。

   ```
   shell$  gpg --fingerprint key-value
   ```

   在此命令的輸出中，指紋字串應為 `E0AF FA11 FFF3 5BD7 349E E222 479C 97A1 848A BDC8`。若字串不相符，請勿安裝代理程式並聯絡 AWS。

1. 在您驗證指紋之後，即可使用它來驗證 Lambda Insights 代理程式套件。輸入以下命令，下載套件簽章檔案。

   ```
   shell$  wget https://lambda-insights-extension.s3-ap-northeast-1.amazonaws.com/amazon_linux/lambda-insights-extension.rpm.sig
   ```

1. 執行下列命令，驗證簽章：

   ```
   shell$ gpg --verify lambda-insights-extension.rpm.sig lambda-insights-extension.rpm
   ```

   輸出應與以下類似：

   ```
   gpg: Signature made Thu 08 Apr 2021 06:41:00 PM UTC using RSA key ID 848ABDC8
   gpg: Good signature from "Amazon Lambda Insights Extension"
   gpg: WARNING: This key is not certified with a trusted signature!
   gpg:          There is no indication that the signature belongs to the owner.
   Primary key fingerprint: E0AF FA11 FFF3 5BD7 349E  E222 479C 97A1 848A BDC8
   ```

   在預期的輸出中，可能會有關信任簽章的警告。只有您或您信任者所簽章的金鑰才能信任。這不表示該簽章是無效的，只是您尚未驗證該公有金鑰。

   如果輸出包含 `BAD signature`，檢查您是否已正確執行步驟。如果您繼續取得`BAD signature`回應，請聯絡 AWS 並避免使用下載的檔案。

### x86-64 範例
<a name="Lambda-Insights-Getting-Started-docker-example"></a>

本節包含在容器映像型 Python Lambda 函數上啟用 Lambda Insights 的範例。

**在 Lambda 容器映像上啟用 Lambda Insights 的範例**

1. 建立類似如下的 DDockerfile：

   ```
   FROM public.ecr.aws/lambda/python:3.8
   
   // extra lines to install the agent here
   RUN curl -O https://lambda-insights-extension.s3-ap-northeast-1.amazonaws.com/amazon_linux/lambda-insights-extension.rpm && \
       rpm -U lambda-insights-extension.rpm && \
       rm -f lambda-insights-extension.rpm
     
   COPY index.py ${LAMBDA_TASK_ROOT}
   CMD [ "index.handler" ]
   ```

1. 建立一個類似如下的名為 `index.py` 的 Python 檔案：

   ```
   def handler(event, context):
     return {
       'message': 'Hello World!'
     }
   ```

1. 將 Dockerfile 和 `index.py` 放在同一個目錄中。然後，在該目錄中，執行以下步驟，從而建置 Docker 影像並將其上傳到 Amazon ECR。

   ```
   // create an ECR repository
   aws ecr create-repository --repository-name test-repository
   // build the docker image
   docker build -t test-image .
   // sign in to AWS
   aws ecr get-login-password | docker login --username AWS --password-stdin "${ACCOUNT_ID}".dkr.ecr."${REGION}".amazonaws.com
   // tag the image
   docker tag test-image:latest "${ACCOUNT_ID}".dkr.ecr."${REGION}".amazonaws.com/test-repository:latest
   // push the image to ECR
   docker push "${ACCOUNT_ID}".dkr.ecr."${REGION}".amazonaws.com/test-repository:latest
   ```

1. 使用您剛才建立的 Amazon ECR 映像來建立 Lambda 函數。

1.  將 **CloudWatchLambdaInsightsExecutionRolePolicy** IAM 政策指派給您的函數執行角色。

## ARM64 容器映像部署
<a name="Lambda-Insights-Getting-Started-docker-ARM64"></a>

若要在部署為在 AL2\$1aarch64 容器 (使用 ARM64 架構) 上執行之容器映像的 Lambda 函數上，啟用 Lambda Insights，請在您的 Dockerfile 中新增下列行。這些行會將 Lambda Insights 代理程式安裝為容器映像中的延伸。

```
RUN curl -O https://lambda-insights-extension-arm64.s3-ap-northeast-1.amazonaws.com/amazon_linux/lambda-insights-extension-arm64.rpm && \
    rpm -U lambda-insights-extension-arm64.rpm && \
    rm -f lambda-insights-extension-arm64.rpm
```

建立 Lambda 函數之後，請將 **CloudWatchLambdaInsightsExecutionRolePolicy** IAM 政策設定為函數的執行角色，並且在容器映像型 Lambda 函數上啟用 Lambda Insights。

**注意**  
若要使用較舊版本的 Lambda Insights 延伸，請將先前命令中的 URL 取代為此 URL：`https://lambda-insights-extension-arm64.s3-ap-northeast-1.amazonaws.com/amazon_linux/lambda-insights-extension-arm64.1.0.229.0.rpm`。如需詳細資訊，請參閱[Lambda Insights 延伸的可用版本](Lambda-Insights-extension-versions.md)。

**若要在 Linux 伺服器上驗證 Lambda Insights 代理程式套件的簽章**

1. 輸入下列命令，以下載公有金鑰。

   ```
   shell$ wget https://lambda-insights-extension-arm64.s3-ap-northeast-1.amazonaws.com/lambda-insights-extension.gpg
   ```

1. 輸入下列命令，將公有金鑰匯入至您的 keyring。

   ```
   shell$ gpg --import lambda-insights-extension.gpg
   ```

   輸出會類似下列內容：請記下 `key` 值，在後續步驟您將會用到它。在此範例輸出中，索引鍵值為 `848ABDC8`。

   ```
   gpg: key 848ABDC8: public key "Amazon Lambda Insights Extension" imported
   gpg: Total number processed: 1
   gpg: imported: 1  (RSA: 1)
   ```

1. 執行下列命令，驗證指紋。將 `key-value` 取代為上述步驟中的索引鍵值。

   ```
   shell$  gpg --fingerprint key-value
   ```

   在此命令的輸出中，指紋字串應為 `E0AF FA11 FFF3 5BD7 349E E222 479C 97A1 848A BDC8`。若字串不相符，請勿安裝代理程式並聯絡 AWS。

1. 在您驗證指紋之後，即可使用它來驗證 Lambda Insights 代理程式套件。輸入以下命令，下載套件簽章檔案。

   ```
   shell$  wget https://lambda-insights-extension-arm64.s3-ap-northeast-1.amazonaws.com/amazon_linux/lambda-insights-extension-arm64.rpm.sig
   ```

1. 執行下列命令，驗證簽章：

   ```
   shell$ gpg --verify lambda-insights-extension-arm64.rpm.sig lambda-insights-extension-arm64.rpm
   ```

   輸出應與以下類似：

   ```
   gpg: Signature made Thu 08 Apr 2021 06:41:00 PM UTC using RSA key ID 848ABDC8
   gpg: Good signature from "Amazon Lambda Insights Extension"
   gpg: WARNING: This key is not certified with a trusted signature!
   gpg:          There is no indication that the signature belongs to the owner.
   Primary key fingerprint: E0AF FA11 FFF3 5BD7 349E  E222 479C 97A1 848A BDC8
   ```

   在預期的輸出中，可能會有關信任簽章的警告。只有您或您信任者所簽章的金鑰才能信任。這不表示該簽章是無效的，只是您尚未驗證該公有金鑰。

   如果輸出包含 `BAD signature`，檢查您是否已正確執行步驟。如果您繼續取得`BAD signature`回應，請聯絡 AWS 並避免使用下載的檔案。

### ARM64 範例
<a name="Lambda-Insights-Getting-Started-docker-example-ARM64"></a>

本節包含在容器映像型 Python Lambda 函數上啟用 Lambda Insights 的範例。

**在 Lambda 容器映像上啟用 Lambda Insights 的範例**

1. 建立類似如下的 DDockerfile：

   ```
   FROM public.ecr.aws/lambda/python:3.8
   // extra lines to install the agent here
   RUN curl -O https://lambda-insights-extension-arm64.s3-ap-northeast-1.amazonaws.com/amazon_linux/lambda-insights-extension-arm64.rpm && \
       rpm -U lambda-insights-extension-arm64.rpm && \
       rm -f lambda-insights-extension-arm64.rpm
     
   COPY index.py ${LAMBDA_TASK_ROOT}
   CMD [ "index.handler" ]
   ```

1. 建立一個類似如下的名為 `index.py` 的 Python 檔案：

   ```
   def handler(event, context):
     return {
       'message': 'Hello World!'
     }
   ```

1. 將 Dockerfile 和 `index.py` 放在同一個目錄中。然後，在該目錄中，執行以下步驟，從而建置 Docker 影像並將其上傳到 Amazon ECR。

   ```
   // create an ECR repository
   aws ecr create-repository --repository-name test-repository
   // build the docker image
   docker build -t test-image .
   // sign in to AWS
   aws ecr get-login-password | docker login --username AWS --password-stdin "${ACCOUNT_ID}".dkr.ecr."${REGION}".amazonaws.com
   // tag the image
   docker tag test-image:latest "${ACCOUNT_ID}".dkr.ecr."${REGION}".amazonaws.com/test-repository:latest
   // push the image to ECR
   docker push "${ACCOUNT_ID}".dkr.ecr."${REGION}".amazonaws.com/test-repository:latest
   ```

1. 使用您剛才建立的 Amazon ECR 映像來建立 Lambda 函數。

1.  將 **CloudWatchLambdaInsightsExecutionRolePolicy** IAM 政策指派給您的函數執行角色。

# 更新函式上的 Lambda Insights 延伸模組版本
<a name="Lambda-Insights-Update-Extension"></a>

最佳實務是，建議您始終將 Lambda Insights 延伸模組更新至最新版本。此頁面中的主題說明如何執行此操作。

**注意**  
此頁面說明如何更新已使用 Lambda Insights 的函式所使用的延伸模組版本。如需如何開始使用 Lambda Insights 的詳細資訊，請參閱[開始使用 Lambda Insights](Lambda-Insights-Getting-Started.md)。

## 使用 Lambda 主控台更新 Lambda Insights 延伸模組版本
<a name="Lambda-Insights-Update-Extension-console"></a>

依循下列步驟，使用 Lambda 主控台更新 Lambda Insights 延伸模組版本。

**使用 Lambda 主控台更新**

1. 在 https：//[https://console.aws.amazon.com/lambda/](https://console.aws.amazon.com/lambda/) 開啟 AWS Lambda 主控台。

1. 選擇 函數的名稱。

1. 在**圖層**區段中，選擇**編輯**。

1. 在圖層清單中，搜尋 **LambdaInsightsExtension**，然後將圖層版本變更為 [Lambda Insights 延伸的可用版本](Lambda-Insights-extension-versions.md) 中所列的最新版本。

1. 選擇**儲存**。

## 使用 AWS CLI 更新 Lambda Insights 延伸模組版本
<a name="Lambda-Insights-Update-Extension-CLI"></a>

若要使用 AWS CLI 更新 Lambda Insights 延伸版本，請輸入下列命令。將圖層參數的 ARN 值替換為與您的區域和您要使用的延伸模組版本相符的 ARN。如需 Lambda Insights 延伸模組圖層的最新發行版本相關資訊，請參閱 [Lambda Insights 延伸的可用版本](Lambda-Insights-extension-versions.md)。

```
aws lambda update-function-configuration \
--function-name function-name \
--layers "arn:aws:lambda:us-west-1:111122223333:layer:LambdaInsightsExtension:53"
```

## 使用 AWS SAM CLI 更新一或多個函數上的 Lambda Insights 延伸
<a name="Lambda-Insights-Update-Extension-SAM-CLI"></a>

若要更新所有 Lambda 函數的 Lambda Insights 延伸版本，請使用 Lambda Insights 層的 ARN 更新無 AWS 伺服器應用程式模型 (SAM) 範本 `Globals`區段中的 `Layers` 屬性。如需 Lambda Insights 延伸模組圖層的最新發行版本相關資訊，請參閱 [Lambda Insights 延伸的可用版本](Lambda-Insights-extension-versions.md)。

下列程式碼用於更新所有 Lambda 函式。

```
Globals:
  Function:
    Layers:
       - !Sub "arn:aws:lambda:${AWS::Region}:111122223333:layer:LambdaInsightsExtension:53"
```

下列程式碼只會更新一個函式。

```
Resources:
  MyFunction:
    Type: AWS::Serverless::Function
    Properties:
      Layers:
        - !Sub "arn:aws:lambda:${AWS::Region}:111122223333:layer:LambdaInsightsExtension:53"
```

## CloudFormation 使用 在一或多個函數上更新 Lambda Insights 延伸模組
<a name="Lambda-Insights-Update-Extension-CloudFormation"></a>

若要使用 更新 Lambda Insights 延伸模組版本 CloudFormation，請在函數 CloudFormation 資源的 `Layers` 屬性中更新延伸模組層，如下列範例所示。如需 Lambda Insights 延伸模組圖層的最新發行版本相關資訊，請參閱 [Lambda Insights 延伸的可用版本](Lambda-Insights-extension-versions.md)。

```
Resources:
  MyFunction:
    Type: AWS::Lambda::Function
    Properties:
      Layers:
        - !Sub "arn:aws:lambda:${AWS::Region}:111122223333:layer:LambdaInsightsExtension:53"
```

## 使用 AWS CDK 在一或多個函數上更新 Lambda Insights 延伸
<a name="Lambda-Insights-Update-Extension-CDK"></a>

您可以將 `layerArn` 參數的 ARN 值替換為與您的區域和要使用的延伸模組相符的 ARN，以更新 Lambda 函式的延伸模組版本。如需 Lambda Insights 延伸模組圖層的最新發行版本相關資訊，請參閱 [Lambda Insights 延伸的可用版本](Lambda-Insights-extension-versions.md)。

```
import lambda = require('@aws-cdk/aws-lambda'); 
const layerArn = 'arn:aws:lambda:us-west-1:111122223333:layer:LambdaInsightsExtension:53'; 
const layer = lambda.LayerVersion.fromLayerVersionArn(this, 'LayerFromArn', layerArn);
```

## 使用 Serverless Framework 更新一個或多個函式的 Lambda Insights 延伸模組
<a name="Lambda-Insights-Update-Extension-Serverless"></a>

請依循以下步驟，使用 Serverless Framework 在現有的 Lambda 函式上更新 Lambda Insights 延伸模組版本。如需 Serverless Framework 的詳細資訊，請參閱 [Serverless Framework 文件](https://serverless.com)。

此方法使用適用於 Serverless 的 Lambda Insights 外掛程式。如需詳細資訊，請參閱 [serverless-plugin-lambda-insights](https://www.npmjs.com/package/serverless-plugin-lambda-insights)。

如果您尚未安裝最新版本的 Serverless 命令列介面，必須先安裝或升級。如需詳細資訊，請參閱[使用 AWS 設定 Serverless Framework](https://www.serverless.com/framework/docs/getting-started/)。

**使用 Lambda 主控台更新**

1. 更新 Lambda Insights。如果您尚未這麼做，請在檔案結尾新增 `custom` 區段，並在 `lambdaInsightsVersion` 屬性內指定 Lambda Insights 版本。

   ```
   custom:
       lambdaInsights:
           lambdaInsightsVersion: 53 #specify the Layer Version
   ```

1. 輸入下列命令，重新部署 Serverless 服務。

   ```
   serverless deploy
   ```

## 在 Lambda 容器映像部署上更新 Lambda Insights 延伸模組版本
<a name="Lambda-Insights-Update-Extension-container"></a>

若要在 Lambda 容器映像上更新 Lambda Insights，請依循[在 Lambda 容器映像部署上啟用 Lambda Insights](Lambda-Insights-Getting-Started-docker.md)中的步驟，使用最新版本的 Lambda Insights 重建映像。然後，使用 AWS CLI [更新函數程式碼](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/update-function-code.html)，並提供容器映像 URI 做為 `--image-uri` 參數的值。

# 檢視您的 Lambda Insights 指標
<a name="Lambda-Insights-view-metrics"></a>

在已叫用的 Lambda 函數上安裝 Lambda Insights 延伸之後，您可以使用 CloudWatch 主控台來查看您的指標。您可以查看多函數概觀，或專注於單一函數。您也可以檢視在受管執行個體上執行的 Lambda 函數指標。

如需 Lambda Insights 指標的清單，請參閱 [Lambda Insights 收集的指標](Lambda-Insights-metrics.md)。

**若要檢視 Lambda Insights 指標的多函數概觀**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在左側導覽窗格中，選擇 **Insights**，然後選擇 **Lambda Insights**。

1. 在頁面頂端的 **Lambda Insights 檢視**下拉式清單中，選取**函數**。

1. 選擇**多函式**。

   頁面頂端會顯示具有啟用 Lambda Insights 之區域中所有 Lambda 函數的彙總指標的圖形。頁面下方是列出了函數的表格。

1. 若要依函數名稱進行篩選，以減少顯示的函數數目，請在頁面頂端附近的方塊中輸入部分函數名稱。

1. 若要將此檢視作為小工具新增至儀表板，請選擇 **Add to dashboard** (新增至儀表板)。

**若要檢視函數的指標**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在左側導覽窗格中，選擇 **Insights**，然後選擇 **Lambda Insights**。

1. 在頁面頂端的 **Lambda Insights 檢視**下拉式清單中，選取**函數**。

1. 選擇**單一函式**。

   頁面頂端會顯示含有所選函數之指標的圖形。

1. 如果您已啟用 X-Ray，您可以選擇單一追蹤 ID。這會為該調用開啟「X-Ray 追蹤地圖」頁面，您可以將其縮小，以查看分散式追蹤以及處理該特定交易所涉及的其他服務。如需有關「X-Ray 追蹤地圖」的詳細資訊，請參閱[使用 X-Ray 追蹤地圖](https://docs.aws.amazon.com/xray/latest/devguide/xray-console-servicemap.html)。

1. 若要開啟 CloudWatch Logs Insights 並放大特定錯誤，請選擇 **View logs** (檢視日誌) 頁面底部的表格。

1. 若要將此檢視作為小工具新增至儀表板，請選擇 **Add to dashboard** (新增至儀表板)。

**檢視在受管執行個體上執行的 Lambda 函數指標**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在左側導覽窗格中，選擇 **Insights**，然後選擇 **Lambda Insights**。

1. 在頁面頂端的 **Lambda Insights 檢視**下拉式清單中，選取**受管執行個體函數**。

   此頁面會顯示受管執行個體檢視，其中包含在受管執行個體上執行之 Lambda 函數的指標。

1. 在**檢視**區段中，選取要檢視指標的精細程度層級：
   + **容量提供者** – 在容量提供者層級顯示彙總指標。
   + **執行個體類型** – 顯示執行個體類型層級的彙總指標。
   + **函數** – 在個別函數層級顯示指標。頁面頂端會顯示圖形，其中包含已啟用 Lambda Insights 的區域中所有 Lambda 函數的彙總指標。頁面下方是列出了函數的表格。若要依函數名稱篩選，請在頁面頂端附近的方塊中輸入函數名稱的一部分。

1. 使用**篩選條件**區段，依容量提供者、執行個體類型或函數進行篩選。

1. 若要將此檢視作為小工具新增至儀表板，請選擇 **Add to dashboard** (新增至儀表板)。

# 與 Application Insights 整合
<a name="lambda-insights-appinsights"></a>

Amazon CloudWatch Application Insights 協助您監控應用程式，並會識別和設定金鑰指標、日誌，並在您所有的應用程式資源和技術堆疊中發出警示。如需詳細資訊，請參閱[偵測常見的 CloudWatch Application Insights 應用程式問題](cloudwatch-application-insights.md)。

您可以啟用 Aplication Insights，從 Lambda 函數收集額外資料。如果尚未這樣做，選擇 Lambda Insights 儀表板中效能檢視下 **Application Insights** 索引標籤中的 **Auto-configure Application Insights** (自動設定 Application Insights) 即可啟用此功能。

如果您已設定 CloudWatch Application Insights 來監控 Lambda 函數，Application Insights 儀表板會出現在 **Application Insights** 索引標籤的 Lambda Insights 儀表板下方。

# Lambda Insights 收集的指標
<a name="Lambda-Insights-metrics"></a>

Lambda Insights 會從安裝它的 Lambda 函數收集數個指標。其中一些指標可在 CloudWatch 指標中作為時間序列彙總資料使用。其他指標不會彙總至時間序列資料，但可以使用 CloudWatch Logs Insights 在內嵌指標格式日誌項目中找到。

**Topics**
+ [Lambda 函數：](Lambda-Insights-metrics-lambda-functions.md)
+ [受管執行個體 Lambda 函數](Lambda-Insights-metrics-managed-instances.md)

# Lambda 函數：
<a name="Lambda-Insights-metrics-lambda-functions"></a>

下列指標可作為標準 Lambda 函數`LambdaInsights`命名空間中 CloudWatch Metrics 中的時間序列彙總資料。


| 指標名稱 | 維度 | Description | 
| --- | --- | --- | 
|  `cpu_total_time` |  function\$1name function\$1name, version  |  `cpu_system_time` 和 `cpu_user_time` 的總和。 單位：毫秒  | 
|  `init_duration` |  function\$1name function\$1name, version  |  在 Lambda 執行環境生命週期的 `init` 階段花費的時間。 單位：毫秒  | 
|  `memory_utilization` |  function\$1name function\$1name, version  |  以配置給函數的記憶體百分比來測量的記憶體上限。 單位：百分比  | 
|  `used_memory_max` |  function\$1name function\$1name, version  |  函數執行環境的測量記憶體。 單位：MB  | 
|  `rx_bytes` |  function\$1name function\$1name, version  |  函數接收的位元組數目。 單位：位元組  | 
|  `tmp_free` |  function\$1name function\$1name, version  |  `/tmp` 目錄中的可用空間量 單位：位元組  | 
|  `tmp_used` |  function\$1name function\$1name, version  |  `/tmp` 目錄中的所用空間量 單位：位元組  | 
|  `tx_bytes` |  function\$1name function\$1name, version  |  函數傳送的位元組數目。 單位：位元組  | 
|  `total_memory` |  function\$1name function\$1name, version  |  配置到您 Lambda 函數的記憶體數量。這與你的函數的記憶體大小相同。 單位：MB  | 
|  `total_network` |  function\$1name function\$1name, version  |  `rx_bytes` 和 `tx_bytes` 的總和。即使是不執行輸入/輸出任務的函數，由於 Lambda 執行時間會進行網路呼叫，這個值通常也會大於零。 單位：位元組  | 
|  `used_memory_max` |  function\$1name function\$1name, version  |  函數沙盒的測量記憶體。 單位：MB  | 

可以使用 CloudWatch Logs Insights 在內嵌指標格式日誌項目中找到下列指標。如需有關 CloudWatch Logs Insights 的詳細資訊，請參閱[使用 CloudWatch Logs Insights 分析日誌資料](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html)。

如需內嵌指標格式的詳細資訊，請參閱[在日誌中內嵌指標](CloudWatch_Embedded_Metric_Format.md)。


| 指標名稱 | Description | 
| --- | --- | 
|  `agent_version` |  目前在 Lambda 函數上執行的 Lambda Insights 延伸代理程式版本。 單位：字串  | 
|  `cpu_user_time` |  CPU 執行使用者程式碼所花費的時間。 單位：毫秒  | 
|  `cpu_system_time` |  CPU 執行核心程式碼所花費的時間。 單位：毫秒  | 
|  `cpu_total_time` |  `cpu_system_time` 和 `cpu_user_time` 的總和。 單位：毫秒  | 
|  `fd_use` |  目前正在使用的檔案描述項。 單位：計數  | 
|  `fd_max` |  可用的檔案描述項上限。 單位：計數  | 
|  `version` |  收集其他指標的 Lambda 函數版本。 單位：計數  | 
|  `agent_memory_max` |  Lambda Insights 延伸代理程式耗用的最大記憶體。 單位：位元組  | 
|  `agent_memory_avg` |  Lambda Insights 延伸代理程式耗用的平均記憶體。 單位：位元組  | 
|  `memory_utilization` |  平均記憶體，測量方式為配置給執行環境的記憶體百分比。 單位：百分比  | 
|  `used_memory_max` |  函數執行環境的測量記憶體。 單位：MB  | 
|  `rx_bytes` |  函數接收的位元組數目。 單位：位元組  | 
|  `tx_bytes` |  函數傳送的位元組數目。 單位：位元組  | 
|  `threads_max` |  函數程序使用的執行緒數量。作為函數撰寫者，您不能控制執行時間建立的執行緒的初始數量。 單位：計數  | 
|  `tmp_used` |  `/tmp` 目錄中的所用空間量 單位：位元組  | 
|  `tmp_max` |  `/tmp` 目錄中的可用空間量 單位：位元組  | 
|  `total_memory` |  配置到您 Lambda 函數的記憶體數量。這與你的函數的記憶體大小相同。 單位：MB  | 
|  `total_network` |  `rx_bytes` 和 `tx_bytes` 的總和。即使是不執行輸入/輸出任務的函數，由於 Lambda 執行時間會進行網路呼叫，這個值通常也會大於零。 單位：位元組  | 

# 受管執行個體 Lambda 函數
<a name="Lambda-Insights-metrics-managed-instances"></a>

下列指標可在受管執行個體上執行的 Lambda 函數`LambdaInsights`命名空間中，做為 CloudWatch Metrics 中的時間序列彙總資料。


| 指標名稱 | 維度 | Description | 
| --- | --- | --- | 
|  `cpu_utilization` |  function\$1name function\$1name, version  |  以配置給執行環境的 vCPUs 百分比測量的平均 CPU。 單位：百分比  | 
|  `cpu_utilization_max` |  function\$1name function\$1name, version  |  以配置給執行環境的 vCPUs 百分比測量的最大 CPU。這是每隔 1 秒取樣一次。 單位：百分比  | 
|  `cpu_total_time` |  function\$1name function\$1name, version  |  `cpu_system_time` 和 `cpu_user_time` 的總和。 單位：毫秒  | 
|  `memory_utilization` |  function\$1name function\$1name, version  |  平均記憶體，測量方式為配置給執行環境的記憶體百分比。 單位：百分比  | 
|  `memory_utilization_max` |  function\$1name function\$1name, version  |  以配置給執行環境的記憶體百分比來測量的最大記憶體。這是每隔 50 毫秒取樣一次。 單位：百分比  | 
|  `used_memory_max` |  function\$1name function\$1name, version  |  函數執行環境的測量記憶體。 單位：MB  | 
|  `rx_bytes` |  function\$1name function\$1name, version  |  函數接收的位元組數目。 單位：位元組  | 
|  `tmp_free` |  function\$1name function\$1name, version  |  `/tmp` 目錄中的可用空間量 單位：位元組  | 
|  `tmp_used` |  function\$1name function\$1name, version  |  `/tmp` 目錄中的所用空間量 單位：位元組  | 
|  `tx_bytes` |  function\$1name function\$1name, version  |  函數傳送的位元組數目。 單位：位元組  | 
|  `total_memory` |  function\$1name function\$1name, version  |  配置到您 Lambda 函數的記憶體數量。這與函數的記憶體大小相同。 單位：MB  | 
|  `total_network` |  function\$1name function\$1name, version  |  `rx_bytes` 和 `tx_bytes` 的總和。即使是不執行輸入/輸出任務的函數，由於 Lambda 執行時間會進行網路呼叫，這個值通常也會大於零。 單位：位元組  | 
|  `used_memory_max` |  function\$1name function\$1name, version  |  函數沙盒的測量記憶體。 單位：MB  | 

可以使用 CloudWatch Logs Insights 在內嵌指標格式日誌項目中找到下列指標。如需有關 CloudWatch Logs Insights 的詳細資訊，請參閱[使用 CloudWatch Logs Insights 分析日誌資料](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html)。

如需內嵌指標格式的詳細資訊，請參閱[在日誌中內嵌指標](CloudWatch_Embedded_Metric_Format.md)。


| 指標名稱 | Description | 
| --- | --- | 
|  `lambda_mode` |  指出此日誌事件是否適用於在 Lambda 受管執行個體上執行的函數。如果此欄位出現在日誌事件中，則只能有一個值 - `managed-instance`。缺少此欄位表示函數是一般 Lambda 函數。 單位：字串  | 
|  `agent_version` |  目前在 Lambda 函數上執行的 Lambda Insights 延伸代理程式版本。 單位：字串  | 
|  `cpu_utilization` |  以配置給執行環境的 vCPUs 百分比測量的平均 CPU。 單位：百分比  | 
|  `cpu_utilization_max` |  以配置給執行環境的 vCPUs 百分比測量的最大 CPU。這是每隔 1 秒取樣一次。 單位：百分比  | 
|  `cpu_user_time` |  CPU 執行使用者程式碼所花費的時間。 單位：毫秒  | 
|  `cpu_system_time` |  CPU 執行核心程式碼所花費的時間。 單位：毫秒  | 
|  `cpu_total_time` |  `cpu_system_time` 和 `cpu_user_time` 的總和。 單位：毫秒  | 
|  `fd_use` |  目前正在使用的檔案描述項。 單位：計數  | 
|  `fd_max` |  可用的檔案描述項上限。 單位：計數  | 
|  `execution_environment_init` |  布林值，指出此函數的新執行環境是否已旋轉。 單位：布林值  | 
|  `version` |  收集其他指標的 Lambda 函數版本。 單位：計數  | 
|  `agent_memory_max` |  Lambda Insights 延伸代理程式耗用的最大記憶體。 單位：位元組  | 
|  `agent_memory_avg` |  Lambda Insights 延伸代理程式耗用的平均記憶體。 單位：位元組  | 
|  `memory_utilization` |  平均記憶體，測量方式為配置給執行環境的記憶體百分比。 單位：百分比  | 
|  `memory_utilization_max` |  以配置給執行環境的記憶體百分比來測量的最大記憶體。這是每隔 50 毫秒取樣一次。 單位：百分比  | 
|  `used_memory_max` |  函數執行環境的測量記憶體。 單位：MB  | 
|  `rx_bytes` |  函數接收的位元組數目。 單位：位元組  | 
|  `tx_bytes` |  函數傳送的位元組數目。 單位：位元組  | 
|  `threads_max` |  函數程序使用的執行緒數量。作為函數撰寫者，您不能控制執行時間建立的執行緒的初始數量。 單位：計數  | 
|  `tmp_free` |  `/tmp` 目錄中的可用空間量 單位：位元組  | 
|  `tmp_used` |  `/tmp` 目錄中的所用空間量 單位：位元組  | 
|  `tmp_max` |  `/tmp` 目錄中的可用空間量 單位：位元組  | 
|  `total_memory` |  配置到您 Lambda 函數的記憶體數量。這與函數的記憶體大小相同。 單位：MB  | 
|  `total_network` |  `rx_bytes` 和 `tx_bytes` 的總和。即使是不執行輸入/輸出任務的函數，由於 Lambda 執行時間會進行網路呼叫，這個值通常也會大於零。 單位：位元組  | 

# CloudWatch Lambda Insights 的疑難排解和已知問題
<a name="Lambda-Insights-Troubleshooting"></a>

故障診斷任何問題的第一個步驟是啟用 Lambda Insights 延伸上的偵錯記錄。為此，請在 Lambda 函數上設定下列環境變數：`LAMBDA_INSIGHTS_LOG_LEVEL=info`。如需詳細資訊，請參閱[使用 AWS Lambda 環境變數](https://docs.aws.amazon.com/lambda/latest/dg/configuration-envvars.html)。

該延伸將日誌發出至與您的函數相同的日誌群組 (`/aws/lambda/function-name)`)。檢閱這些日誌，查看錯誤是否可能與安裝問題有關。

## 我看不到來自 Lambda Insights 的任何指標
<a name="Lambda-Insights-Troubleshooting-nometrics"></a>

如果看不到您預期會看到的 Lambda Insights 指標，請檢查下列可能性：
+ **指標可能只是延遲**— 如果尚未叫用函數或資料尚未清除，您將不會在 CloudWatch 中看到指標。如需詳細資訊，請參閱本節後續的**已知問題**部分。
+ **確認 Lambda 函數具有正確的許可**— 確定已將 **CloudWatchLambdaInsightsExecutionRolePolicy** IAM 政策指派給函數的執行角色。
+ **檢查 Lambda 執行時間**— Lambda Insights 僅支援特定的 Lambda 執行時間。如需支援的執行時間的清單，請參閱 [Lambda Insights](Lambda-Insights.md)。

  例如，若要在 Java 8 上使用 Lambda Insights，您必須使用 `java8.al2` 執行時間，而不是 `java8` 執行時間。
+ **檢查網路存取**— Lambda 函數可能位於沒有網際網路存取的 VPC 私有子網路上，而且您沒有為 CloudWatch Logs 設定 VPC 端點。為了協助偵錯此問題，您可以將環境變數設為 `LAMBDA_INSIGHTS_LOG_LEVEL=info`。

## 已知問題
<a name="Lambda-Insights-Troubleshooting-knownissues"></a>

資料延遲最多可達 20 分鐘。當函數處理常式完成時，Lambda 會凍結沙盒，也會凍結 Lambda Insights 延伸。在函數執行時，我們使用基於 TPS 函數的自適應批次策略來輸出資料。不過，如果函數停止叫用一段時間，且緩衝區中仍有事件資料，則可能會延遲此資料，直到 Lambda 關閉閒置沙盒為止。當 Lambda 關閉沙盒時，我們會排清緩衝的資料。

# CloudWatch Lambda Insights 中的遙測事件範例
<a name="Lambda-Insights-example-event"></a>

每次叫用啟用了 Lambda Insights 的 Lambda 函數會將單一日誌事件寫入 `/aws/lambda-insights` 日誌群組。每個日誌事件都包含內嵌指標格式的指標。如需內嵌指標格式的詳細資訊，請參閱[在日誌中內嵌指標](CloudWatch_Embedded_Metric_Format.md)。

若要分析這些日誌事件，您可以使用下列方法：
+ CloudWatch 主控台的 Lambda Insights 區段，如 [檢視您的 Lambda Insights 指標](Lambda-Insights-view-metrics.md) 中所述。
+ 使用 CloudWatch Logs Insights 日誌事件查詢。如需詳細資訊，請參閱[搭配 CloudWatch Logs Insights 分析日誌資料](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AnalyzingLogData.html)。
+ 在 `LambdaInsights` 命名空間中收集的指標，您可以使用 CloudWatch 指標繪製圖形。

以下是具有內嵌指標格式的 Lambda Insights 日誌事件範例。

```
{
    "_aws": {
        "Timestamp": 1605034324256,
        "CloudWatchMetrics": [
            {
                "Namespace": "LambdaInsights",
                "Dimensions": [
                    [ "function_name" ],
                    [ "function_name", "version" ]
                ],
                "Metrics": [
                    { "Name": "memory_utilization", "Unit": "Percent" },
                    { "Name": "total_memory", "Unit": "Megabytes" },
                    { "Name": "used_memory_max", "Unit": "Megabytes" },
                    { "Name": "cpu_total_time", "Unit": "Milliseconds" },
                    { "Name": "tx_bytes", "Unit": "Bytes" },
                    { "Name": "rx_bytes", "Unit": "Bytes" },
                    { "Name": "total_network", "Unit": "Bytes" },
                    { "Name": "init_duration", "Unit": "Milliseconds" }
                ]
            }
        ],
        "LambdaInsights": {
            "ShareTelemetry": true
        }
    },
    "event_type": "performance",
    "function_name": "cpu-intensive",
    "version": "Blue",
    "request_id": "12345678-8bcc-42f7-b1de-123456789012",
    "trace_id": "1-5faae118-12345678901234567890",
    "duration": 45191,
    "billed_duration": 45200,
    "billed_mb_ms": 11571200,
    "cold_start": true,
    "init_duration": 130,
    "tmp_free": 538329088,
    "tmp_max": 551346176,
    "threads_max": 11,
    "used_memory_max": 63,
    "total_memory": 256,
    "memory_utilization": 24,
    "cpu_user_time": 6640,
    "cpu_system_time": 50,
    "cpu_total_time": 6690,
    "fd_use": 416,
    "fd_max": 32642,
    "tx_bytes": 4434,
    "rx_bytes": 6911,
    "timeout": true,
    "shutdown_reason": "Timeout",
    "total_network": 11345,
    "agent_version": "1.0.72.0",
    "agent_memory_avg": 10,
    "agent_memory_max": 10
}
```

以下是在 Lambda 受管執行個體上執行之 Lambda 函數的 Lambda Insights 日誌事件範例。

```
{
    "total_network": 16443,
    "tmp_free": 531492864,
    "total_memory": 2048,
    "fd_use": 85,
    "tmp_used": 11984896,
    "execution_environment_init": false,
    "version": "3",
    "event_type": "performance",
    "agent_memory_max": 6,
    "fd_max": 1024,
    "function_name": "cpu-intensive",
    "tx_bytes": 8404,
    "memory_utilization": 3,
    "used_memory_max": 73,
    "memory_utilization_max": 3,
    "cpu_system_time": 541,
    "threads_max": 49,
    "tmp_max": 543477760,
    "cpu_utilization_max": 2,
    "agent_memory_avg": 6,
    "cpu_total_time": 815,
    "rx_bytes": 8039,
    "lambda_mode": "managed-instance",
    "agent_version": "1.0.660.0",
    "_aws": {
        "CloudWatchMetrics": [
            {
                "Namespace": "LambdaInsights",
                "Dimensions": [
                    [
                        "function_name"
                    ],
                    [
                        "function_name",
                        "version"
                    ]
                ],
                "Metrics": [
                    {
                        "Name": "cpu_total_time",
                        "Unit": "Milliseconds"
                    },
                    {
                        "Name": "cpu_utilization",
                        "Unit": "Percent"
                    },
                    {
                        "Name": "cpu_utilization_max",
                        "Unit": "Percent"
                    },
                    {
                        "Name": "tx_bytes",
                        "Unit": "Bytes"
                    },
                    {
                        "Name": "rx_bytes",
                        "Unit": "Bytes"
                    },
                    {
                        "Name": "total_network",
                        "Unit": "Bytes"
                    },
                    {
                        "Name": "used_memory_max",
                        "Unit": "Megabytes"
                    },
                    {
                        "Name": "memory_utilization",
                        "Unit": "Percent"
                    },
                    {
                        "Name": "memory_utilization_max",
                        "Unit": "Percent"
                    },
                    {
                        "Name": "total_memory",
                        "Unit": "Megabytes"
                    },
                    {
                        "Name": "tmp_used",
                        "Unit": "Bytes"
                    },
                    {
                        "Name": "tmp_free",
                        "Unit": "Bytes"
                    }
                ]
            }
        ],
        "Timestamp": 1764164871353,
        "LambdaInsights": {
            "ShareTelemetry": true
        }
    },
    "cpu_utilization": 1,
    "cpu_user_time": 273
}
```

# CloudWatch Database Insights
<a name="Database-Insights"></a>

可使用 CloudWatch Database Insights 大規模監控和排解 Amazon Aurora MySQL、Amazon Aurora PostgreSQL、Amazon Aurora PostgreSQL Limitless、Amazon RDS for SQL Server、RDS for MySQL、RDS for PostgreSQL、RDS for Oracle 及 RDS for MariaDB 資料庫。

透過 Database Insights，可以使用預先建置的專業儀表板來監控資料庫機群。為協助您分析機群的效能， Database Insights 儀表板會顯示精選指標與視覺化內容，您可以自訂這些儀表板。透過在單個儀表板中呈現機群中所有資料庫的指標，Database Insights 可讓您同時監控所有資料庫。

例如，您可以使用 Database Insights 在數百個資料庫執行個體機群內尋找效能不佳的資料庫。然後，您可以選擇該執行個體，並使用 Database Insights 對問題進行疑難排解。

如需有關引擎 AWS 區域和執行個體類別支援的資訊，請參閱 [Database Insights 的 Aurora 資料庫引擎、區域和執行個體類別支援，](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_DatabaseInsights.Engines.html)以及 [Database Insights 的 Amazon RDS 資料庫引擎、區域和執行個體類別支援](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_DatabaseInsights.Engines.html)。

Database Insights 支援跨多個帳戶和區域監控工作負載。若要進一步了解 Database Insights 的跨帳戶跨區域監控方式，請參閱[設定 CloudWatch Database Insights 的跨帳戶跨區域監控 ](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Database-Insights-Cross-Account-Cross-Region.html)

若要開始使用 Database Insights，請參閱下列主題。

**主題**
+ [開始使用 CloudWatch Database Insights](Database-Insights-Get-Started.md)
+ [檢視 CloudWatch Database Insights 的機群運作狀態儀表板](Database-Insights-Fleet-Health-Dashboard.md)
+ [檢視 CloudWatch Database Insights 的資料庫執行個體儀表板](Database-Insights-Database-Instance-Dashboard.md)
+ [CloudWatch Database Insights 疑難排解](Database-Insights-Troubleshooting.md)

## Database Insights 的模式
<a name="Database-Insights-modes"></a>

Database Insights 具有進階模式和標準模式。標準模式是 Database Insights 的預設模式，您可以為資料庫開啟進階模式。

下表顯示 CloudWatch 針對 Database Insights 的進階模式與標準模式支援哪些功能。


| 功能 | 標準模式 | 進階模式 | 
| --- | --- | --- | 
| 依維度分析資料庫負載的主要貢獻因子 | 支援 | 支援 | 
| 查詢資料庫指標，繪製圖表並設定警示，最多保留 7 天 | 支援 | 支援 | 
| 定義精細存取控制政策，以限制對潛在敏感維度 (例如 SQL 文字) 的存取權限 | 支援 | 支援 | 
| 分析資料庫中的作業系統程序，並提供每個執行程序的詳細指標 此功能需要 [Amazon RDS 增強型監控](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PerfInsights_Counters.html)才可運作。 | 不支援 | 支援 | 
| 定義和儲存整個機群的監控檢視，大規模評估資料庫運作狀態 | 不支援 | 支援 | 
| 分析具有 15 個月資料保留期與引導式使用者體驗的 SQL 鎖定狀態 | 不支援 | 僅支援 Aurora PostgreSQL | 
| 分析具有 15 個月資料保留期與引導式使用者體驗的 SQL 執行計畫 | 不支援 | 僅支援 Aurora PostgreSQL、RDS for Oracle 和 RDS for SQL Server | 
| 視覺化每個查詢的統計資料 | 不支援 | 支援 | 
| 分析執行緩慢的 SQL 查詢需要將資料庫日誌匯出至 CloudWatch Logs，此功能才可運作。 | 不支援 | 支援 | 
| 使用 CloudWatch Application Signals 檢視呼叫服務 | 不支援 | 支援 | 
| 檢視所有資料庫遙測的合併儀表板，包括指標、日誌、事件和應用程式需要將資料庫日誌匯出至 CloudWatch Logs，才可在 Database Insights 主控台中檢視資料庫日誌。 | 不支援 | 支援 | 
| 自動將 Performance Insights 計數器指標匯入 CloudWatch | 不支援 | 支援 | 
| 在 CloudWatch 中檢視 Amazon RDS 事件 | 不支援 | 支援 | 
| 使用按需分析功能來分析所選時段的資料庫效能 | 不支援 | 支援 | 

**注意**  
Database Insights 功能在不同 AWS 區域中的可用性不同，因為並非所有區域都提供所有進階模式功能。

## 資料保留
<a name="Database-Insights-retention"></a>

Database Insights 的進階模式會保留 Performance Insights 收集的過去 15 個月的指標。

如果針對標準模式啟用 Performance Insights，Amazon RDS 會保留 Performance Insights 計數器指標 7 天。

如需有關 Performance Insights 計數器指標的資訊，請參閱 [Performance Insights 計算器指標](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PerfInsights_Counters.html)。

如需有關 Database Insights 收集之 CloudWatch 指標保留期的資訊，請參閱下列主題。
+ 《Amazon Aurora 使用者指南》中的[適用於 Amazon Aurora 的 Amazon CloudWatch 指標](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/Aurora.AuroraMonitoring.Metrics.html) **
+ 《Amazon RDS 使用者指南》中的[適用於 Amazon Relational Database Service 的 Amazon CloudWatch 指標](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/rds-metrics.html) **
+ 《Amazon Aurora 使用者指南》中的[適用於 Amazon RDS Performance Insights 的 Amazon CloudWatch 指標](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PerfInsights.Cloudwatch.html) **
+ 《Amazon Aurora 使用者指南》中的[適用於 Amazon RDS Performance Insights 的 Amazon CloudWatch 指標](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PerfInsights.Cloudwatch.html) **

## Database Insights 如何與 Performance Insights 整合
<a name="Database-Insights-pi"></a>

Performance Insights 屬於資料庫效能監控服務。

Database Insights 以 Performance Insights 的功能為基礎擴充與延伸。Database Insights 新增監控、分析與最佳化功能。

若要啟用 Database Insights 的進階模式，必須啟用 Performance Insights。

Database Insights 會自動將 Performance Insights 計數器指標匯入 CloudWatch。Database Insights 的進階模式會自動保留 Database Insights 收集之所有指標 15 個月，包括 Performance Insights 指標和 CloudWatch 指標。在執行個體中啟用進階模式時，這會自動發生，無需進一步設定。如需 Performance Insights 計數器指標的相關資訊，請參閱《Amazon Aurora 使用者指南》**中的 [Performance Insights 計算器指標](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PerfInsights_Counters.html)。

## 定價
<a name="Database-Insights-pricing"></a>

如需有關定價的資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

# 開始使用 CloudWatch Database Insights
<a name="Database-Insights-Get-Started"></a>

Amazon RDS 和 Aurora 資料庫預設啟用 Database Insights 的標準模式。若要開始使用 Database Insights 的進階模式，可以建立新的資料庫或修改資料庫。

如需為 Amazon RDS 資料庫啟用 Database Insights 的進階模式或標準模式的詳細資訊，請參閱下列主題。
+ 《Amazon RDS 使用者指南》中的 [Turning on the Advanced mode of Database Insights for Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_DatabaseInsights.TurningOnAdvanced.html) **
+ 《Amazon RDS 使用者指南》中的 [Turning on the Standard mode of Database Insights for Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_DatabaseInsights.TurningOnStandard.html) **
+ 《Amazon RDS 使用者指南》中的 [Turning CloudWatch Database Insights on or off when creating a DB instance or Multi-AZ DB cluster for Amazon RDS](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_DatabaseInsights.TurnOnCreateDatabase.html) **

如需為 Amazon Aurora 資料庫啟用 Database Insights 的進階模式或標準模式的相關資訊，請參閱下列主題。
+ 《Amazon Aurora 使用者指南》中的 [Turning on the Advanced mode of Database Insights for Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_DatabaseInsights.TurningOnAdvanced.html) **
+ 《Amazon Aurora 使用者指南》中的 [Turning on the Standard mode of Database Insights for Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_DatabaseInsights.TurningOnStandard.html) **

如需為 Aurora PostgreSQL Limitless Database 啟用 Database Insights 進階模式或標準模式的相關資訊，請參閱下列主題。
+ 《Amazon Aurora 使用者指南》中的[為 Aurora PostgreSQL Limitless Database 開啟 Database Insights 進階模式](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/limitless-monitoring.cwdbi.advanced.html) **
+ 《Amazon Aurora 使用者指南》中的[為 Aurora PostgreSQL Limitless Database 開啟 Database Insights 標準模式](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/limitless-monitoring.cwdbi.standard.html) **

## Database Insights 的必要許可
<a name="w2aac26c13c31c17"></a>

使用 Database Insights 需要特定 IAM 許可。Database Insights 需要 CloudWatch、CloudWatch Logs、Amazon RDS 和 Amazon RDS Performance Insights 的許可。若您擁有更廣泛的權限，可能無需為使用者或角色提供這些許可。

需要下列 CloudWatch 許可才能使用 Database Insights。
+ `cloudwatch:BatchGetServiceLevelIndicatorReport`
+ `cloudwatch:DescribeAlarms`
+ `cloudwatch:GetDashboard`
+ `cloudwatch:GetMetricData`
+ `cloudwatch:ListMetrics`
+ `cloudwatch:PutDashboard`

需要下列 CloudWatch Logs 許可才能使用 Database Insights。
+ `logs:DescribeLogGroups`
+ `logs:GetQueryResults`
+ `logs:StartQuery`
+ `logs:StopQuery`

需要下列 Amazon RDS 許可才能使用 Database Insights。
+ `rds:DescribeDBClusters`
+ `rds:DescribeDBInstances`
+ `rds:DescribeEvents`
+ `rds:DescribeDBShardGroups` (如果您要監控 Aurora PostgreSQL Limitless Database)

需要下列 Performance Insights 許可才能使用 Database Insights。
+ `pi:ListAvailableResourceMetrics`
+ `pi:ListAvailableResourceDimensions`
+ `pi:DescribeDimensionKeys`
+ `pi:GetDimensionKeyDetails`
+ `pi:GetResourceMetrics`
+ `pi:ListPerformanceAnalysisReports`
+ `pi:GetResourceMetadata`
+ `pi:GetPerformanceAnalysisReport`
+ `pi:CreatePerformanceAnalysisReport`
+ `pi:DeletePerformanceAnalysisReport`
+ `pi:ListTagsForResource`
+ `pi:TagResource`
+ `pi:UntagResource`

下列政策範例中包含完整存取 Database Insights 所需的許可。

### 完整存取的政策範例
<a name="Database-Insights-permissions-sample"></a>

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [{
    "Effect" : "Allow",
      "Action" : [
        "cloudwatch:BatchGetServiceLevelIndicatorReport",
        "cloudwatch:DescribeAlarms",
        "cloudwatch:GetMetricStatistics",
        "cloudwatch:GetMetricData",
        "cloudwatch:ListMetrics",
        "cloudwatch:PutDashboard"
      ],
      "Resource" : "*"
    },
    {
    "Effect" : "Allow",
      "Action" : [
        "logs:DescribeLogGroups",
        "logs:GetQueryResults",
        "logs:StartQuery",
        "logs:StopQuery"
      ],
      "Resource" : "*"
    },
    {
    "Effect" : "Allow",
      "Action" : [
        "pi:DescribeDimensionKeys",
        "pi:GetDimensionKeyDetails",
        "pi:GetResourceMetadata",
        "pi:GetResourceMetrics",
        "pi:ListAvailableResourceDimensions",
        "pi:ListAvailableResourceMetrics",
        "pi:CreatePerformanceAnalysisReport",
        "pi:GetPerformanceAnalysisReport",
        "pi:ListPerformanceAnalysisReports",
        "pi:DeletePerformanceAnalysisReport",
        "pi:TagResource",
        "pi:UntagResource",
        "pi:ListTagsForResource"
      ],
      "Resource" : "arn:aws:pi:*:*:*/rds/*"
    },
    {
    "Effect" : "Allow",
      "Action" : [
        "rds:DescribeDBInstances",
        "rds:DescribeDBClusters",
        "rds:DescribeEvents"
      ],
      "Resource" : "*"
    }
  ]
}
```

------

# 設定 CloudWatch Database Insights 的跨帳戶跨區域監控
<a name="Database-Insights-Cross-Account-Cross-Region"></a>

 CloudWatch Database Insights 支援跨帳戶和跨區域資料庫機群監控，可在整個資料庫 AWS 基礎設施中集中觀察。它可讓您從單一統一主控台體驗，監控、疑難排解和最佳化橫跨多個 AWS 帳戶和區域的資料庫。

**Topics**
+ [先決條件](#Database-Insights-Cross-Account-Cross-Region-Prereq)
+ [設定您的監控和來源帳戶以進行 Database Insights 跨帳戶存取](#Database-Insights-Cross-Account-Cross-Region-MonitoringSourceAccountSetup)
+ [設定跨帳戶跨區域主控台的 Database Insights](#Database-Insights-Cross-Account-Cross-Region-setup)
+ [使用 Database Insights 跨帳戶跨區域儀表板](#Database-Insights-Cross-Account-Cross-Region-Using)

## 先決條件
<a name="Database-Insights-Cross-Account-Cross-Region-Prereq"></a>
+ Database Insights 跨帳戶跨區域需要先設定 **CloudWatch 跨帳戶可觀測性和****跨帳戶跨區域 CloudWatch 主控台**。請參閱以下如何啟用兩者的說明。
+ 如果您已啟用它們，則仍可能需要設定額外的資料共用，讓 Database Insights 在您的環境中跨帳戶和區域運作。請參閱以下說明，並確定您已選取正確的資料共用組態。

## 設定您的監控和來源帳戶以進行 Database Insights 跨帳戶存取
<a name="Database-Insights-Cross-Account-Cross-Region-MonitoringSourceAccountSetup"></a>

1. 遵循 [CloudWatch 跨帳戶可觀測性的](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Unified-Cross-Account-Setup.html)step-by-step指南。CloudFormation 範本以程式碼部署的形式提供給基礎設施。

1. 在**步驟 1：設定監控帳戶** - 服務、服務水準目標 (SLO) 中，您至少需要選取下列資料類型，才能與監控帳戶共用，以便 Database Insights 跨帳戶和區域運作：**日誌**、**指標**、**追蹤**和 Application Signals - 服務。 **SLOs**

1. 您需要針對要透過跨帳戶跨區域支援設定 Database Insights **的所有**區域執行此程序。

## 設定跨帳戶跨區域主控台的 Database Insights
<a name="Database-Insights-Cross-Account-Cross-Region-setup"></a>

1. 遵循[跨帳戶跨區域 CloudWatch 主控台](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Cross-Account-Cross-Region.html)中的step-by-step指南。

1. 在**步驟 5：許可**中，您至少需要選取要與監控帳戶共用的下列資料類型：**包含 CloudWatch 自動儀表板**，以及**包含 Database Insights 的唯讀存取權。**否則，您也可以選擇**對帳戶中所有內容進行完整唯讀存取**，其中包含所有可用的資料來源。

1.  CloudWatch 跨區域主控台是全域設定，因此您只需要執行此步驟一次，它適用於所有區域。

## 使用 Database Insights 跨帳戶跨區域儀表板
<a name="Database-Insights-Cross-Account-Cross-Region-Using"></a>

 設定 Database Insights 支援跨帳戶跨區域後，您可以在**資料庫檢視**下的左側面板的**篩選條件**區段中啟用「跨帳戶跨區域模式」。您會看到位於左上角的切換按鈕，如下螢幕擷取畫面所示。

![\[alt text not found\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/database-insights-enable-cross-account-toggle.png)


 啟用跨帳戶跨區域模式後，即可使用新的篩選條件，可讓您選取多個區域，並依 AWS 帳戶 IDs和標籤、資料庫資源類型和資料庫資源識別符進行篩選。

 根據預設，會選取您目前的區域和所有帳戶。如果您變更區域和帳戶的選取項目，機群運作狀態儀表板會自動更新，以顯示符合所選區域和帳戶篩選條件的資源。

 從機群運作狀態儀表板中，您可以針對屬於其他 AWS 帳戶和區域的執行個體，輕鬆導覽至資料庫執行個體儀表板。

 使用 Database Insights 跨帳戶跨區域監控時，必須考量幾個層面：
+  警示只能在監控帳戶中建立。警示可以在來源帳戶的指標上設定，但需要在監控帳戶中建立。
+  機群監控檢視只能定義並儲存在監控帳戶中。
+  Database Insights 執行個體儀表板中的自訂指標儀表板只能在監控帳戶中自訂。
+  指定時間的 Database Insights 機群運作狀態儀表板中允許的最大區域數為 3。
+  監控帳戶僅允許讀取操作。這表示您無法從監控帳戶建立效能分析報告。
+  在機群運作狀態儀表板中啟用跨帳戶跨區域模式時，無法使用 AWS 資源標籤和資源屬性進行篩選。

# 檢視 CloudWatch Database Insights 的機群運作狀態儀表板
<a name="Database-Insights-Fleet-Health-Dashboard"></a>

可以使用機群運作狀態儀表板來檢視資料庫機群運作狀態的快照。

![\[機群運作狀態儀表板\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_fhd.png)


## 機群運作狀態檢視
<a name="Database-Insights-fleet-views"></a>

Database Insights 中的*資料庫機群*是您要監控的一組資料庫。可以在**篩選條件**元件中選擇篩選條件，為資料庫機群建立監控檢視。藉助此元件，您可以在叢集或執行個體名稱及標籤等屬性上套用篩選條件。在機群運作狀態儀表板中，CloudWatch 會顯示符合機群運作狀態檢視至少一項篩選條件的資料庫。

![\[依屬性和標籤篩選\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_filter.png)


若要建立、修改或刪除資料庫機群的檢視，請依循下列主題中的程序操作。
+ [建立 CloudWatch Database Insights 的機群運作狀態檢視](Database-Insights-fleet-views-create.md)
+ [編輯 CloudWatch Database Insights 的機群運作狀態檢視](Database-Insights-fleet-views-edit.md)
+ [刪除 CloudWatch Database Insights 的機群運作狀態檢視](Database-Insights-fleet-views-delete.md)

## RDS 執行個體概觀資料表
<a name="Database-Insights-instances"></a>

**RDS 執行個體概觀**資料表會顯示機群中每個執行個體的警示狀態、資料庫負載百分比上限，以及上次狀態更新的時間。

![\[Amazon RDS 資源資料表\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_fhd-resources.png)


## 執行個體狀態摘要
<a name="Database-Insights-Instances-State-Summary"></a>

可透過**執行個體狀態摘要**檢視機群中所有執行個體的運作狀態。執行個體狀態摘要會根據**警示**和資料庫負載指標提供兩個檢視。依預設，CloudWatch 會顯示**警示**檢視。

![\[執行個體狀態摘要\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_iss.png)


Honeycomb 中的每個節點代表一個執行個體。如需執行個體的詳細資訊，可以選擇對應的節點，然後選擇**依此執行個體篩選檢視**。

![\[已選取執行個體狀態摘要\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_iss-selected.png)


Honeycomb 元件摘要說明機群中各個執行個體的警示狀態，並在 Honeycomb 頂端顯示處於每種狀態的節點數量。CloudWatch 顯示 Honeycomb 中顯示之資料的最後重新整理時間。

當您切換到**資料庫負載**檢視時，可以從資料庫負載指標的角度查看機群的整體運作狀態。資料庫負載 (DB 負載) 衡量的是資料庫中處於活躍狀態的工作階段的數量。資料庫負載是 Database Insights 中的關鍵指標，每秒收集一次。CloudWatch 根據資料庫負載的閾值，將資料庫執行個體分類為下列狀態。
+ 高
+ 警告
+ 確定
+ 閒置

可以透過選擇對應的狀態圖示來檢視資料庫負載的閾值。

如需 Amazon RDS 資料庫負載的相關資訊，請參閱《Amazon RDS 使用者指南》**中的 [Database load](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PerfInsights.Overview.ActiveSessions.html)。如需 Amazon Aurora 資料庫負載的相關資訊，請參閱《Amazon Aurora 使用者指南》**中的 [Database load](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PerfInsights.Overview.ActiveSessions.html)。

依預設，CloudWatch 會顯示資料庫負載平均值。選擇**最大值**可監控每個執行個體的資料庫負載上限。

從執行個體狀態摘要中選擇節點，可顯示執行個體的警示和資料庫負載。

## 前 10 個圖表
<a name="Database-Insights-Top-Ten"></a>

透過**依相對資料庫負載的前 10 個執行個體**圖表，可檢視資料庫負載隨時間的變化趨勢，該圖表顯示資料庫負載最高的前 10 個執行個體。此圖表還提供資料庫負載最高的執行個體的主要查詢和主要等待事件。

![\[「依資料庫負載排序的前 10 個執行個體」圖表\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_top10.png)


透過**依指標排序的前 10 個執行個體**圖表，可以比較機群中前 10 個執行個體的兩項關鍵指標。可以選取下列指標：
+ CPU 使用率 (%)
+ 可用記憶體 (%)
+ 資料庫連線 (%)
+ 網路輸送量
+ 讀取 IOPS
+ 寫入 IOPS
+ 讀取延遲
+ 寫入延遲

![\[「依指標排序的前 10 個執行個體」圖表\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_fhd-top10per.png)


## Amazon RDS 事件
<a name="Database-Insights-Events"></a>

可透過**事件**摘要和資料表檢視機群中執行個體的 RDS 事件。

![\[事件摘要\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_events.png)


若要檢視**事件**資料表，請選擇**詳細資訊**。

![\[事件詳細資訊\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_events-details.png)


如需 Amazon RDS 和 Amazon Aurora 事件清單，請參閱下列主題。
+ 《Amazon Aurora 使用者指南》中的 [Amazon RDS event categories and event messages for Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_Events.Messages.html) **
+ 《Amazon RDS 使用者指南》中的 [Amazon RDS event categories and event messages](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Events.Messages.html) **

## 呼叫服務資料表
<a name="Database-Insights-Calling-Services"></a>

可透過**呼叫服務**資料表檢視呼叫資料庫端點的 CloudWatch Application Signals 服務，以及延遲、錯誤等相關應用程式層級的指標。

![\[呼叫服務資料表\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_fhd-calling.png)


Database Insights 會顯示呼叫依資料庫負載排序之前 10 個執行個體的服務。若要檢視其他執行個體的呼叫服務，請在資料庫執行個體儀表板中選擇執行個體。

當應用程式呼叫的端點是 Aurora 叢集時，Database Insights 會在**呼叫服務**資料表中顯示 Aurora 叢集的寫入器或讀取器端點，而不是個別資料庫執行個體。不過，當應用程式呼叫的端點是 Amazon RDS 叢集時，Database Insights 會顯示應用程式在 Amazon RDS 叢集內呼叫的特定資料庫執行個體。

如需 CloudWatch Application Signals 的詳細資訊，請參閱 [應用程式訊號](CloudWatch-Application-Monitoring-Sections.md)。

# 建立 CloudWatch Database Insights 的機群運作狀態檢視
<a name="Database-Insights-fleet-views-create"></a>

若要建立機群運作狀態檢視，請依循下列程序。

**建立機群運作狀態檢視**

1. 簽署 AWS 管理主控台 並開啟位於 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 的 CloudWatch 主控台。

1. 選擇 **Insights**。

1. 選擇 **Database Insights**。

1. 選擇篩選條件，篩選出要監控的資料庫機群。

1. 選擇**將篩選條件儲存為機群**。

1. 在**儲存篩選條件集 (機群)** 視窗中，輸入機群的名稱。

1. 選擇 **Save (儲存)** 按鈕。

若要存取儲存的機群，請選擇**儲存的機群**下拉式清單。然後，選擇機群。

# 編輯 CloudWatch Database Insights 的機群運作狀態檢視
<a name="Database-Insights-fleet-views-edit"></a>

若要編輯機群運作狀態檢視，請依循下列程序。

**編輯機群運作狀態檢視**

1. 簽署 AWS 管理主控台 並開啟位於 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 的 CloudWatch 主控台。

1. 選擇 **Insights**。

1. 選擇 **Database Insights**。

1. 選擇**儲存的機群**下拉式清單。

1. 選擇要編輯之機群運作狀態檢視的垂直省略符號。

1. 在**編輯篩選條件集 (機群)** 視窗中，可以編輯機群的名稱和機群的篩選條件。

1. 選擇 **Save (儲存)** 按鈕。

# 刪除 CloudWatch Database Insights 的機群運作狀態檢視
<a name="Database-Insights-fleet-views-delete"></a>

若要刪除機群運作狀態檢視，請依循下列程序。

**刪除機群運作狀態檢視**

1. 簽署 AWS 管理主控台 並開啟位於 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 的 CloudWatch 主控台。

1. 選擇 **Insights**。

1. 選擇 **Database Insights**。

1. 選擇**儲存的機群**下拉式清單。

1. 選擇您要刪除之機群運作狀態檢視的垂直省略符號。

1. 在**刪除篩選條件集 (機群)** 視窗中，選擇**刪除**按鈕。

# 檢視 CloudWatch Database Insights 的資料庫執行個體儀表板
<a name="Database-Insights-Database-Instance-Dashboard"></a>

使用資料庫執行個體儀表板，可檢視資料庫執行個體的運作狀態概覽。

若要分析 Amazon Aurora PostgreSQL 的鎖樹狀目錄和執行計畫，請參閱下列主題。

**主題**
+ [使用 CloudWatch Database Insights 分析 Amazon Aurora PostgreSQL 和 Amazon RDS for PostgreSQL 的鎖定樹](Database-Insights-Lock-Analysis.md)
+ [使用 CloudWatch Database Insights 分析執行計畫](Database-Insights-Execution-Plans.md)

## 資料庫負載圖表
<a name="Database-Insights-database-load"></a>

*資料庫負載 (DB 負載)* 衡量資料庫中工作階段活動的層級。資料庫負載是 Database Insights 中的關鍵指標，Database Insights 每秒收集資料庫負載資料一次。

![\[資料庫執行個體儀表板\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_did.png)


如需資料庫負載的詳細資訊，請參閱《Amazon RDS 使用者指南》**中的[資料庫負載](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PerfInsights.Overview.ActiveSessions.html)或《Amazon Aurora 使用者指南》**中的[資料庫負載](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PerfInsights.Overview.ActiveSessions.html)。

使用**資料庫負載**圖表，可檢視所有受支援資料庫引擎的資料庫負載，負載依下列維度進行配量 (分組)。
+ 封鎖物件 (僅適用於[支援鎖分析的資料庫引擎](Database-Insights-Lock-Analysis.md))
+ 封鎖工作階段 (僅適用於[支援鎖分析的資料庫引擎](Database-Insights-Lock-Analysis.md))
+ 封鎖 SQL (僅適用於[支援鎖分析的資料庫引擎](Database-Insights-Lock-Analysis.md))
+ 資料庫
+ 主機
+ SQL
+ 使用者
+ 等待
+ 應用程式 (僅適用於 Amazon Aurora PostgreSQL)
+ 計畫 (僅適用於[支援執行計劃擷取的資料庫引擎](Database-Insights-Execution-Plans.md))
+ 工作階段類型 (僅適用於 Amazon Aurora PostgreSQL)

**注意**  
如需有關在 Amazon RDS 中分析 Oracle PDB 負載的資訊，請參閱《Amazon RDS 使用者指南》**中的[分析 Oracle PDB 負載](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_PerfInsights.UsingDashboard.AnalyzeDBLoad.TopPDB.html)。

![\[資料庫執行個體儀表板中的資料庫負載\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_did-dbload.png)


預設情況下，CloudWatch 會以長條圖顯示資料庫負載。選擇**折線圖**能以堆疊折線圖顯示資料庫負載。

![\[資料庫執行個體儀表板中資料庫負載的折線圖\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_did-dbload-line.png)


## 資料庫負載分析索引標籤
<a name="Database-Insights-DB-load-analysis"></a>

可以使用**資料庫負載分析**索引標籤，針對下列每個維度監控資料庫負載的主要貢獻因子。
+ 資料庫
+ 主機
+ SQL
+ 使用者
+ 等待
+ 鎖分析 (僅適用於[支援鎖分析的資料庫引擎](Database-Insights-Lock-Analysis.md))
+ 應用程式 (僅適用於 Amazon Aurora PostgreSQL)
+ 工作階段類型 (僅適用於 Amazon Aurora PostgreSQL)

![\[顯示資料庫負載分析索引標籤的儀表板\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_lat.png)


## 分析查詢統計資料
<a name="Database-Insights-sql-stats"></a>

您可能需要分析資料庫負載較高之查詢的統計資料。若要分析查詢統計資料，請依循下列程序。

**分析查詢統計資料**

1. 登入 AWS 管理主控台 ，並在 https：//[https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 選擇 **Insights**。

1. 選擇 **Database Insights**。

1. 選擇**資料庫執行個體**檢視。

1. 選擇資料庫執行個體。

1. 選擇 **Top SQL** (最高 SQL) 索引標籤。

1. 若要檢視查詢統計資料，請選擇查詢。  
![\[「最高 SQL」索引標籤中顯示的資料表。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/DBInsights_LoadTopSQL.png)

## 資料庫遙測索引標籤
<a name="Database-Insights-database-telemetry"></a>

透過**資料庫遙測**索引標籤，可檢視所選執行個體的指標、日誌、事件和慢速查詢。

### 資料庫遙測的指標區段
<a name="Database-Insights-metrics-tel"></a>

**指標**區段顯示為每個引擎類型自訂的預設指標儀表板。

可以新增作業系統指標、資料庫計數器指標和 CloudWatch 指標，以自訂此儀表板。也可以從儀表板移除指標。可以為區域中帳戶的每個引擎類型自訂一個儀表板。這意味著在該區域內，同一帳戶下特定引擎類型的所有執行個體都將共用相同的指標儀表板。

在您的帳戶中擁有儀表板編輯許可的使用者，可編輯任何引擎的任何儀表板。

您對儀表板所做的變更會自動儲存，並套用至該區域和帳戶中資料庫引擎的每個執行個體。

![\[儀表板顯示不同類型的資料庫指標範例。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_dbmetrics.png)


**在資料庫遙測索引標籤中針對引擎類型自訂儀表板**

1. 登入 AWS 管理主控台 ，並在 https：//[https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 選擇 **Insights**、**Database Insights**。

1. 針對**資料庫檢視**，選擇**資料庫執行個體**。

1. 在**篩選條件**區段中，尋找並選擇您要檢視其指標的資料庫執行個體。

1. 選擇**資料庫遙測**索引標籤，然後選擇**指標**索引標籤。

   預設資料庫執行個體儀表板將隨即顯示。

1. 若要將小工具新增至儀表板，請執行下列動作：

   1. 選擇**建立小工具**。

   1. 在**建立小工具**快顯視窗中，尋找您要新增的一個或多個指標，並選取每個指標的核取方塊。如果您在此步驟中選取多個指標，它們都會出現在儀表板上的同個新小工具中。然後選擇**建立小工具**。

      請記住，您對此儀表板所做的任何變更，都將套用至帳戶中此區域內此引擎類型的所有 Database Insights 儀表板。

1. 若要從儀表板刪除圖形，請在小工具中選擇垂直省略符號，然後選擇**刪除**。

1. 若要將更多指標新增至儀表板中的現有小工具，或變更其標題，請在小工具中選擇垂直省略符號，然後選擇**編輯**。然後在**更新小工具**快顯視窗中，尋找要新增的一個或多個指標，選取其核取方塊，然後選擇**更新小工具**。也可以變更小工具標題。

1. 自訂儀表板之後，可以選擇**重設儀表板**，將其重設為原始預設狀態。

### 資料庫遙測的日誌區段
<a name="Database-Insights-logs-tel"></a>

**日誌**區段提供針對所選資料庫執行個體的、匯出至 CloudWatch Logs 的資料庫日誌檢視。

![\[資料庫執行個體儀表板中的資料庫遙測\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_did-telemetry-logs.png)


如需有關將日誌發布到 CloudWatch Logs for Amazon RDS 的資訊，請參閱《Amazon RDS 使用者指南》中的[將資料庫日誌發布至 Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.Procedural.UploadtoCloudWatch.html)。**如需有關將日誌發布到 CloudWatch Logs for Amazon Aurora 的資訊，請參閱《Amazon Aurora 使用者指南》**中的[將資料庫日誌發布至 Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_LogAccess.Procedural.UploadtoCloudWatch.html)。

對於 Aurora PostgreSQL Limitless Databases，日誌會自動發布至 CloudWatch Logs，並且可在 Database Insights 主控台中偵測到。

### 作業系統會處理資料庫遙測資料
<a name="Database-Insights-OS-processes"></a>

可以使用**資料庫遙測**索引標籤中的**作業系統程序**索引標籤，來檢視執行資料庫執行個體之作業系統 (OS) 的指標。這些指標提供特定時間戳記下，於您的資料庫上執行之作業系統程序的快照，同時包含每個執行程序的關鍵指標，例如記憶體與 CPU 使用率。Database Insights 會將這些指標與資料庫負載圖表中的指標相互關聯，因此當您在資料庫負載圖表中選取某個資料點時，作業系統程序資料便會更新為顯示相同時間戳記的遙測資料。

當您選擇資料點時， Database Insights 會根據您為整體頁面選擇的時間範圍，自動選取要顯示的期間。您能回溯的最早時間，取決於您為 `RDSOSMetrics` 日誌群組設定的保留時間。

如果尚未選擇時間戳記，根據預設，資料表中會填入最新時間戳記的遙測。

**注意**  
只有在您已啟用 [Amazon RDS 增強型監控](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PerfInsights_Counters.html)功能時，才能使用作業系統程序資訊。增強型監控功能會產生額外費用。如需詳細資訊，請參閱[增強型監控的成本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_Monitoring.OS.html#USER_Monitoring.OS.cost)。系統會自動為 Aurora PostgreSQL Limitless Database 啟用增強型監控。

![\[事件資料表\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbinsights-osprocesses.png)


在**作業系統程序**檢視中，系統會針對每個程序顯示下列資料：
+ **程序 ID**：此程序的 ID。
+ **虛擬記憶體**：分配給程序的虛擬記憶體容量，以 KB 為單位。
+ **殘餘位址**：程序正在使用的實際實體記憶體。
+ **CPU%**：程序正在使用的 CPU 頻寬總量百分比。
+ **記憶體%**：程序正在使用的記憶體總量百分比。
+ **VM 限制**：可分配給程序的虛擬記憶體容量上限。

  如果此欄位中的值為 0，則 VM 限制不適用於該程序。

顯示的監控資料擷取自 Amazon CloudWatch Logs。也可以直接從 CloudWatch Logs 中的日誌串流擷取這些指標。如需相關資訊，請參閱[使用 CloudWatch Logs 檢視作業系統指標](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_Monitoring.OS.CloudWatchLogs.html)。

以下情況下不會傳回作業系統程序指標：
+ 資料庫執行個體容錯移轉。
+ 變更資料庫執行個體的執行個體類別 (擴充運算)。

在資料庫執行個體重新啟動期間會返回作業系統程序指標，因為只有資料庫引擎重新啟動。作業系統指標仍會繼續回報。

### 資料庫遙測的慢速 SQL 查詢區段
<a name="Database-Insights-slow-sql-tel"></a>

若要檢視慢速 SQL 查詢和查詢模式，必須啟用日誌匯出至 CloudWatch Logs，並設定資料庫的資料庫參數。

如需有關將 Amazon RDS 日誌發布到 CloudWatch Logs 的資訊，請參閱《Amazon RDS 使用者指南》中的[將資料庫日誌發布至 Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.Procedural.UploadtoCloudWatch.html)。**

如需有關將 Aurora 日誌發布到 CloudWatch Logs 的資訊，請參閱《Amazon Aurora 使用者指南》**中的[將資料庫日誌發布至 Amazon CloudWatch Logs](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_LogAccess.Procedural.UploadtoCloudWatch.html)。

如需在 Amazon RDS 中為資料庫設定資料庫參數的相關資訊，請參閱《Amazon RDS 使用者指南》**中的[使用 Database Insights for Amazon RDS 設定資料庫以監控慢速 SQL 查詢](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_DatabaseInsights.SlowSQL.html)。

如需在 Amazon Aurora中設定資料庫參數的相關資訊，請參閱《Amazon Aurora 使用者指南》[https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_DatabaseInsights.SlowSQL.html](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_DatabaseInsights.SlowSQL.html)中的*使用 Database Insights for Amazon Aurora 設定資料庫以監控慢速 SQL 查詢*。

**慢速 SQL 查詢**區段提供依頻率排序的慢速查詢模式清單。透過選取模式，可以檢視符合所選模式的慢速查詢清單。可以使用慢速查詢清單來識別影響資料庫執行個體的慢速查詢。

Database Insights 會顯示慢速查詢的統計資料。統計資料僅代表超出所設定慢速查詢持續時間閾值的查詢。

![\[顯示慢速 SQL 查詢範例的詳細資訊\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_slowsql.png)


**重要**  
慢速查詢可能包含敏感資料。使用 CloudWatch Logs 遮罩敏感資料。如需詳細資訊，請參閱《Amazon CloudWatch Logs 使用者指南》**中的[使用遮罩功能協助保護敏感日誌資料](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/mask-sensitive-log-data.html)。

### 事件資料表
<a name="Database-Insights-events-tel"></a>

可透過**事件**資料表檢視資料庫執行個體的 RDS 事件。如需 Amazon Aurora 的事件清單，請參閱《Amazon Aurora 使用者指南》**中的 [Aurora 的 Amazon RDS 事件類別和事件訊息](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_Events.Messages.html)。如需 Amazon 關聯式資料庫服務的事件清單，請參閱《Amazon RDS 使用者指南》中的 [Aurora 的 Amazon RDS 事件類別和事件訊息](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_Events.Messages.html)。 **

![\[事件資料表\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_did-events.png)


## 呼叫服務索引標籤
<a name="Database-Insights-calling"></a>

Database Insights 會顯示呼叫執行個體的服務和操作。Database Insights 會與 CloudWatch Application Signals 整合，提供每項服務和操作的指標，包括可用性、延遲、錯誤和磁碟區。

當應用程式呼叫的端點是 Aurora 叢集時，Database Insights 會在**呼叫服務**資料表中顯示 Aurora 叢集的寫入器或讀取器端點，而不是個別資料庫執行個體。不過，當應用程式呼叫的端點是 Amazon RDS 叢集時，Database Insights 會顯示應用程式在 Amazon RDS 叢集內呼叫的特定資料庫執行個體。」

![\[呼叫服務索引標籤\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_did-calling.png)


## 使用 CloudWatch Database Insights 隨需分析資料庫效能
<a name="Database-Insights-On-demand-Analysis"></a>

使用 CloudWatch Database Insights 對您的 Amazon RDS 資料庫執行隨需分析，以分析資料庫效能。

您可以透過選取**資料庫負載**圖表右上角的**分析效能**來執行隨需效能分析。報告將在選取的期間內執行。可透過**效能分析**索引標籤檢視機群中資料庫的效能分析報告。

![\[效能分析索引標籤\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_dl-perfanalysis.png)


如需有關 Amazon Aurora 效能分析報告的資訊，請參閱《Amazon Aurora 使用者指南》**中的[分析一段時間的資料庫效能](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PerfInsights.UsingDashboard.AnalyzePerformanceTimePeriod.html)。

## 將 CloudWatch Database Insights 與 CloudWatch Application Signals 整合
<a name="Database-Insights-Integration-Application-Signals"></a>

將 CloudWatch Database Insights 與 CloudWatch Application Signals 整合。

可透過**呼叫服務**索引標籤檢視呼叫所選執行個體端點的 CloudWatch Application Signals 服務和操作。預設情況下，CloudWatch 會依故障率對資料表進行排序。在**服務**、**操作**或**端點地址**欄位中選擇值，以在 CloudWatch Application Signals 主控台中檢視對應的資源。

如需 CloudWatch Application Signals 所支援系統的詳細資訊，請參閱 [支援的系統](CloudWatch-Application-Signals-supportmatrix.md)。

# 使用 CloudWatch Database Insights 分析 Amazon Aurora PostgreSQL 和 Amazon RDS for PostgreSQL 的鎖定樹
<a name="Database-Insights-Lock-Analysis"></a>

若要對鎖定造成的效能問題進行故障診斷，您可以使用下列方法，使用 CloudWatch Database Insights 分析 Amazon Aurora PostgreSQL 和 Amazon RDS for PostgreSQL 資料庫的鎖定樹。
+ **配量依據**下拉式清單 – 在**資料庫負載**圖表中，選擇**封鎖物件**、**封鎖工作階段**或**封鎖 SQL** 維度，以檢視主要阻礙因子如何隨時間推移影響資料庫負載。使用資料庫負載圖表，您可以分析主要阻礙因子是恆定存在還是頻繁變動。然後，可以對阻礙因子進行疑難排解。  
![\[在配量依據下拉式清單中選取封鎖工作階段的主要 SQL 資料表\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/DBInsights_TopSQLBlocking.png)
+ **鎖分析**索引標籤 – 選擇**資料庫負載分析**，然後選擇**鎖分析**索引標籤，以檢視資料庫中的鎖爭用資訊。  
![\[資料庫載入儀表板中的鎖樹狀目錄資料表\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/DBInsights_LoadLockAnalysis.png)

**注意**  
CloudWatch Database Insights 支援所有 Aurora PostgreSQL 版本的鎖分析。若要分析鎖樹狀目錄，必須啟用 Database Insights 進階模式。如需如何開啟進階模式的資訊，請參閱 [Turning on the Advanced mode of Database Insights for Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_DatabaseInsights.TurningOnAdvanced.html) 和 [Turning on the Advanced mode of Database Insights for Amazon Relational Database Service](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_DatabaseInsights.TurningOnAdvanced.html)

鎖分析索引標籤提供有關資料庫鎖爭用情況的資訊。鎖樹狀目錄視覺化圖形顯示來自不同工作階段的鎖請求之間的關係與相依項。

Database Insights 每 15 秒擷取一次快照。快照顯示某個時間點的資料庫鎖資料。

**注意**  
當 CloudWatch 偵測到高鎖定時，CloudWatch 會在**鎖分析**索引標籤上顯示**偵測到的高鎖定**橫幅。如果 CloudWatch 連續 15 分鐘每 15 秒拍攝鎖快照，CloudWatch 會偵測到高鎖定現象。

樹狀目錄中的每個節點代表特定工作階段。父節點是封鎖其子節點的工作階段。

若要分析鎖樹狀目錄，請依循下列程序。

**分析鎖樹狀目錄**

1. 登入 AWS 管理主控台 ，並在 https：//[https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 選擇 **Insights**。

1. 選擇 **Database Insights**。

1. 選擇**資料庫執行個體**檢視。

1. 選擇資料庫執行個體。

1. 選擇**資料庫負載分析**索引標籤。

1. 選擇**鎖分析**索引標籤。

   若要檢視資料庫執行個體的鎖資料，請將期間設定為 1 天或更短時間。

1. 選擇快照視窗。依預設， Database Insights 會選擇具有最多封鎖工作階段的快照視窗。  
![\[鎖分析資料表\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_lock-analysis.png)

1. 若要檢視快照的鎖資料，請選擇 Database Insights 拍攝快照的時間。

1. 若要展開鎖樹狀目錄，請選擇工作階段 ID 旁的箭頭。  
![\[已展開鎖樹狀目錄\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_lock-analysis-expand.png)

## 鎖快照資料
<a name="Database-Insights-Lock-Analysis-snapshot-data"></a>

Database Insights 為每個鎖請求提供以下資訊。若要檢視預設未啟用的欄位，請選擇**鎖樹狀目錄**資料表**的設定**圖示，並啟用其他欄位。


| 欄名稱 | 定義  | 預設欄位 | 備註 | 
| --- | --- | --- | --- | 
|  `session_id`  | 唯一的工作階段識別符。 |  是  | `session_id` 衍生自 `HEX(pg_stat_activity.backend_start).HEX(pg_locks.pid)`。 | 
|  `pid`  | 此後端的 PID。 |  是  | `pg_locks.pid` | 
|  `blocked_sessions_count`  | 此鎖封鎖的工作階段數目。 |  是  | `blocked_sessions_count` 衍生自此鎖封鎖的工作階段 ID 數目。 | 
|  `last_query_executed`  | 此工作階段執行的最後一個查詢。對於封鎖程式來說，可能不是將鎖封鎖的查詢。 |  是  | `pg_stat_activity.query` | 
|  `wait_event`  | 如果後端目前正在等待，則為等待事件名稱，否則值為 NULL。 |  是  | `pg_stat_activity.wait_event` | 
|  `blocking_time_(In Seconds)`  | 此鎖定啟動以來經過的時間 (以秒為單位)。 |  是  | `blocking_time_(In Seconds)` 衍生自首位等待者等待交易 (`pg_locks.waitstart`) 的開始時間。 | 
|  `blocking_mode`  | 封鎖工作階段保留的鎖模式。 |  否  | `pg_locks.mode` | 
|  `waiting_mode`  | 等待工作階段請求的鎖模式。 |  否  | `pg_locks.mode` | 
|  `application`  | 連線至後端的應用程式名稱。 |  否  | `pg_stat_activity.application_name` | 
|  `blocking_txn_start_time`  | 封鎖交易的開始時間，如果沒有作用中的交易，則為 null。 |  否  | `pg_stat_activity.xact_start` | 
|  `waiting_start_time`  | 等待中的使用者工作階段開始等待此鎖的時間，如果保留鎖，則為 null。 |  否  | `pg_locks.waitstart` | 
|  `session_start_time`  | 使用者工作階段開始的時間。 |  否  | `pg_stat_activity.backend_start` | 
|  `state`  | 後端的狀態。 |  否  | `pg_stat_activity.state` | 
|  `wait_event_type`  | 此工作階段正在等待的等待事件類型。 |  否  | `pg_stat_activity.wait_event_type` | 
|  `last_query_exec_time`  | 上次查詢開始的時間。 |  否  | `pg_stat_activity.query_start` | 
|  `user`  | 登入此後端之使用者的名稱。 |  否  | `pg_stat_activity.usename` | 
|  `host`  | 透過對 `client_addr` 執行反向 DNS 查詢所報告的、已連線用戶端的主機名稱。此欄位僅針對 IP 連線時為非空值，且僅在 [log\$1hostname](https://www.postgresql.org/docs/current/runtime-config-logging.html#GUC-LOG-HOSTNAME) 啟用時生效。 |  否  | `pg_stat_activity.client_hostname` | 
|  `port`  | 用戶端用於與此後端通訊的 TCP 連接埠號碼；如果使用 Unix 通訊端，則為 `-1`。如果此欄位為 null，表示這是內部伺服器程序。 |  否  | `pg_stat_activity.client_port` | 
|  `client_address`  | 連線到此後端之用戶端的 IP 位址。如果此欄位為 null，表示用戶端是透過伺服器機器上的 Unix 通訊端連線，或者這是自動清空等內部程序。 |  否  | `pg_stat_activity.client_addr` | 
|  `granted`  | 如果保留鎖，值為 true；如果等待鎖，則值為 false。 |  否  | `pg_locks.granted` | 
|  `waiting_tuple`  |  頁面內鎖針對的元組編號，若目標不是元組，則為 null。  |  否  | `pg_locks.tuple` | 
|  `waiting_page`  | 關係中鎖針對的頁碼，如果目標不是關係頁面或元組，則為 null。 |  否  | `pg_locks.page` | 
|  `waiting_transaction_id`  | 鎖針對的交易的 ID，如果目標不是交易 ID，則為 null。 |  否  | `pg_locks.transactionid` | 
|  `waiting_relation`  | 鎖針對的關係的 OID，如果目標不是關係或關係的一部分，則為 null。 |  否  | `pg_locks.relation` | 
|  `waiting_object_id`  | 鎖目標在其系統目錄內的 OID，如果目標不是一般資料庫物件，則為 null。 |  否  | `pg_locks.objid` | 
|  `waiting_database_id`  | 鎖目標所在之資料庫的 OID；如果目標是共用物件，值為零；如果目標是交易 ID，則為 null。 |  否  | `pg_locks.database` | 
|  `waiting_database_name`  | 鎖目標所在之資料庫的名稱。 |  否  | `pg_stat_activity.datname` | 
|  `waiting_locktype`  | 可鎖物件的類型：relation、extend、frozenid、page、tuple、transactionid、virtualxid、spectoken、object、userlock、advisory 或 applytransaction。 |  否  | `pg_locks.locktype` | 
|  `is_fastpath`  | 若鎖是以快速路徑取得，值為 true；若鎖是從主鎖資料表取得，則值為 false。 |  否  | `pg_locks.fastpath` | 

如需 `pg_stat_activity` 和 `pg_locks` 檢視中值的詳細資訊，請參閱 PostgreSQL 文件中的下列主題。
+ [pg\$1locks](https://www.postgresql.org/docs/current/view-pg-locks.html)
+ [pg\$1stat\$1activity](https://www.postgresql.org/docs/current/monitoring-stats.html#MONITORING-PG-STAT-ACTIVITY-VIEW)

# 使用 CloudWatch Database Insights 分析執行計畫
<a name="Database-Insights-Execution-Plans"></a>

可以使用下列方法分析 Amazon Aurora PostgreSQL、RDS for Microsoft SQL Server 和 RDS for Oracle 資料庫的執行計畫。
+ **配量依據**下拉式清單 – 選擇**資料庫負載**圖表中的**計畫**維度，可檢視不同計畫如何隨時間推移影響資料庫負載。
+ **最高 SQL** 索引標籤 – 選擇**資料庫負載分析**，然後選擇**最高 SQL** 索引標籤，以檢視每個摘要查詢的計畫數目。

  若要分析摘要查詢的執行計畫，請選擇查詢，然後選擇**計畫**索引標籤。如需詳細資訊，請參閱下列程序。

## 先決條件
<a name="Database-Insights-Execution-Plans-prereqs"></a>

若要分析執行計畫，必須使用 Database Insights 的進階模式。如需如何開啟進階模式的資訊，請參閱 [Turning on the Advanced mode of Database Insights for Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_DatabaseInsights.TurningOnAdvanced.html) 和 [Turning on the Advanced mode of Database Insights for Amazon Relational Database Service](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_DatabaseInsights.TurningOnAdvanced.html)。

如果使用的是 Aurora PostgreSQL，還需滿足下列先決條件：
+ 您的資料庫執行個體必須使用 Aurora PostgreSQL 版本 14.10、15.5 或更高版本。如需有關升級 Aurora PostgreSQL 資料庫叢集的資訊，請參閱《Amazon Aurora 使用者指南》**中的 [Upgrading Amazon Aurora PostgreSQL DB clusters](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_UpgradeDBInstance.PostgreSQL.html)。
+ 必須透過下列其中一個選項將參數 `aurora_compute_plan_id` 設定為 `on`，以設定資料庫叢集來分析執行計畫。
  + 《Amazon Aurora 使用者指南》中的 [Creating a DB cluster parameter group in Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_WorkingWithParamGroups.CreatingCluster.html) **
  + 《Amazon Aurora 使用者指南》中的 [Modifying parameters in a DB cluster parameter group in Amazon Aurora](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_WorkingWithParamGroups.ModifyingCluster.html) **

## 分析執行計畫
<a name="Database-Insights-Execution-Plans-analyze"></a>

若要分析執行計畫，請依循下列程序。

**分析執行計畫**

1. 簽署 AWS 管理主控台 並開啟位於 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 的 CloudWatch 主控台。

1. 選擇 **Insights**。

1. 選擇 **Database Insights**。

1. 選擇**資料庫執行個體**檢視。

1. 選擇資料庫執行個體。

1. 選擇 **Top SQL** (最高 SQL) 索引標籤。**欄位計數**欄位顯示針對每個摘要查詢收集的計畫數目。

1. (選用) 如果**計畫計數**資料欄未顯示，請選擇**最高 SQL** 資料表上的**設定**圖示，以自訂欄位的可見性和順序。  
![\[計畫詳細資訊資料表的設定\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/DBInsights2.png)

1. 選擇摘要查詢，展開到其元件陳述式中。  
![\[將查詢展開至其元件陳述式\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_did-dbload-expand.png)

1. 向下捲動並檢視 SQL 文字。然後，選擇**計畫**索引標籤。

   依預設，CloudWatch 會顯示預估的執行計畫。對於 Aurora PostgreSQL，若要檢視實際執行計畫，請啟用資料庫執行個體的 `aurora_stat_plans.with_analyze` 參數。如需有關參數 `aurora_stat_plans.with_analyze` 的詳細資訊，請參閱《Amazon Aurora 使用者指南》**中的監控 [Aurora PostgreSQL 的查詢執行計畫與尖峰記憶體用量](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/AuroraPostgreSQL.Monitoring.Query.Plans.html#aurora.with_analyze)。

1. 若要比較同個摘要查詢的計畫，請從**摘要查詢的計畫**清單中選擇兩個**計畫**。

   一次可以查看查詢的一個或兩個計畫。下列螢幕擷取畫面範例中，兩個計畫皆適用於 Aurora PostgreSQL。  
![\[比較計畫\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_did-plans.png)

1. 也可以透過在 DBLoad 圖表的**配量依據**下拉式清單中選擇**計畫**，檢視各項計畫如何隨時間推移影響資料庫負載。  
![\[Database load chart showing active sessions over time with plans contribution highlighted.\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/DBInsights_OverTime.png)

# 使用 Database Insights 監控 Aurora Limitless 資料庫
<a name="database-insights-limitless"></a>

Database Insights 支援在機群和執行個體層級監控 [Aurora PostgreSQL Limitless Database](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_DatabaseInsights.Engines.html)。可在資料庫執行個體儀表板和機群運作狀態儀表板中偵測到您的 Aurora PostgreSQL Limitless Database。

Aurora PostgreSQL Limitless Database 使用*碎片群組*。每個碎片群組包含多個資料庫執行個體，可協同處理分散式工作負載。Database Insights 可協助您了解碎片群組中執行個體之間的負載分佈。

在機群運作狀態儀表板中， Database Insights 可監控您的 Limitless 碎片群組，以及組成資料庫機群的其餘資料庫。可透過與機群中其他資料庫相同的方式，取得有關 Limitless 碎片群組運作狀態和 DBLoad 使用率的權威觀點。在執行個體儀表板中， Database Insights 會提供碎片群組層級以及針對群組內個別執行個體的監控。Database Insights 提供每個碎片群組的新檢視，您可以在其中查看資料庫負載在碎片群組內各執行個體間的分佈狀況。由此可導航至碎片群組內的特定執行個體儀表板。

## Aurora Limitless 的可用功能
<a name="database-insights-limitless-features"></a>

以下資料表顯示 Aurora PostgreSQL Limitless Database 可用的功能。它們會標示出各項功能是否支援標準監控模式與進階監控模式，是否可在碎片群組層級與執行個體層級使用，以及是否可在 Database Insights 的機群儀表板或執行個體儀表板中使用。


| 功能 | 標準 | Advanced (進階) | ShardGroup | 執行個體 | Database Insights 儀表板 | 
| --- | --- | --- | --- | --- | --- | 
| 依維度分析資料庫負載的主要貢獻因子 | 支援 | 支援 | 是 | 是 | 執行個體 | 
| 查詢資料庫指標，繪製圖表並設定警示，最多保留 7 天 | 支援 | 支援 | 是 | 是 | 執行個體 | 
| 定義精細存取控制政策，以限制對潛在敏感維度 (例如 SQL 文字) 的存取權限 | 支援 | 支援 | 是 | 是 | 執行個體 | 
| 使用負載分佈元件來分析同個碎片群組內執行個體之間的負載分佈 | 支援 | 支援 | 是 | 否 | 執行個體 | 
|  分析資料庫中的作業系統程序，並提供每個執行程序的詳細指標 此功能需要 [Amazon RDS 增強型監控](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_PerfInsights_Counters.html)才可運作。  | 不支援 | 支援 | 否 | 是 | 執行個體 | 
| 建立並儲存整個機群的監控檢視，以評估數百個資料庫的運作狀態 | 不支援 | 支援 | 是 | 否 | 機群 | 
| 分析具有 15 個月資料保留期與引導式使用者體驗的 SQL 鎖定狀態 | 不支援 | 不支援 | 否 | 否 | 執行個體 | 
| 分析具有 15 個月資料保留期與引導式使用者體驗的 SQL 執行計畫 | 不支援 | 不支援 | 否 | 否 | 執行個體 | 
| 視覺化每個查詢的統計資料 | 不支援 | 支援 | 否 | 是 | 執行個體 | 
| 分析執行緩慢的 SQL 查詢 需要將資料庫日誌匯出至 CloudWatch Logs，此功能才可運作。 | 不支援 | 支援 | 否 | 是 | 執行個體 | 
| 使用 CloudWatch Application Signals 檢視呼叫服務 | 不支援 | 支援 | 是 | 否 | 兩者 | 
| 檢視所有資料庫遙測的合併儀表板，包括指標、日誌、事件和應用程式需要將資料庫日誌匯出至 CloudWatch Logs，才可在 Database Insights 主控台中檢視資料庫日誌。 | 不支援 | 支援 | 否 | 是 | 執行個體 | 
| 自動將 Performance Insights 計數器指標匯入 CloudWatch | 不支援 | 支援 | N/A | N/A | 執行個體 | 
| 在 CloudWatch 中檢視 Amazon RDS 事件 | 不支援 | 支援 | 是 | 否 | 兩者 | 
| 使用按需分析功能來分析所選時段的資料庫效能 | 不支援 | 不支援 | 否 | 否 | 執行個體 | 

**注意**  
系統會自動為 Aurora PostgreSQL Limitless Database 啟用增強型監控。增強型監控功能會產生額外費用。如需詳細資訊，請參閱[增強型監控的成本](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_Monitoring.OS.html#USER_Monitoring.OS.cost)。  
對於 Aurora PostgreSQL Limitless Databases，日誌會自動發布至 CloudWatch Logs，並且可在 Database Insights 主控台中偵測到。此操作將產生額外費用，費用依據標準 CloudWatch Logs 定價計算。如需詳細了解 CloudWatch Logs 和 Database Insights 的定價方式及定價範例，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/?nc1=h_ls)。

## 在機群運作狀態儀表板中監控 Aurora Limitless 碎片群組
<a name="database-insights-limitless-fleet"></a>

 Database Insights 支援在機群運作狀態儀表板中監控 Aurora Limitless 碎片群組。

在此檢視中，您可以查看 Limitless 碎片群組，以及組成資料庫機群的其他資料庫。機群運作狀態儀表板提供有關 Limitless 碎片群組運作狀態和 DBLoad 使用率的權威觀點，類似於機群中其他資料庫資訊的呈現方式。

![\[Database Insights 機群運作狀態儀表板。主面板顯示代表資料庫執行個體的六邊形網格，其中一個反白顯示為「碎片群組 2」。會顯示路由器和碎片的資料庫負載使用率。右上角顯示一段時間內「依資料庫負載使用率排序的前 10 個執行個體」圖表。以下是「db-microsoftsqlserver-enterprise-1-dbi-advanced」的詳細資訊，包括熱門查詢和等待事件。底部區段不會顯示重要事件，也不會顯示呼叫服務。左側邊欄顯示總計 44 個執行個體，其中 2 個處於警示狀態，資料庫負載使用率平均值為 25.1%。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_fhd.png)


 在機群運作狀態儀表板中檢視 Aurora Limitless 資料庫時：
+ 只有碎片群組是可見的，而非個別的執行個體
+ 碎片群組出現在下列小工具中：
  + Honeycomb 圖表
  + 依資料庫負載排名前 10
  + 事件
  + 呼叫服務
  + 資料表清單
+ 提供路由器和碎片的資料庫負載使用率

透過此機群層級檢視，您可以監控 Aurora Limitless 碎片群組的效能，並將其與機群中的其他資料庫進行比較，提供整個資料庫機群的完整概觀。

![\[Database Insights 儀表板顯示資料庫執行個體清單。資料表將顯示 7 個執行個體及其資料庫識別符、警示狀態、引擎類型、資料庫負載使用率、上次狀態更新和資料庫版本。引擎包括 PostgreSQL、SQL Server Enterprise、Oracle Standard、Aurora MySQL 和 Aurora PostgreSQL。SQL Server 執行個體的負載最高，達到 25.21%。兩個 Aurora PostgreSQL 執行個體被標記為「Limitless」，並顯示碎片和路由器的個別使用率。介面包含篩選、排序和檢視其他詳細資訊的選項。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_fhd-limitless-list-view.png)


## 在執行個體儀表板中監控 Aurora PostgreSQL Limitless Database
<a name="database-insights-limitless-monitor"></a>

Database Insights 在 Aurora PostgreSQL Limitless Database 中的運作方式，與在標準 Aurora 資料庫叢集中的運作方式相同。不過，您可以在 Aurora PostgreSQL Limitless Database 的碎片群組層級追蹤指標。要追蹤的兩個主要指標如下：
+ **資料庫負載**：度量資料庫中的活動程度。關鍵指標為 `DBLoad`，每秒收集一次。`DBLoad` 指標的單位是平均作用中工作階段 (AAS)。為了取得平均作用中工作階段，Database Insights 會取樣並行執行查詢的工作階段數目。AAS 是將特定時段內的工作階段總數除以樣本總數。
+ **CPU 上限**：資料庫可用的運算能力上限。若要查看作用中的工作階段是否超過最大 CPU，請查看其與 `Max vCPU` 數線的關係。`Max vCPU` 值由資料庫執行個體的 vCPU (虛擬 CPU) 核心數目決定。

此外，您可以將 `DBLoad` 指標「配量」為維度，這是指標的子類別。最有用的維度如下：
+ **最高執行個體**：以遞減順序顯示執行個體 (碎片和路由器) 的相對資料庫負載。
+ **等待事件**：會導致 SQL 陳述式等待特定事件發生後，才能繼續執行。等待事件指出工作受到阻礙的位置。
+ **最高 SQL**：顯示哪些查詢對資料庫負載的貢獻最大。

![\[Database Insights 儀表板顯示資料庫效能指標。頂端區段顯示從 7 月 14 日 12:00 到 14:45 的折線圖追蹤資料庫活動。下方「資料庫負載分析」索引標籤顯示「最高執行個體」檢視，其中列出 4 個資料庫執行個體 (DTR-3-757、DTR-2-903、DAS-4-112 和 DAS-5-992) 及其負載使用率指標，所有數值均低於 0.01 AAS (平均作用中工作階段)。介面包含警示狀態、篩選條件和各種分析檢視的選項。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_limitless-top-instances.png)


## 使用 Database Insights 分析 Aurora PostgreSQL Limitless Database 的資料庫負載
<a name="database-insights-limitless-dbload"></a>

透過 Database Insights，您可以在碎片群組層級和執行個體層級追蹤 Aurora PostgreSQL Limitless Database 的指標。分析 Aurora PostgreSQL Limitless Database 的資料庫負載時，建議您將每個碎片和路由器的資料庫負載與最大 vCPU 進行比較。

絕對檢視會顯示平均作用中工作階段 (AAS) 的數量和預估 vCPU。相對檢視會顯示 AAS 與預估 vCPU 的比率。

![\[Database Insights 儀表板顯示碎片群組 1 Aurora PostgreSQL 叢集的資料庫負載分佈。介面會顯示平均作用中工作階段 (AAS) 的時間序列圖表，以及 5 個資料庫執行個體間負載分佈的圓餅圖。圓餅圖顯示總共有 261 個 AAS，百分比分別分配於 DTR-2-103、DTR-3-650、DAS-4-659、DAS-5-784、DAS-6-336 等執行個體。儀表板包含篩選條件、警示狀態和資料庫遙測選項。」\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/dbi_limitless-doughnut.png)


### 使用 Database Insights 儀表板分析相對資料庫負載
<a name="analyzing-relative-db-load"></a>

您可能想要透過追蹤相對資料庫負載，改善 Aurora PostgreSQL Limitless Database 的效能。若要按執行個體來分析 Aurora PostgreSQL Limitless Database 的相對資料庫負載，請依循下列程序。

**使用主控台分析相對資料庫負載**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇 Database Insights。

1. 選擇 Aurora PostgreSQL Limitless Database。Database Insights 儀表板會針對該 Aurora PostgreSQL Limitless Database 顯示。

1. 在資料庫載入 (DB 載入) 區段的*配量依據*中選擇*執行個體*。若要查看 Aurora PostgreSQL Limitless Database 中所有執行個體的平均作用中工作階段 (AAS) 與 vCPU 核心的比率，請針對*檢視為*選擇*相對*。

   平均作用中工作階段圖表顯示 Aurora PostgreSQL Limitless Database 中執行個體的資料庫負載。

1. 若要檢視最高執行個體，請選擇*最高執行個體*索引標籤。

1. (選用) 若要分析 Aurora PostgreSQL Limitless Database 中執行個體的資料庫負載，請在*執行個體*欄位中選擇執行個體名稱。

### 使用 Database Insights 儀表板依等待事件分析資料庫負載
<a name="analyzing-db-load-waits"></a>

您可能想要透過追蹤等待事件，改善 Aurora PostgreSQL Limitless Database 的效能。若要依等待事件分析 Aurora PostgreSQL Limitless Database 的資料庫負載，請依循下列程序。

**使用主控台依等待事件分析 Aurora PostgreSQL Limitless Database 的資料庫負載**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇 Database Insights。

1. 選擇 Aurora PostgreSQL Limitless Database。Database Insights 儀表板會針對該 Aurora PostgreSQL Limitless Database 顯示。

1. 在「資料庫負載」區段中，針對*配量依據*選擇*等待*。若要檢視 AAS 的數量和估計 vCPU，請針對*檢視為*選擇*絕對*。

   平均作用中工作階段圖表顯示 Aurora PostgreSQL Limitless Database 中執行個體的資料庫負載。

1. 向下捲動至 *Top SQL* (最高 SQL) 索引標籤。

1. 選擇 SQL 陳述式，展開到其元件陳述式中。

### 使用 Database Insights 儀表板分析負載分佈
<a name="analyzing-db-load-distribution"></a>

您可能想要平衡 Aurora PostgreSQL Limitless Database 上執行個體的負載分佈。若要分析 Aurora PostgreSQL Limitless Database 上執行個體的負載分佈，請依循下列程序。

**使用主控台分析 Aurora PostgreSQL Limitless Database 上執行個體的負載分佈**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇 Database Insights。

1. 選擇 Aurora PostgreSQL Limitless Database。Database Insights 儀表板會針對該 Aurora PostgreSQL Limitless Database 顯示。

1. 在資料庫載入 (DB 載入) 區段的*配量依據*中選擇*執行個體*。若要檢視 Aurora PostgreSQL Limitless Database 中所有執行個體的 AAS 數量和估計 vCPU，請針對*檢視為*選擇*絕對*。

   平均作用中工作階段圖表顯示 Aurora PostgreSQL Limitless Database 中執行個體的資料庫負載。

1. 若要查看 Aurora PostgreSQL Limitless Database 中執行個體負載分佈的圖表，請選擇*負載分佈*索引標籤。

# CloudWatch Database Insights 疑難排解
<a name="Database-Insights-Troubleshooting"></a>

參考以下資訊對 CloudWatch Database Insights 相關問題進行疑難排解。

## 套用標籤至 Amazon RDS 資源
<a name="Database-Insights-Troubleshooting-tags"></a>

若要套用標籤至資料庫，請使用 Amazon RDS API、AWS CLI 或 Amazon RDS 主控台。如需詳細資訊，請參閱下列主題。
+ *Amazon RDS API 參考*中的 [AddTagsToResource](https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_AddTagsToResource.html)
+ *Amazon RDS 命令列參考*中的 [add-tags-to-resource](https://docs.aws.amazon.com/cli/latest/reference/rds/add-tags-to-resource.html) 
+ 《Amazon Aurora 使用者指南》中的[標記 Amazon Aurora 和 Amazon RDS 資源](https://docs.aws.amazon.com/AmazonRDS/latest/AuroraUserGuide/USER_Tagging.html) **

## 機群的資料庫執行個體上限
<a name="Database-Insights-Troubleshooting-fleet-limit"></a>

不能在資料庫機群中監控超過 500 個資料庫執行個體。可以使用篩選條件來建立包含少於 500 個資料庫執行個體的機群運作狀態檢視。

# 使用 Contributor Insights 來分析高基數資料
<a name="ContributorInsights"></a>

您可以使用 Contributor Insights 來分析日誌資料，以及建立顯示參與者資料的時間序列。您可以查看與前 N 個參與者有關的指標、唯一參與者的總數及其用量。這有助於您尋找最頂端的說話者，並了解正在影響系統效能的對象或項目。例如，您可以尋找錯誤的主機、識別負荷最重的網路使用者，或是尋找產生最多錯誤的 URL。

您可以從頭開始建置規則，當您使用 時 AWS 管理主控台 ，也可以使用 AWS 已建立的範例規則。規則會定義您希望用來定義參與者的日誌欄位，例如 `IpAddress`。您也可以篩選日誌資料來尋找和分析個別參與者的行為。

CloudWatch 也提供內建規則，可讓您用來分析來自其他 AWS 服務的指標。

所有規則都會即時分析傳入的資料。

如果您登入的帳戶已設定為 CloudWatch 跨帳戶觀察功能中的監控帳戶，則可以在該監視帳戶中建立 Contributor Insights 規則，分析來源帳戶和監控帳戶中的日誌群組。您也可以建立單一規則，來分析多個帳戶中的日誌群組。如需詳細資訊，請參閱[CloudWatch 跨帳戶觀察功能](CloudWatch-Unified-Cross-Account.md)。

使用 Contributor Insights 時，每次出現符合規則的日誌事件，您都需要支付費用。如需詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

**注意**  
僅當規則參考的數值介於 -1e9 和 1e9 之間時，Contributor Insights 才能比對日誌項目。若日誌項目中的值超出此範圍，Contributor Insights 會略過該日誌項目。

**Topics**
+ [在 CloudWatch 中建立 Contributor Insights 規則](ContributorInsights-CreateRule.md)
+ [CloudWatch 中的 Contributor Insights 規則語法](ContributorInsights-RuleSyntax.md)
+ [CloudWatch Contributor Insights 規則範例](ContributorInsights-Rule-Examples.md)
+ [在 CloudWatch 中檢視 Contributor Insights 報告](ContributorInsights-ViewReports.md)
+ [在 CloudWatch 中繪製規則產生的指標](ContributorInsights-GraphReportData.md)
+ [在 CloudWatch 中使用 Contributor Insights 內建規則](ContributorInsights-BuiltInRules.md)

# 在 CloudWatch 中建立 Contributor Insights 規則
<a name="ContributorInsights-CreateRule"></a>

您可以建立規則來分析日誌資料。任何 JSON 或通用日誌格式 (CLF) 的日誌都可進行評估。這包括遵循這些格式之一的自訂日誌，以及來自 AWS 服務的日誌，例如 Amazon VPC 流程日誌、Amazon Route 53 DNS 查詢日誌、Amazon ECS 容器日誌，以及來自 Amazon SageMaker AI AWS CloudTrail、Amazon RDS AWS AppSync 和 API Gateway 的日誌。

在規格中，當您指定欄位名稱或值時，所有的比對都區分大小寫。

您可以在建立規則時使用內建範例規則，或者也可以從頭開始建立您自己的規則。Contributor Insights 包含下列日誌類型的範例規則：
+ Amazon API Gateway 日誌
+ Amazon Route 53 公有 DNS 查詢日誌
+ Amazon Route 53 Resolver 查詢日誌
+ CloudWatch Container Insights 日誌
+ VPC 流量日誌

如果您登入的帳戶已設定為 CloudWatch 跨帳戶觀察功能中的監控帳戶，您不僅可以為監控帳戶中的日誌群組建立規則，還可以為與此監控帳戶連結之來源帳戶中的日誌群組建立 Contributor Insights 規則。您也可以設定單一規則，來監控不同帳戶中的日誌群組。如需詳細資訊，請參閱[CloudWatch 跨帳戶觀察功能](CloudWatch-Unified-Cross-Account.md)。

**重要**  
當您將 `cloudwatch:PutInsightRule` 許可授予使用者時，依預設，該使用者可以建立規則來評估 CloudWatch Logs 中的任何日誌群組。您可以新增 IAM 政策條件，以限制這些許可，進而讓使用者包含和排除特定日誌群組。如需詳細資訊，請參閱[使用條件索引鍵限制 Contributor Insights 使用者存取日誌群組](iam-cw-condition-keys-contributor.md)。

**如何使用內建範例規則建立規則**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇**日誌**、**Contributor Insights**。

1. 選擇**建立規則**。

   

1.  在 **Select log group(s)** (選取日誌群組) 中，選取您要讓規則監控的日誌群組。您最多可以選取 20 個日誌群組。如果您已登入 CloudWatch 跨帳戶觀察功能中設定的監控帳戶，則可以在來源帳戶中選取日誌群組，然後設定單一規則來分析不同帳戶中的日誌群組。

   1.  (選用) 若要選取名稱開頭為特定字串的所有日誌群組，請選擇 **Select by prefix match** (依字首相符選取) 下拉式清單，然後輸入字首。如果這是監控帳戶，您可以選擇選取要搜尋的帳戶，否則會選取所有帳戶。
**注意**  
 每個符合規則的日誌事件都會產生費用。如果選擇 **Select by prefix match** (依字首相符選取) 下拉式清單，請注意字首可能匹配到的日誌群組數量。如果您搜尋到的日誌群組比所需的多，則可能會產生非預期的費用。如需詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing)。

1. 在 **Rule type** (規則類型) 中，選擇 **Sample rule** (範例規則)。然後選擇 **Select sample rule** (選取範例規則) 並選取規則。

1. 對於**日誌格式**，選取規則將評估之日誌的格式。

1. 對於**轉換器**，選取**在轉換器上啟用 Contributor Insights**，讓規則在 [CloudWatch Logs 日誌轉換功能](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CloudWatch-Logs-Transformation.html.html)轉換日誌事件之後，評估日誌事件。如果選取啟用此功能：
   + 如果規則評估具有轉換器的任何日誌群組，規則將套用至日誌的轉換後版本。
   + 如果規則評估沒有轉換器的日誌群組，規則將套用至日誌的原始版本。

   如果不選取此選項，評估將套用至所有日誌群組中的原始日誌事件，即使該等群組使用了日誌轉換亦然。
**注意**  
如果日誌群組具有轉換器，且某些日誌事件的轉換失敗，Contributor Insights 將不會評估該等日誌事件。如需有關調查日誌轉換故障的資訊，請參閱[轉換指標與錯誤](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Transformation-Errors-Metrics.html)。

1.  您選擇的規則範例已填寫**日誌格式**、**影響**、**篩選條件**和**彙整對象**等欄位。您可以視需要調整這些值。

1. 選擇**下一步**。

1. 在 **Rule name (規則名稱)** 中，輸入名稱。有效字元為 A-Z、a-z、0-9、(連字號)、(底線) 和 (句號)。

1. 選擇是要以停用或啟用狀態建立規則。如果您選擇啟用，規則會立即開始分析您的資料。執行啟用的規則時會產生費用。如需詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

   Contributor Insights 只會分析建立規則之後的新日誌事件。規則無法處理先前由 CloudWatch Logs 處理的日誌事件。

1. (選用) 在 **Tags** (標籤) 中，新增一或多個鍵/值對，作為此值的標籤。標籤可協助您識別和組織 AWS 資源，並追蹤成本 AWS 。如需詳細資訊，請參閱[標記您的 Amazon CloudWatch 資源](CloudWatch-Tagging.md)。

1. 選擇**建立**。

**如何從頭開始建立規則**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇**日誌**、**Contributor Insights**。

1. 選擇**建立規則**。

   

1.  在 **Select log group(s)** (選取日誌群組) 中，選取您要讓規則監控的日誌群組。您最多可以選取 20 個日誌群組。如果您已登入 CloudWatch 跨帳戶觀察功能中設定的監控帳戶，則可以在來源帳戶中選取日誌群組，然後設定單一規則來分析不同帳戶中的日誌群組。

   1.  (選用) 若要選取名稱開頭為特定字串的所有日誌群組，請選擇 **Select by prefix match** (依字首相符選取) 下拉式清單，然後輸入字首。
**注意**  
 每個符合規則的日誌事件都會產生費用。如果選擇 **Select by prefix match** (依字首相符選取) 下拉式清單，請注意字首可能匹配到的日誌群組數量。如果您搜尋到的日誌群組比所需的多，則可能會產生非預期的費用。如需詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing)。

1. 在 **Rule type** (規則類型) 中，選擇 **Custom rule** (自訂規則)。

1. 針對 **Log format (日誌格式)**，選擇 **JSON** 或 **CLF**。

1. 對於**轉換器**，選取**在轉換器上啟用 Contributor Insights**，讓規則在 [CloudWatch Logs 日誌轉換功能](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CloudWatch-Logs-Transformation.html.html)轉換日誌事件之後，評估日誌事件。如果選取啟用此功能：
   + 如果規則評估具有轉換器的任何日誌群組，規則將套用至日誌的轉換後版本。
   + 如果規則評估沒有轉換器的日誌群組，規則將套用至日誌的原始版本。

   如果不選取此選項，評估將套用至所有日誌群組中的原始日誌事件，即使該等群組使用了日誌轉換亦然。
**注意**  
如果日誌群組具有轉換器，且某些日誌事件的轉換失敗，Contributor Insights 將不會評估該等日誌事件。如需有關調查日誌轉換故障的資訊，請參閱[轉換指標與錯誤](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/Transformation-Errors-Metrics.html)。

1. 您可以使用精靈完成建立規則，或是透過選擇 **Syntax (語法)** 標籤並手動指定您的規則語法。

   如要繼續使用精靈，請執行以下作業：

   1. 針對 **Contribution (貢獻)**、**Key (索引鍵)**，輸入您希望報告的參與者類型。報告會針對此參與者類型顯示前 N 個值。

      有效的項目是任何包含值的日誌欄位。範例包括 **requestId**、**sourceIPaddress** 和 **containerID**。

      如需有關為特定日誌群組中的日誌尋找日誌欄位名稱的資訊，請參閱「[尋找日誌欄位](#finding_log_fields)」。

      大於 1 KB 的索引鍵會截斷至 1KB。

   1. (選用) 選擇 **Add new key** (新增鍵)，以新增更多鍵。您最多可以在規則中包含四個索引鍵。如果您輸入的索引鍵超過一個，報告中的參與者會由索引鍵的唯一值組合定義。例如，如果您指定了三個索引鍵，則三個索引鍵的每個唯一值組合都會計為唯一的參與者。

   1. (選用) 如果您想要新增篩選條件，來縮小結果範圍，請選擇 **Add filter** (新增篩選條件)。針對 **Match** (比對)，輸入您希望據以篩選的日誌名稱。針對 **Condition** (條件)，選擇比較運算子並輸入您希望為其進行篩選的值。

      您可以在規則中新增最多四個篩選條件。多個篩選條件會以 AND 邏輯聯結，因此只會評估符合所有篩選條件的日誌事件。
**注意**  
遵循比較運算子的陣列 (例如 `In`、`NotIn` 或 `StartsWith`) 最多可包含 10 個字串值。如需有關 Contributor Insights 規則語法的詳細資訊，請參閱 [CloudWatch 中的 Contributor Insights 規則語法](ContributorInsights-RuleSyntax.md)。

   1. 針對 **Aggregate on** (彙整對象)，選擇 **Count** (計數) 或 **Sum** (總和)。選擇 **Count** (計數) 會使參與者排名以發生次數為基礎。選擇 **Sum** (總和) 會使排名以您為 **Contribution** (貢獻)、**Value** (值) 所指定的欄位值彙整總和為基礎。

1. 如要輸入您的規則作為 JSON 物件，而非使用精靈，請執行以下作業：

   1. 選擇 **Syntax (語法)** 標籤。

   1. 在 **Rule body (規則主體)** 中，輸入您規則的 JSON 物件。如需規則語法的資訊，請參閱 [CloudWatch 中的 Contributor Insights 規則語法](ContributorInsights-RuleSyntax.md)。

1. 選擇**下一步**。

1. 在 **Rule name (規則名稱)** 中，輸入名稱。有效字元是 A‒Z、a‒z、0‒9、"-"、"\$1" 和 "."。

1. 選擇是要以停用或啟用狀態建立規則。如果您選擇啟用，規則會立即開始分析您的資料。執行啟用的規則時會產生費用。如需詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)。

   Contributor Insights 只會分析建立規則之後的新日誌事件。規則無法處理先前由 CloudWatch Logs 處理的日誌事件。

1. (選用) 在 **Tags** (標籤) 中，新增一或多個鍵/值對，作為此值的標籤。標籤可協助您識別和組織 AWS 資源，並追蹤成本 AWS 。如需詳細資訊，請參閱[標記您的 Amazon CloudWatch 資源](CloudWatch-Tagging.md)。

1. 選擇**下一步**。

1. 確認您輸入的設定值，然後選擇 **Create rule** (建立規則)。

您可以停用、啟用或刪除您已建立的規則。

**啟用、停用或刪除 Contributor Insights 中的規則**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇**日誌**、**Contributor Insights**。

1. 在規則清單中，選取單一規則旁邊的核取方塊。

   內建規則由 AWS 服務建立，無法編輯、停用或刪除。

1. 選擇 **Actions (動作)**，然後選擇您希望的選項。<a name="finding_log_fields"></a>

**尋找日誌欄位**

當您建立規則時，您需要了解日誌群組中日誌項目內的欄位名稱。

**尋找日誌群組中的日誌欄位**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格的 **Logs (日誌)** 下，選擇 **Insights (深入分析)**。

1. 在查詢編輯器上方，選取一或多個要查詢的日誌群組。

   選取日誌群組時，CloudWatch Logs Insights 會自動偵測日誌群組中資料內的欄位，並在 **Discovered fields** (已探索欄位) 的右側窗格中顯示。

# CloudWatch 中的 Contributor Insights 規則語法
<a name="ContributorInsights-RuleSyntax"></a>

本節說明 Contributor Insights 規則的語法。請只在您透過輸入 JSON 區塊來建立規則時使用此語法。如果您使用精靈建立規則，您便不需要了解語法。如需使用精靈建立規則的詳細資訊，請參閱 [在 CloudWatch 中建立 Contributor Insights 規則](ContributorInsights-CreateRule.md)。

所有規則與日誌事件欄位名稱及值進行的比對都區分大小寫。

以下範例示範 JSON 日誌的語法。

```
{
    "Schema": {
        "Name": "CloudWatchLogRule",
        "Version": 1
    },
    "LogGroupNames": [
        "API-Gateway-Access-Logs*",
        "Log-group-name2"
    ],
    "LogFormat": "JSON",
    "Contribution": {
        "Keys": [
            "$.ip"
        ],
        "ValueOf": "$.requestBytes",
        "Filters": [
            {
                "Match": "$.httpMethod",
                "In": [
                    "PUT"
                ]
            }
        ]
    },
    "AggregateOn": "Sum"
}
```Contributor Insights 規則中的欄位

結構描述  
 分析 CloudWatch Logs 資料之規則的 `Schema` 值必須總是為 `{"Name": "CloudWatchLogRule", "Version": 1}` 

LogGroupNames  
 字串陣列。針對陣列中的每個元素，您可以選擇在字串的結尾使用 `*` 來包含所有名稱開頭為該字首的日誌群組。  
請小心搭配日誌群組名稱使用萬用字元。每個符合規則的日誌事件都會產生費用。如果您不小心搜尋了比您預期數量更多的日誌群組，您可能會產生未預期的費用。如需詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing)。

LogGroupARNs  
如果您要在 CloudWatch 跨帳戶觀察功能的監控帳戶中建立此規則，則可以使用 `LogGroupARNs` 來指定與監控帳戶連結之來源帳戶中的日誌群組，還可以指定監控帳戶自身中的日誌群組。您必須在規則中指定 `LogGroupNames` 或 `LogGroupARNs`，但不能同時指定兩者。  
 `LogGroupARNs` 是字串陣列。對於陣列中的每個元素，您可以在某些情況下選擇使用 `*` 作為萬用字元。例如，您可以指定 `arn:aws:logs:us-west-1:*:log-group/MyLogGroupName2`，以指定美國西部 (加利佛尼亞北部) 區域中所有來源帳戶以及監控帳戶中命名為 `MyLogGroupName2` 的日誌群組。您也可以指定 `arn:aws:logs:us-west-1:111122223333:log-group/GroupNamePrefix*`，來指定 111122223333 帳戶在美國西部 (加利佛尼亞北部) 中名稱以 `GroupNamePrefix` 開頭的所有日誌群組。  
您無法指定部分 AWS 帳戶 ID 做為萬用字元的字首。  
將萬用字元用於日誌群組 ARN 用時應小心。每個符合規則的日誌事件都會產生費用。如果您不小心搜尋了比您預期數量更多的日誌群組，您可能會產生未預期的費用。如需詳細資訊，請參閱 [Amazon CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing)。

LogFormat  
 有效值為 `JSON` 和 `CLF`。

Contribution  
 此物件包含 `Keys` 陣列 (其中最多可以有四個成員)、選用的單一 `ValueOf`，以及其中最多可包含四個 `Filters` 的選用陣列。

金鑰  
 最多四個日誌欄位的陣列，會用來作為分類參與者的維度。如果您輸入的索引鍵超過一個，索引鍵值的每個唯一組合都會計為唯一的參與者。欄位必須使用 JSON 屬性格式表示法指定。

ValueOf  
 (選用) 請只在您指定 `Sum` 作為 `AggregateOn` 的值時才使用此項目。`ValueOf` 會使用數值指定日誌欄位。在這種規則類型中，參與者會根據此欄位值的總和進行排名，而非在日誌項目中發生的次數。例如，如果您想要根據其在特定期間內的總 `BytesSent` 排名參與者，您可將 `ValueOf` 設為 `BytesSent`，並為 `AggregateOn` 指定 `Sum`。

篩選條件  
 指定最多四個篩選條件的陣列，縮小包含在報告中的日誌事件。如果您指定了多個篩選條件，Contributor Insights 會使用邏輯 AND 運算子進行評估。您可以使用此項目來在您的搜尋中篩選掉不相關的日誌事件，或是您可以用來選取單一參與者以分析其行為。  
陣列中的每個成員都必須包含 `Match` 欄位，以及一個指出要使用比對運算子類型的欄位。  
`Match` 欄位會指定要在篩選條件中評估的日誌欄位。日誌欄位是使用 JSON 屬性格式表示法指定。  
比對運算子欄位必須是以下其中一個：`In`、`NotIn`、`StartsWith`、`GreaterThan`、`LessThan`、`EqualTo`、`NotEqualTo` 或 `IsPresent`。如果運算子欄位是 `In`、`NotIn` 或 `StartsWith`，其後會跟隨一個要檢查的字串值陣列。Contributor Insights 會使用 OR 運算子評估字串值陣列。陣列最多可包含 10 個字串值。  
如果運算子欄位是 `GreaterThan`、`LessThan`、`EqualTo` 或 `NotEqualTo`，其後會跟隨要比較的單一數值。  
如果運算子欄位是 `IsPresent`，其後會跟隨 `true` 或 `false`。此運算子會根據日誌事件中是否存在指定的日誌欄位來比對日誌事件。`isPresent` 只能搭配 JSON 屬性分葉節點中的值運作。例如，尋找與 `c-count` 相符的篩選條件不會評估值為 `details.c-count.c1` 的日誌事件。  
請參閱以下四個篩選條件範例：  

```
{"Match": "$.httpMethod", "In": [ "PUT", ] }
{"Match": "$.StatusCode", "EqualTo": 200 }
{"Match": "$.BytesReceived", "GreaterThan": 10000}
{"Match": "$.eventSource", "StartsWith": [ "ec2", "ecs" ] }
```

AggregateOn  
 有效值為 `Count` 和 `Sum`。指定是要根據發生計數彙整報告，還是在 `ValueOf` 欄位中指定的欄位值總和彙整報告。

**JSON 屬性格式表示法**

`Keys`、`ValueOf` 和 `Match` 欄位允許使用點表示法的 JSON 屬性格式，其中 `$` 表示 JSON 物件的根。其後會跟隨一個句點，然後是包含子屬性名稱的英數字串。其支援多個屬性層級。

字串的第一個字元只能是 A-Z 或 a-z。字串的後續字元可以是 A-Z、a-z 或 0-9。

以下清單示範 JSON 屬性格式的有效範例：

```
$.userAgent
$.endpoints[0]
$.users[1].name
$.requestParameters.instanceId
```

**CLF 日誌規則中的其他欄位**

通用日誌格式 (CLF) 日誌事件不會跟 JSON 一樣包含欄位的名稱。如要提供欄位以用於 Contributor Insights 規則，CLF 日誌事件可以視為索引從 `1` 開始的陣列處理。您可以將第一個欄位指定為 **"1"**，將第二個欄位指定為 **"2"**，以此類推。

如要讓 CLF 日誌的規則更容易閱讀，您可以使用 `Fields`。這可以讓您為 CLF 欄位位置提供命名別名。例如，您可以指定位置 "4" 是一個 IP 位址。指定之後，`IpAddress` 便可以用來在規則的 `Keys`、`ValueOf` 和 `Filters` 中作為屬性。

以下是使用 `Fields` 欄位的 CLF 日誌規則範例。

```
{
    "Schema": {
        "Name": "CloudWatchLogRule",
        "Version": 1
    },
    "LogGroupNames": [
        "API-Gateway-Access-Logs*"
    ],
    "LogFormat": "CLF",
    "Fields": {
        "4": "IpAddress",
        "7": "StatusCode"
    },
    "Contribution": {
        "Keys": [
            "IpAddress"
        ],
        "Filters": [
            {
                "Match": "StatusCode",
                "EqualTo": 200
            }
        ]
    },
    "AggregateOn": "Count"
}
```

# CloudWatch Contributor Insights 規則範例
<a name="ContributorInsights-Rule-Examples"></a>

本節包含範例，示範 Contributor Insights 規則的使用案例。

**VPC 流程日誌：來源及目的地 IP 地址傳輸的位元組**

```
{
    "Schema": {
        "Name": "CloudWatchLogRule",
        "Version": 1
    },
    "LogGroupNames": [
        "/aws/containerinsights/sample-cluster-name/flowlogs"
    ],
    "LogFormat": "CLF",
    "Fields": {
        "4": "srcaddr",
        "5": "dstaddr",
        "10": "bytes"
    },
    "Contribution": {
        "Keys": [
            "srcaddr",
            "dstaddr"
        ],
        "ValueOf": "bytes",
        "Filters": []
    },
    "AggregateOn": "Sum"
}
```

**VPC 流程日誌：HTTPS 請求數量上限**

```
{
    "Schema": {
        "Name": "CloudWatchLogRule",
        "Version": 1
    },
    "LogGroupNames": [
        "/aws/containerinsights/sample-cluster-name/flowlogs"
    ],
    "LogFormat": "CLF",
    "Fields": {
        "5": "destination address",
        "7": "destination port",
        "9": "packet count"
    },
    "Contribution": {
        "Keys": [
            "destination address"
        ],
        "ValueOf": "packet count",
        "Filters": [
            {
                "Match": "destination port",
                "EqualTo": 443
            }
        ]
    },
    "AggregateOn": "Sum"
}
```

**VPC 流程日誌：遭拒絕的 TCP 連線**

```
{
    "Schema": {
        "Name": "CloudWatchLogRule",
        "Version": 1
    },
    "LogGroupNames": [
        "/aws/containerinsights/sample-cluster-name/flowlogs"
    ],
    "LogFormat": "CLF",
    "Fields": {
        "3": "interfaceID",
        "4": "sourceAddress",
        "8": "protocol",
        "13": "action"
    },
    "Contribution": {
        "Keys": [
            "interfaceID",
            "sourceAddress"
        ],
        "Filters": [
            {
                "Match": "protocol",
                "EqualTo": 6
            },
            {
                "Match": "action",
                "In": [
                    "REJECT"
                ]
            }
        ]
    },
    "AggregateOn": "Sum"
}
```

**依來源地址進行 Route 53 NXDomain 回應**

```
{
    "Schema": {
        "Name": "CloudWatchLogRule",
        "Version": 1
    },
    "AggregateOn": "Count",
    "Contribution": {
        "Filters": [
            {
                "Match": "$.rcode",
                "StartsWith": [
                    "NXDOMAIN"
                ]
            }
        ],
        "Keys": [
            "$.srcaddr"
        ]
    },
    "LogFormat": "JSON",
    "LogGroupNames": [
        "<loggroupname>"
    ]
}
```

**依網域名稱進行 Route 53 Resolver 查詢**

```
{
    "Schema": {
        "Name": "CloudWatchLogRule",
        "Version": 1
    },
    "AggregateOn": "Count",
    "Contribution": {
        "Filters": [],
        "Keys": [
            "$.query_name"
        ]
    },
    "LogFormat": "JSON",
    "LogGroupNames": [
        "<loggroupname>"
    ]
}
```

**依查詢類型和來源地址進行 Route 53 Resolver 查詢**

```
{
    "Schema": {
        "Name": "CloudWatchLogRule",
        "Version": 1
    },
    "AggregateOn": "Count",
    "Contribution": {
        "Filters": [],
        "Keys": [
            "$.query_type",
            "$.srcaddr"
        ]
    },
    "LogFormat": "JSON",
    "LogGroupNames": [
        "<loggroupname>"
    ]
}
```

# 在 CloudWatch 中檢視 Contributor Insights 報告
<a name="ContributorInsights-ViewReports"></a>

如要檢視報告資料的圖表和您規則找到的參與者排名清單，請遵循這些步驟。

**檢視您的規則報告**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇**日誌**、**Contributor Insights**。

   

1. 在規則清單中，選擇規則的名稱。

   圖表會顯示過去三個小時內的規則結果。圖表下方的表格會顯示前 10 個參與者。

1. 如要變更表格中顯示的參與者數，請選擇圖表頂端的 **Top 10 contributors (前 10 個參與者)**。

1. 如要篩選圖表，只顯示來自單一參與者的結果，請在表格圖例中選擇該參與者。如要再次顯示所有參與者，請在圖例中再次選擇相同的參與者。

1. 如要變更報告中顯示的時間範圍，請在圖表的頂端選擇 **15m** (15 分鐘)、**30m** (30 分鐘)、**1h** (1 小時)、**2h** (2 小時)、**3h** (3 小時) 或 **custom** (自訂)。

   報告的時間範圍上限是 24 小時，但您可以選擇長達過去 15 天內發生的 24 小時時段。如要選擇過去的時段，請選擇 **custom (自訂)**、**absolute (絕對)**，然後指定您的時段。

1. 如要變更用於彙整和排名參與者的時間期間長度，請選擇圖表頂端的 **period (期間)**。檢視更長的時間期間通常會顯示尖峰較少且較為平滑的報告。選擇較短的時間期間更有可能會顯示尖峰。

1. 若要將此圖表新增至 CloudWatch 儀表板，請選擇 **Add to dashboard** (新增至儀表板)。

1. 若要開啟 CloudWatch Logs Insights 查詢視窗，並在查詢方塊中載入此報告中的日誌群組，請選擇 **View logs** (檢視日誌)。

1. 如要將報告資料匯出至您的剪貼簿或 CSV 檔案，請選擇 **Export (匯出)**。

# 在 CloudWatch 中繪製規則產生的指標
<a name="ContributorInsights-GraphReportData"></a>

Contributor Insights 提供指標數學函數 `INSIGHT_RULE_METRIC`。您可以使用此函數，將 Contributor Insights 報表中的資料新增至 CloudWatch 主控台的 **Metrics** (指標) 標籤。您也可以根據此數學函數設定警示。如需指標數學函數的詳細資訊，請參閱 [搭配 CloudWatch 指標使用數學表達式](using-metric-math.md)。

若要使用此指標數學函數，您必須登入擁有 `cloudwatch:GetMetricData` 和 `cloudwatch:GetInsightRuleReport` 許可的帳戶。



語法是 `INSIGHT_RULE_METRIC(ruleName, metricName)`。*ruleName* 是 Contributor Insights 規則的名稱。*metricName* 是以下清單中的其中一個值。*metricName* 的值會判斷數學函數傳回的資料類型。
+ `UniqueContributors` — 每個資料點的唯一貢獻因子數目。
+ `MaxContributorValue` — 每個資料點的最佳貢獻因子值。圖表中每個資料點的參與者的身分可能會變更。

  如果此規則是以 `Count` 彙整，則每個資料點的最高貢獻因子是在該期間中發生次數最多的貢獻因子。如果規則是以 `Sum` 彙整，則最高貢獻因子是該期間中，規則的 `Value` 所指定日誌欄位內總和數最大的貢獻因子。
+ `SampleCount` — 規則符合的資料點數目。
+ `Sum` — 該資料點所表示時間期間內來自所有貢獻因子的值的總和。
+ `Minimum` — 該資料點所表示時間期間內單一觀察的最小值。
+ `Maximum` — 該資料點所表示時間期間內單一觀察的最大值。
+ `Average` — 該資料點所表示時間期間內來自所有貢獻因子的平均值。

## 在 Contributor Insights 指標資料上設定警示
<a name="ContributorInsights-GraphReportData-Alarm"></a>

您可以使用函數 `INSIGHT_RULE_METRIC`，對 Contributor Insights 產生的指標設定警示。例如，您可以根據遭拒絕傳輸控制通訊協定 (TCP) 連線百分比來建立警示。如果要開始使用此類警示，您可以建立類似於以下兩個範例中所示的規則：

**規則範例：「RejectedConnectionsRule」**

```
{
    "Schema": {
        "Name": "CloudWatchLogRule",
        "Version": 1
    },
    "LogGroupNames": [
        "/aws/containerinsights/sample-cluster-name/flowlogs"
    ],
    "LogFormat": "CLF",
    "Fields": {
        "3": "interfaceID",
        "4": "sourceAddress",
        "8": "protocol",
        "13": "action"
    },
    "Contribution": {
        "Keys": [
            "interfaceID",
            "sourceAddress"
        ],
        "Filters": [
            {
                "Match": "protocol",
                "EqualTo": 6
            },
            {
                "Match": "action",
                "In": [
                    "REJECT"
                ]
            }
        ]
    },
    "AggregateOn": "Sum"
}
```

**規則範例：「TotalConnectionsRule」**

```
{
    "Schema": {
        "Name": "CloudWatchLogRule",
        "Version": 1
    },
    "LogGroupNames": [
        "/aws/containerinsights/sample-cluster-name/flowlogs"
    ],
    "LogFormat": "CLF",
    "Fields": {
        "3": "interfaceID",
        "4": "sourceAddress",
        "8": "protocol",
        "13": "action"
    },
    "Contribution": {
        "Keys": [
            "interfaceID",
            "sourceAddress"
        ],
        "Filters": [{
            "Match": "protocol",
            "EqualTo": 6
        }],
        "AggregateOn": "Sum"
    }
}
```

建立規則後，您便可以在 CloudWatch 主控台中選取 **Metrics** (指標) 索引標籤，您可以在其中使用以下指標數學表達式範例來繪製 Contributor Insights 報告的資料圖表：

**範例：指標數學表達式**

```
e1 INSIGHT_RULE_METRIC("RejectedConnectionsRule", "Sum")
e2 INSIGHT_RULE_METRIC("TotalConnectionsRule", "Sum")
e3 (e1/e2)*100
```

在該範例中，指標數學表達式 `e3` 會傳回所有遭拒絕的 TCP 連線。如果您想要在 20% 的 TCP 連線遭到拒絕時收到通知，您可以透過將閾值從 `100` 變更為 `20` 來修改表達式。

**注意**  
您可以在 **Metrics** (指標) 區段中，對您監控的指標設定警示。在 **Graphed metrics** (圖表化指標) 索引標籤上，您可以選取 **Actions** (動作) 資料欄下的 **Create alarm** (建立警示) 圖示。**Create alarm** (建立警示) 圖示看起來像個鈴鐺。

如需有關繪製指標圖表和使用指標數學函數的詳細資訊，請參閱以下區段：[將數學運算式新增至 CloudWatch 圖形](using-metric-math.md#adding-metrics-expression-console)。

# 在 CloudWatch 中使用 Contributor Insights 內建規則
<a name="ContributorInsights-BuiltInRules"></a>

您可以使用 Contributor Insights 內建規則來分析來自其他服務的指標 AWS 。下列服務支援內建規則：
+ 《Amazon DynamoDB 開發人員指南》中的 [Contributor Insights for Amazon DynamoDB](https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/contributorinsights.html)。
+ 《AWS PrivateLink 指南》中的[使用 Contributor Insights 內建規則](https://docs.aws.amazon.com/vpc/latest/privatelink/privatelink-cloudwatch-metrics.html#privatelink-contributor-insights)。

# 偵測常見的 CloudWatch Application Insights 應用程式問題
<a name="cloudwatch-application-insights"></a>

使用 Amazon CloudWatch Application Insights 來偵測應用程式的問題。CloudWatch Application Insights 可為您的應用程式和基礎 AWS 資源提供可觀測性。它可協助您設定應用程式資源的最佳監控，以持續分析資料的應用程式問題跡象。Application Insights 採用 [SageMaker](https://docs.aws.amazon.com/sagemaker/latest/dg/wahtis.html) 和其他 AWS 技術，提供自動化儀表板，顯示監控應用程式的潛在問題，協助您快速隔離應用程式和基礎設施正在發生的問題。Application Insights 為應用程式運作狀態提供的增強可見度，有助於降低平均修復時間 (MTTR)，進而故障診斷應用程式的問題。

當您在 Amazon CloudWatch Application Insights 中新增應用程式時，它會掃描應用程式中的資源，並在適用於應用程式元件的 [CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html) 中建議和設定指標和日誌。範例應用程式元件可包含 SQL Server 後端資料庫和 Microsoft IIS/Web 層。Application Insights 會使用歷史資料分析指標模式以偵測異常，並持續偵測應用程式、作業系統和基礎設施日誌中的錯誤和異常。它會結合分類演算法和內建規則，建立這些觀察的關聯。然後，自動建立儀表板，顯示相關的觀察和問題嚴重性資訊，協助您決定動作的優先順序。針對 .NET 和 SQL 應用程式堆疊中的常見問題，例如應用程式延遲、SQL Server 故障備份、記憶體流失、大型 HTTP 請求，以及取消的輸入/輸出操作，它提供了額外的洞察，指出可能的根本原因和解決步驟。內建與 [AWS SSM OpsCenter](https://docs.aws.amazon.com/systems-manager/latest/userguide/OpsCenter.html) 的整合可讓您執行相關的 Systems Manager Automation 文件以解決問題。

**Topics**
+ [什麼是 Amazon CloudWatch Application Insights？](appinsights-what-is.md)
+ [Application Insights 的運作方式](appinsights-how-works.md)
+ [先決條件、IAM 政策和許可](appinsights-accessing.md)
+ [設定應用程式以進行監控](appinsights-setting-up.md)
+ [Application Insights 跨帳戶觀察](appinsights-cross-account.md)
+ [使用元件組態](component-config.md)
+ [使用 CloudFormation 範本](appinsights-cloudformation.md)
+ [教學課程：設定 SAP ASE 的監控](appinsights-tutorial-sap-ase.md)
+ [教學課程：設定 SAP HANA 的監控](appinsights-tutorial-sap-hana.md)
+ [教學課程：設定 SAP NetWeaver 的監控](appinsights-tutorial-sap-netweaver.md)
+ [檢視和故障診斷 Application Insights](appinsights-troubleshooting.md)
+ [支援的日誌和指標](appinsights-logs-and-metrics.md)

# 什麼是 Amazon CloudWatch Application Insights？
<a name="appinsights-what-is"></a>

CloudWatch Application Insights 可幫助您監控使用 Amazon EC2 執行個體以及其他 [應用程式資源](#appinsights-components)的應用程式。它會識別和設定關鍵指標、日誌，並在您所有的應用程式資源和技術堆疊 (例如，Microsoft SQL Server 資料庫、Web (IIS) 和應用程式伺服器、作業系統、負載平衡器和佇列) 中發出警示。並持續監控指標和日誌，以偵測和建立異常及錯誤的關聯。偵測到錯誤和異常時，Application Insights 會產生 [CloudWatch Events](https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/WhatIsCloudWatchEvents.html)，可用於設定通知或採取動作。為協助進行故障診斷，它會建立已偵測到問題的自動化儀表板，包括關聯的指標異常和日誌錯誤以及其他洞見，指出可能的根本原因。自動化儀表板可協助您採用補救動作，讓應用程式保持良好的運作狀態，防止應用程式的最終使用者受到影響。它也會建立 OpsItems，讓您使用 [AWS SSM OpsCenter](https://docs.aws.amazon.com/systems-manager/latest/userguide/OpsCenter.html) 解決問題。

您可以在 CloudWatch 上設定重要的計數器，例如鏡像寫入交易/秒、復原佇列長度和交易延遲，以及 Windows 事件日誌。當 SQL HA 工作負載發生容錯移轉事件或問題時，CloudWatch Application Insights 會提供自動化洞察，例如對查詢目標資料庫的限制存取。

CloudWatch Application Insights 已與 [AWS Launch Wizard](https://docs.aws.amazon.com/launchwizard/latest/userguide/what-is-launch-wizard.html) 整合，可在 AWS上部署 SQL Server HA 工作負載時提供單鍵監控設定體驗。當您在 [Launch Wizard 主控台](https://console.aws.amazon.com/launchwizard)上選取透過 Application Insights 設定監控和洞察的選項時，CloudWatch Application Insights 會在 CloudWatch 上自動設定相關指標、日誌和警示，並開始監控新部署的工作負載。您可以在 CloudWatch 主控台上檢視自動化洞見和偵測到的問題，以及 SQL Server HA 工作負載的運作狀態。

**Topics**
+ [功能](#appinsights-features)
+ [概念](#appinsights-concepts)
+ [定價](#appinsights-pricing)
+ [相關服務](#appinsights-related-services)
+ [支援的應用程式元件](#appinsights-components)
+ [支援的技術堆疊](#appinsights-stack)

## 功能
<a name="appinsights-features"></a>

Application Insights 提供以下功能。

**自動設定應用程式資源監控**  
CloudWatch Application Insights 可減少為您應用程式設定監控所需要的時間。其執行作業的方式是掃描應用程式資源、提供建議指標和日誌的可自訂清單，並在 CloudWatch 中設定他們以提供應用程式資源的必要可見度，例如 Amazon EC2 與 Elastic Load Balancer (ELB)。它還會對監控的指標設定動態警示。警示會根據兩週前偵測到的異常自動更新。

**問題偵測和通知**  
CloudWatch Application Insights 會偵測應用程式潛在問題的跡象，例如指標異常和日誌錯誤。它會建立這些觀察的關聯，以顯示應用程式的潛在問題。然後產生 CloudWatch Events，[可設定為接收通知或採取動作](appinsights-cloudwatch-events.md)。這可讓您不必建立指標或日誌錯誤的個別警示。此外，還可以[設定 Amazon SNS 通知](appinsights-problem-notifications.md)，以接收偵測到問題的提醒。

**疑難排解**  
CloudWatch Application Insights 會為偵測到的問題建立 CloudWatch 自動儀表板。此儀表板會顯示問題的詳細資訊，包括相關聯的指標異常和日誌錯誤，以利故障診斷。它們也會提供額外的洞見，指出異常和錯誤的可能根本原因。

## 概念
<a name="appinsights-concepts"></a>

以下是了解 Application Insights 如何監控應用程式的重要概念。

**元件**  
構成應用程式的自動分組、獨立或自訂分組的類似資源。我們建議將類似的資源分組為自訂的元件，以利監控。

**觀察**  
偵測到的應用程式或應用程式資源個別事件 (指標異常、日誌錯誤或例外狀況)。

**問題**  
透過建立關聯、分類和分組相關觀察偵測到問題。

如需 CloudWatch Application Insights 的其他重要概念定義，請參閱 [Amazon CloudWatch 概念](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html)。

## 定價
<a name="appinsights-pricing"></a>

CloudWatch Application Insights 會針對所選應用程式資源設定建議的指標和日誌，使用 CloudWatch 指標、CloudWatch Logs 和 CloudWatch Events，在偵測到問題時發送通知。這些功能會根據 [CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing)向 AWS 您的帳戶收費。針對偵測到的問題，Application Insights 也會建立 [SSM OpsItems](https://docs.aws.amazon.com/systems-manager/latest/userguide/OpsCenter-working-with-OpsItems.html)，以通知您有關問題。此外，Application Insights 還會建立 [SSM Parameter Store 參數](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html)，以在執行個體上設定 CloudWatch 代理程式。Amazon EC2 Systems Manager 功能是根據 [SSM 定價](https://aws.amazon.com/systems-manager/pricing/)收費。設定協助、監控、資料分析或問題偵測不收取費用。

### CloudWatch Application Insights 的成本
<a name="appinsights-pricing-ec2"></a>

Amazon EC2 的成本包含下列功能的使用情況：
+ CloudWatch 代理程式
  + CloudWatch 代理程式日誌群組
  + CloudWatch 代理程式指標
  + Prometheus 日誌群組 (適用於 JMX 工作負載)

所有資源的成本包括以下功能的使用：
+ CloudWatch 警示 (大部分成本)
+ SSM OpsItem (最低成本)

### 成本計算範例
<a name="appinsights-pricing-example"></a>

在這個範例中的成本根據下列情況來計算。

您建立了包含下列項目的資源群組：
+ 一個安裝了 SQL Server 的 Amazon EC2 執行個體。
+ 連接了 Amazon EBS 磁碟區。

當您使用 CloudWatch Application Insights 加入此資源群組時，會偵測到安裝在 Amazon EC2 執行個體上的 SQL Server 工作負載。CloudWatch Application Insights 會開始監控以下指標。

針對 SQL Server 執行個體，監控以下指標：
+ CPUUtilization
+ StatusCheckFailed
+ 記憶體 % 使用中的認可位元組
+ 記憶體可用的 MB 數
+ 網路介面位元組總數/秒
+ 分頁檔用量 %
+ 實體磁碟 % 磁碟時間
+ 處理器 % 處理器時間
+ SQLServer:Buffer Manager 快取命中率
+ SQLServer:Buffer Manager 預期壽命
+ SQLServer:General Statistics Processes blocked
+ SQLServer：一般統計資料使用者連線
+ SQLServer：鎖定死鎖數目/秒
+ SQLServer:SQL Statistics 每秒批次要求數
+ 系統處理器佇列長度

針對連接到 SQL Server 執行個體的磁碟區，監控以下指標：
+ VolumeReadBytes
+ VolumeWriteBytes
+ VolumeReadOps
+ VolumeWriteOps
+ VolumeTotalReadTime
+ VolumeTotalWriteTime
+ VolumeIdleTime
+ VolumeQueueLength
+ VolumeThroughputPercentage
+ VolumeConsumedReadWriteOps
+ BurstBalance

在這個案例中，成本是根據 [CloudWatch 定價](https://aws.amazon.com/cloudwatch/pricing/)頁面和 [SSM 定價](https://aws.amazon.com/systems-manager/pricing/)頁面來計算：
+ **自訂指標**

  在此案例中，上述指標有 13 個指標會使用 CloudWatch 代理程式發射至 CloudWatch。這些指標會被視為自訂指標。每個自訂指標的費用為每月 0.3 USD。這些自訂指標的總費用為 13 \$1 0.3 USD = 每月 3.90 USD。
+ **警示**

  在此案例中，CloudWatch Application Insights 總共監控 26 個指標，進而產生 26 個警示。每個警示的費用為每月 0.1 USD。警示的總費用為 26 \$1 0.1 USD = 每月 2.60 USD。
+ **資料擷取和錯誤日誌**

  資料擷取的成本為每 GB 0.05 USD，而 SQL Server 錯誤日誌的儲存費用為每 GB 0.03 USD。資料擷取和錯誤日誌的總成本為每 GB 0.05 USD \$1 每 GB 0.03 USD = 每 GB 0.08 USD。
+ **Amazon EC2 Systems Manager OpsItem**

  系統會針對每個被 CloudWatch Application Insights 偵測到的問題建立 SSM OpsItem。如果您的應用程式中有 *n* 個問題，總成本為每月 0.00267 USD \$1 *n*。

## 相關服務
<a name="appinsights-related-services"></a>

以下服務與 CloudWatch Application Insights 一起使用：

**相關 AWS 服務**
+ **Amazon CloudWatch** 可讓您全面了解系統的資源使用率、應用程式效能和運作狀態。它會收集並追蹤指標、傳送警示通知、根據您定義的規則自動更新正在監控的資源，並可讓您監控自己的自訂指標。CloudWatch Application Insights 透過 CloudWatch 啟動，特別是在 CloudWatch 預設的操作儀表板內。如需更多資訊，請參閱 [https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/WhatIsCloudWatch.html)。
+ **CloudWatch Container Insights** 會從您的容器化應用程式和微型服務收集、彙總及總結指標和日誌。您可以使用 Container Insights 來監控 Amazon ECS、Amazon Elastic Kubernetes Service 和 Amazon EC2 上的 Kubernetes 平台。Application Insights 在 Container Insights 或 Application Insights 主控台上啟用時，Application Insights 會在 Container Insights 儀表板上顯示偵測到的問題。如需詳細資訊，請參閱 [Container Insights](ContainerInsights.md)。
+ **Amazon DynamoDB** 是全受管的 NoSQL 資料庫服務，可讓您卸下操作及擴展分散式資料庫的管理負擔，不再需要煩惱硬體佈建、設定和組態、複寫、軟體修補或叢集擴展。DynamoDB 還提供靜態加密，解決了保護敏感資料所涉及的操作負擔和複雜性。
+ **Amazon EC2 **在 AWS 雲端中提供可擴展的運算容量。您可使用 Amazon EC2 按需要啟動任意數量的虛擬伺服器，設定安全性和聯網功能以及管理儲存。您可以擴展與縮減規模，以處理需求或熱門峰值的變更，從而降低您預測流量的需求。如需詳細資訊，請參閱 [https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/concepts.html)或 [https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/concepts.html](https://docs.aws.amazon.com/AWSEC2/latest/WindowsGuide/concepts.html)。
+ **Amazon Elastic Block Store (Amazon EBS)** 提供區塊層級儲存體磁碟區，可搭配使用 Amazon EC2 執行個體。Amazon EBS 磁碟區的行為與未格式化的原始區塊型儲存設備相似。您可以將這些磁碟區作為裝置，掛載在您的執行個體上。連接至執行個體的 Amazon EBS 磁碟區將顯示為儲存體磁碟區，其可永久保留，不受執行個體的壽命影響。您可以在這些磁碟區上建立檔案系統，或利用您使用區塊型儲存裝置 (例如硬碟) 的任何方式來使用它們。您可以動態變更連接到執行個體的磁碟區組態。如需詳細資訊，請參閱 [Amazon EBS 使用者指南](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEBS.html)。
+ **Amazon EC2 Auto Scaling** 能確保您有正確的 EC2 執行個體數量可處理應用程式的負載。如需詳細資訊，請參閱 [https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html](https://docs.aws.amazon.com/autoscaling/ec2/userguide/what-is-amazon-ec2-auto-scaling.html)。
+ **Elastic Load Balancing **會將傳入的應用程式或網路流量分配到多個可用區域的多個目標，例如 EC2 執行個體、容器和 IP 地址。如需詳細資訊，請參閱《[https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/what-is-load-balancing.html](https://docs.aws.amazon.com/elasticloadbalancing/latest/userguide/what-is-load-balancing.html)》。
+ **IAM **是一種 Web 服務，可協助您安全地控制使用者對 AWS 資源的存取。使用 IAM 控制誰可以使用您的 AWS 資源 （身分驗證），以及控制他們可以使用的資源，以及他們可以如何使用它們 （授權）。如需詳細資訊，請參閱 [Amazon CloudWatch 身分驗證與存取控制](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/auth-and-access-control-cw.html)。
+ **AWS Lambda** 可讓您建置由 事件觸發的函數組成的無伺服器應用程式，並使用 CodePipeline 和 AWS CodeBuild 自動部署它們。如需詳細資訊，請參閱 [AWS Lambda 應用程式](https://docs.aws.amazon.com/lambda/latest/dg/deploying-lambda-apps.html)。
+ **AWS Launch Wizard for SQL Server** 可減少將 SQL Server 高可用性解決方案部署到雲端所需的時間。您可以在服務主控台輸入應用程式需求，包括效能、節點數量和連線能力，並 AWS Launch Wizard 識別部署和執行 SQL Server Always On 應用程式的適當 AWS 資源。
+ **AWS 資源群組**可協助您組織組成應用程式的資源。使用 Resource Groups，您可以一次管理和自動化大量資源的任務。一個應用程式只能註冊一個資源群組。如需詳細資訊，請參閱[https://docs.aws.amazon.com/ARG/latest/userguide/welcome.html](https://docs.aws.amazon.com/ARG/latest/userguide/welcome.html)。
+ **Amazon SQS** 提供安全、耐用且可用的託管佇列，可讓您整合與分離分散式軟體系統和元件。如需詳細資訊，請參閱 [https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html](https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html)。
+ **AWS Step Functions** 是一種無伺服器函數編寫器，可讓您將各種 AWS 服務和資源，包括 AWS Lambda 函數，排序為結構化的視覺化工作流程。如需詳細資訊，請參閱[「AWS Step Functions 使用者指南」](https://docs.aws.amazon.com/step-functions/latest/dg/welcome.html)。
+ **AWS SSM OpsCenter **彙總和標準化跨服務的 OpsItems，同時提供每個 OpsItem、相關 OpsItems 和相關資源的情境式調查資料。OpsCenter 也提供可用來快速解決問題的 Systems Manager Automation 文件 (Runbook)。您可以為每個 OpsItem 指定可搜尋的自訂資料。您也可以依狀態和來源，檢視自動產生的 OpsItem 摘要報告。如需詳細資訊，請參閱《[AWS Systems Manager 使用者指南》**](https://docs.aws.amazon.com/systems-manager/latest/userguide/OpsCenter.html)。
+ **Amazon API Gateway** 是一項 AWS 服務，用於建立、發佈、維護、監控和保護任何規模的 REST、HTTP 和 WebSocket APIs。API 開發人員可以建立 APIs 來存取 AWS 或其他 Web 服務，以及存放在 AWS 雲端的資料。如需詳細資訊，請參閱[《Amazon API Gateway 使用者指南](https://docs.aws.amazon.com/apigateway/latest/developerguide/welcome.html)。
**注意**  
Application Insights 僅支援 REST API 通訊協定 (API Gateway 服務的第 1 版)。
+ **Amazon Elastic Container Service (Amazon ECS)** 是全受管容器協同運作服務。您可以使用 Amazon ECS 執行最敏感和任務關鍵型應用程式。如需詳細資訊，請參閱《[Amazon Elastic Container Service 開發人員指南》](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/Welcome.html)。
+ **Amazon Elastic Kubernetes Service (Amazon EKS)** 是一項受管服務，可讓您在 上執行 Kubernetes， AWS 而無需安裝、操作和維護您自己的 Kubernetes 控制平面或節點。Kubernetes 是一套開放原始碼系統，用於容器化應用程式的自動化部署、擴展與管理。如需詳細資訊，請參閱[《Amazon EKS 使用者指南》](https://docs.aws.amazon.com/eks/latest/userguide/what-is-eks.html)。
+ **Amazon EC2 上的 Kubernetes**。Kubernetes 是開放原始碼軟體，可協助您大規模部署及管理容器化應用程式。Kubernetes 可管理 Amazon EC2 運算執行個體的叢集，並在這些執行個體上執行容器，其中包含部署、維護和擴展程序。藉助 Kubernetes，您可以在內部部署和雲端使用相同的工具集來執行各種類型的容器化應用程式。如需詳細資訊，請參閱 [Kubernetes 文件：入門](https://kubernetes.io/docs/setup/)。
+ **Amazon FSx** 可協助您啟動和執行由 AWS全受管的熱門檔案系統。使用 Amazon FSx，您可以利用常見的開放原始碼和商業授權檔案系統的功能集與效能，從而避免費時的管理任務。如需詳細資訊，請參閱 [Amazon FSx 說明文件](https://docs.aws.amazon.com/fsx/)。
+ **Amazon Simple Notification Service (SNS)** 是一項全受管簡訊服務，適用於應用程式對應用程式和應用程式對人的通訊。您可以設定 Amazon SNS 以透過 Application Insights 進行監控。當 Amazon SNS 設定為用於監控的資源時，Application Insights 會追蹤 SNS 指標，以協助判斷 SNS 訊息可能會遇到問題或失敗的原因。
+ **Amazon Elastic File System (Amazon EFS)** 是一種全受管的彈性 NFS 檔案系統，可與 AWS 雲端 服務和內部部署資源搭配使用。該系統建置為可根據需求擴展到 PB 級，而不會中斷應用程式。儲存容量會在您新增和移除的檔案時自動擴展和縮減，讓您無需佈建和管理容量以配合擴展。如需詳細資訊，請參閱 [Amazon Elastic File System 文件](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AmazonEFS.html)。

**相關第三方服務**
+ 對於 Application Insights 中監控的某些工作負載和應用程式，**Prometheus JMX exporter** 使用 AWS Systems Manager Distributor 進行安裝，以便 CloudWatch Application Insights 能夠擷取 Java 特定的指標。當您選擇監控 Java 應用程式時，Application Insights 會自動為您安裝 Prometheus JMX Exporter。

## 支援的應用程式元件
<a name="appinsights-components"></a>

CloudWatch Application Insights 會掃描您的資源群組，以識別應用程式元件。元件可為獨立、自動分組 (例如 Auto Scaling 群組中或負載平衡器後端的執行個體) 或自訂 (將個別的 Amazon EC2 執行個體集合在一起)。

CloudWatch Application Insights 支援以下元件：

**AWS 元件**
+ Amazon EC2
+ Amazon EBS
+ Amazon RDS
+ Elastic Load Balancing：Application Load Balancer 和 Classic Load Balancer (這些負載平衡器的所有目標執行個體都會予以識別並設定)。
+ Amazon EC2 Auto Scaling 群組： AWS Auto Scaling （針對所有目標執行個體動態設定 Auto Scaling 群組；如果您的應用程式擴展，CloudWatch Application Insights 會自動設定新的執行個體）。Auto Scaling 群組不支援以 CloudFormation 堆疊為基礎的資源群組。
+ AWS Lambda
+ Amazon Simple Queue Service (Amazon SQS)
+ Amazon DynamoDB 資料表
+ Amazon S3 儲存貯體指標
+ AWS Step Functions
+ Amazon API Gateway REST API 階段
+ Amazon Elastic Container Service (Amazon ECS)：叢集、服務和任務
+ Amazon Elastic Kubernetes Service (Amazon EKS)：叢集
+ Amazon EC2 上的 Kubernetes：在 EC2 上執行的 Kubernetes 叢集
+ Amazon SNS 主題

CloudWatch Application Insights 目前不會追蹤任何其他元件類型資源。如果您的 Application Insights 應用程式不顯示支援的元件類型，此元件可能已註冊，並由 Application Insights 監控的您其他應用程式所管理。

## 支援的技術堆疊
<a name="appinsights-stack"></a>

您可以使用 CloudWatch Application Insights 來監控在 Windows Server 和 Linux 作業系統上執行的應用程式，方法是選取下列其中一項技術的應用程式層的下拉式功能表選項：
+ 前端：Microsoft Internet Information Services (IIS) Web 伺服器
+ 工作者層：
  + .NET Framework 
  + .NET Core
+ 應用程式：
  + Java
  + SAP NetWeaver 標準、分散式和高可用性部署
+ Active Directory
+ SharePoint
+ 資料庫：
  + 在 Amazon RDS 或 Amazon EC2 上執行的 Microsoft SQL Server (包括 SQL Server 高可用性組態。請參閱「[元件組態範例](component-configuration-examples.md)」)。
  + 在 Amazon RDS、Amazon Aurora 或 Amazon EC2 上執行的 MySQL
  + 在 Amazon RDS 或 Amazon EC2 上執行的 PostgreSQL
  + Amazon DynamoDB 資料表
  + 在 Amazon RDS 或 Amazon EC2 上執行的 Oracle
  + 在單一 Amazon EC2 執行個體和多個 EC2 執行個體上的 SAP HANA 資料庫
  + 跨可用區域 SAP HANA 資料庫高可用性設定。
  + 單一 Amazon EC2 執行個體上的 SAP Sybase ASE 資料庫
  + 跨可用區域 SAP Sybase ASE 資料庫高可用性設定

如果上面列出的任何技術堆疊都不適用於您的應用程式資源，您可以從 **Manage monitoring** (管理監控) 頁面上的應用程式層下拉式功能表中選擇 **Custom** (自訂)，進而監控您的應用程式堆疊。

# Amazon CloudWatch Application Insights 的運作方式
<a name="appinsights-how-works"></a>

CloudWatch Application Insights 可監控應用程式資源。以下資訊可說明 Application Insights 的運作方式。

**Topics**
+ [Application Insights 如何監控應用程式](#appinsights-how-works-sub)
+ [資料保留](#appinsights-retention)
+ [配額](#appinsights-limits)
+ [AWS CloudWatch Application Insights 使用的 Systems Manager (SSM) 套件](appinsights-ssm-packages.md)
+ [AWS CloudWatch Application Insights 使用的 Systems Manager (SSM) 文件](appinsights-ssm-documents.md)

## Application Insights 如何監控應用程式
<a name="appinsights-how-works-sub"></a>

以下資訊可說明 Application Insights 如何監控應用程式。

**Application Discovery 和組態**  
第一次在 CloudWatch Application Insights 中新增應用程式時會掃描應用程式元件，建議監控應用程式的關鍵指標、日誌和其他資料來源。然後，您就可以根據這些建議來設定您的應用程式。

**資料預先處理**  
CloudWatch Application Insights 持續分析在各應用程式資源中受監控的資料來源，以探索指標異常和日誌錯誤 (觀察)。

**智慧型問題偵測**  
CloudWatch Application Insights 引擎使用分類演算法和內建規則建立觀察的關聯，以偵測應用程式中的問題。為協助故障診斷，它會建立包含問題情境資訊的自動化 CloudWatch 儀表板。

**提醒和動作**  
當 CloudWatch Application Insights 偵測到應用程式的問題時，會產生 CloudWatch Events 來通知您該問題。如需如何設定這些事件的詳細資訊，請參閱 [偵測到的問題的 Application Insights CloudWatch Events](appinsights-cloudwatch-events.md)。此外，還可以[設定 Amazon SNS 通知](appinsights-problem-notifications.md)，以接收偵測到問題的提醒。

**範例藍本**

您有 SQL Server 資料庫支援的 ASP .NET 應用程式。突然間，您的資料庫因記憶體高壓開始故障。這可能會導致應用程式效能降級，而且 Web 伺服器和負載平衡器可能發生 HTTP 500 錯誤。

使用 CloudWatch Application Insights 及其智慧型分析，您可以檢查顯示相關指標和日誌檔程式碼片段的動態建立儀表板，找出造成問題的應用程式層。在本例中，問題可能發生在 SQL 資料庫 layer。

## 資料保留
<a name="appinsights-retention"></a>

CloudWatch Application Insights 會將問題保留 55 天，觀察保留 60 天。

## 配額
<a name="appinsights-limits"></a>

如需 CloudWatch Application Insights 的預設配額，請參閱 [Amazon CloudWatch Application Insights 端點和配額](https://docs.aws.amazon.com/general/latest/gr/applicationinsights.html)。除非另有說明，否則每個配額都是每個 AWS 區域。請聯絡 [AWS Support](https://console.aws.amazon.com/support/home#/case/create?issueType=technical) 請求提高您的服務配額。許多服務包含的配額無法變更。如需有關特定服務的配額詳細資訊，請參閱該服務的文件。

# AWS CloudWatch Application Insights 使用的 Systems Manager (SSM) 套件
<a name="appinsights-ssm-packages"></a>

本節中列出的套件由 Application Insights 使用，並且可以透過 AWS Systems Manager Distributor 獨立管理和部署。如需 SSM Distributor 的詳細資訊，請參閱*《AWS Systems Manager 使用者指南》*中的 [AWS Systems Manager Distributor](https://docs.aws.amazon.com/systems-manager/latest/userguide/distributor.html)。

**Topics**
+ [`AWSObservabilityExporter-JMXExporterInstallAndConfigure`](#configure-java)
+ [`AWSObservabilityExporter-SAP-HANADBExporterInstallAndConfigure`](#appinsights-ssm-sap-prometheus)
+ [`AWSObservabilityExporter-HAClusterExporterInstallAndConfigure`](#appinsights-ssm-sap-prometheus-ha)
+ [`AWSObservabilityExporter-SAP-SAPHostExporterInstallAndConfigure`](#appinsights-ssm-sap-host-exporter)
+ [`AWSObservabilityExporter-SQLExporterInstallAndConfigure`](#appinsights-ssm-sql-prometheus)

## `AWSObservabilityExporter-JMXExporterInstallAndConfigure`
<a name="configure-java"></a>

您可以從 [Prometheus JMX Exporter](https://prometheus.io/docs/instrumenting/exporters/#third-party-exporters) 為 Application Insights 擷取工作負載特定的 Java 指標，進而設定和監控警示。在 Application Insights 主控台的 **Manage monitoring** (管理監控) 頁面，從 **Application tier** (應用程式層) 下拉式清單選取 **JAVA 應用程式**。然後，在 **JAVA Prometheus exporter configuration** (JAVA Prometheus 匯出程式組態) 下，選擇 **Collection method** (集合方法) 和 **JMX port number** (JMX 連接埠號碼)。

若要使用 [AWS Systems Manager Distributor](https://docs.aws.amazon.com/systems-manager/latest/userguide/distributor.html) 來封裝、安裝和設定獨立於 Application Insights AWS提供的 Prometheus JMX 匯出工具套件，請完成以下步驟。

**使用 Prometheus JMX Exporter SSM 套件的先決條件**
+ 已安裝 SSM agent 2.3.1550.0 版或更新版本
+ 已設定 JAVA\$1HOME 環境變數

**安裝和設定 `AWSObservabilityExporter-JMXExporterInstallAndConfigure` 套件**  
`AWSObservabilityExporter-JMXExporterInstallAndConfigure` 封裝是一種 SSM Distributor 套件，您可將其用於安裝和設定 [Prometheus JMX Exporter](https://github.com/prometheus/jmx_exporter)。當 Java 指標由 Prometheus JMX Exporter 傳送時，您可以設定 CloudWatch 代理程式來擷取 CloudWatch 服務的指標。

1. 根據您的偏好設定，在 Prometheus GitHub 儲存庫中準備 [Prometheus JMX Exporter YAML 組態檔案](https://github.com/prometheus/jmx_exporter#configuration)。使用範例組態和選項描述來引導您。

1. 將編碼為 Base64 的 Prometheus JMX Exporter YAML 組態檔案複製到 [SSM 參數存放區](https://console.aws.amazon.com/systems-manager/parameters)中的新 SSM 參數。

1. 導覽至 [SSM Distributor](https://console.aws.amazon.com/systems-manager/distributor) 主控台，並開啟 **Owned by Amazon** (由 Amazon 擁有) 索引標籤。選取 **AWSObservabilityExporter-JMXExporterInstallAndConfigure** 並選擇 **Install one time** (一次性安裝)。

1. 以下列方式取代「其他引數」，更新您在第一個步驟中建立的 SSM 參數：

   ```
   {
     "SSM_EXPORTER_CONFIGURATION": "{{ssm:<SSM_PARAMETER_STORE_NAME>}}",
     "SSM_EXPOSITION_PORT": "9404"
   }
   ```
**注意**  
連接埠 9404 是用來傳送 Prometheus JMX 指標的預設連接埠。您可以更新此連接埠。

**範例：設定 CloudWatch 代理程式以擷取 Java 指標**

1. 安裝 Prometheus JMX Exporter，如上列程序所述。然後透過檢查連接埠狀態來驗證它是否正確安裝在您的執行個體上。

   在 Windows 執行個體上成功安裝範例

   ```
   PS C:\> curl http://localhost:9404 (http://localhost:9404/)
   StatusCode : 200
   StatusDescription : OK
   Content : # HELP jvm_info JVM version info
   ```

   在 Linux 執行個體上成功安裝範例

   ```
   $ curl localhost:9404
   # HELP jmx_config_reload_failure_total Number of times configuration have failed to be reloaded.
   # TYPE jmx_config_reload_failure_total counter
   jmx_config_reload_failure_total 0.0
   ```

1. 建立 Prometheus 服務探索 YAML 檔案。下列範例服務探索檔案會執行下列操作：
   + 將 Prometheus JMX Exporter 主機連接埠指定為 `localhost: 9404`。
   + 將標籤 (`Application`、`ComponentName` 以及 `InstanceId`) 連接至指標，其中這些指標可設定為 CloudWatch 指標維度。

   ```
   $ cat prometheus_sd_jmx.yaml 
   - targets:
     - 127.0.0.1:9404
     labels:
       Application: myApp
       ComponentName: arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/sampl-Appli-MMZW8E3GH4H2/aac36d7fea2a6e5b
       InstanceId: i-12345678901234567
   ```

1. 建立 Prometheus JMX Exporter 組態 YAML 檔案。以下範例組態檔案會記錄以下內容：
   + 指標擷取任務間隔和逾時期間。
   + 指標擷取任務 (`jmx` 和 `sap`)，也稱為抓取，其中包括任務名稱、一次傳回的時間序列上限，以及服務探索檔案路徑。

   ```
   $ cat prometheus.yaml 
   global:
     scrape_interval: 1m
     scrape_timeout: 10s
   scrape_configs:
     - job_name: jmx
       sample_limit: 10000
       file_sd_configs:
         - files: ["/tmp/prometheus_sd_jmx.yaml"]
     - job_name: sap
       sample_limit: 10000
       file_sd_configs:
         - files: ["/tmp/prometheus_sd_sap.yaml"]
   ```

1. 確認您的 Amazon EC2 執行個體上已安裝 CloudWatch 代理程式，且版本為 1.247346.1b249759 或更新版本。若要在您的 EC2 執行個體上安裝 CloudWatch 代理程式，請參閱[安裝 CloudWatch 代理程式](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/install-CloudWatch-Agent-on-EC2-Instance.html)。若要確認版本，請參閱[尋找 CloudWatch 代理程式版本的相關資訊](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/troubleshooting-CloudWatch-Agent.html#CloudWatch-Agent-troubleshooting-agent-version)。

1. 設定 CloudWatch 代理程式。如需如何設定 CloudWatch 代理程式組態檔案的詳細資訊，請參閱[手動建立或編輯 CloudWatch 代理程式組態檔案](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html)。下列 CloudWatch 代理程式組態檔案範例會執行下列操作：
   + 指定 Prometheus JMX Exporter 組態 YAML 檔案路徑。
   + 指定要發布 EMF 指標日誌的目標日誌群組。
   + 為每個指標名稱指定兩組維度。
   + 傳送 8 個 (4 個指標名稱 \$1 每個指標名稱 2 組維度) CloudWatch 指標。

   ```
   {
      "logs":{
         "logs_collected":{
            ....
         },
         "metrics_collected":{
            "prometheus":{
               "cluster_name":"prometheus-test-cluster",
               "log_group_name":"prometheus-test",
               "prometheus_config_path":"/tmp/prometheus.yaml",
               "emf_processor":{
                  "metric_declaration_dedup":true,
                  "metric_namespace":"CWAgent",
                  "metric_unit":{
                     "jvm_threads_current":"Count",
                     "jvm_gc_collection_seconds_sum":"Second",
                     "jvm_memory_bytes_used":"Bytes"
                  },
                  "metric_declaration":[
                     {
                        "source_labels":[
                           "job"
                        ],
                        "label_matcher":"^jmx$",
                        "dimensions":[
                           [
                              "InstanceId",
                              "ComponentName"
                           ],
                           [
                              "ComponentName"
                           ]
                        ],
                        "metric_selectors":[
                           "^java_lang_threading_threadcount$",
                           "^java_lang_memory_heapmemoryusage_used$",
                           "^java_lang_memory_heapmemoryusage_committed$"
                        ]
                     }
                  ]
               }
            }
         }
      },
      "metrics":{
         ....
      }
   }
   ```

## `AWSObservabilityExporter-SAP-HANADBExporterInstallAndConfigure`
<a name="appinsights-ssm-sap-prometheus"></a>

您可以從 [Prometheus HANA 資料庫匯出工具](https://prometheus.io/docs/instrumenting/exporters/#third-party-exporters)為 Application Insights 擷取工作負載特定的 SAP HANA 指標，進而設定和監控警示。如需詳細資訊，請參閱本指南中的 [設定您的 SAP HANA 資料庫以進行監控](appinsights-tutorial-sap-hana.md#appinsights-tutorial-sap-hana-set-up)。

若要使用 [AWS Systems Manager Distributor](https://docs.aws.amazon.com/systems-manager/latest/userguide/distributor.html) 來封裝、安裝和設定獨立於 Application Insights AWS提供的 Prometheus HANA 資料庫匯出工具套件，請完成下列步驟。

**使用 Prometheus HANA 資料庫匯出工具 SSM 套件的先決條件**
+ 已安裝 SSM agent 2.3.1550.0 版或更新版本
+ SAP HANA 資料庫
+ Linux 作業系統 (SUSE Linux、RedHat Linux)
+ 具有 SAP HANA 資料庫監控憑證的機密，使用 AWS Secrets Manager。使用索引鍵/值配對格式建立機密、指定金鑰使用者名稱，然後輸入值的資料庫使用者。新增第二個金鑰密碼，然後針對值輸入密碼。如需建立機密的詳細資訊，請參閱《*AWS Secrets Manager 使用者指南*》中的[建立機密](https://docs.aws.amazon.com/secretsmanager/latest/userguide/manage_create-basic-secret.html)。機密的格式必須如下：

  ```
  {
    "username": "<database_user>",
    "password": "<database_password>"
  }
  ```

**安裝和設定 `AWSObservabilityExporter-SAP-HANADBExporterInstallAndConfigure` 套件**  
`AWSObservabilityExporter-SAP-HANADBExporterInstallAndConfigure` 封裝是一種 SSM Distributor 套件，您可將其用於安裝和設定 [Prometheus HANA 資料庫匯出工具](https://github.com/prometheus/jmx_exporter)。當 HANA 資料庫指標由 Prometheus HANA 資料庫匯出工具傳送時，您可以設定 CloudWatch 代理程式來擷取 CloudWatch 服務的指標。

1. 在 [SSM 參數存放區](https://console.aws.amazon.com/systems-manager/parameters)中建立 SSM 參數，以存放匯出工具組態。以下是範例參數值。

   ```
   {\"exposition_port\":9668,\"multi_tenant\":true,\"timeout\":600,\"hana\":{\"host\":\"localhost\",\"port\":30013,\"aws_secret_name\":\"HANA_DB_CREDS\",\"scale_out_mode\":true}}
   ```
**注意**  
在此範例中，匯出僅在具有作用中 `SYSTEM` 資料庫的 Amazon EC2 執行個體上執行，並且其將在其他 EC2 執行個體上保持閒置狀態，以避免重複指標。匯出工具可以從 `SYSTEM` 資料庫擷取所有資料庫租用戶資訊。

1. 在 [SSM 參數存放區](https://console.aws.amazon.com/systems-manager/parameters)中建立 SSM 參數，以存放匯出工具指標查詢。套件可以接受多個指標參數。每個參數都必須具有有效的 JSON 物件格式。以下是範例參數值：

   ```
   {\"SELECT MAX(TIMESTAMP) TIMESTAMP, HOST, MEASURED_ELEMENT_NAME CORE, SUM(MAP(CAPTION, 'User Time', TO_NUMBER(VALUE), 0)) USER_PCT, SUM(MAP(CAPTION, 'System Time', TO_NUMBER(VALUE), 0)) SYSTEM_PCT, SUM(MAP(CAPTION, 'Wait Time', TO_NUMBER(VALUE), 0)) WAITIO_PCT, SUM(MAP(CAPTION, 'Idle Time', 0, TO_NUMBER(VALUE))) BUSY_PCT, SUM(MAP(CAPTION, 'Idle Time', TO_NUMBER(VALUE), 0)) IDLE_PCT FROM sys.M_HOST_AGENT_METRICS WHERE MEASURED_ELEMENT_TYPE = 'Processor' GROUP BY HOST, MEASURED_ELEMENT_NAME;\":{\"enabled\":true,\"metrics\":[{\"name\":\"hanadb_cpu_user\",\"description\":\"Percentage of CPU time spent by HANA DB in user space, over the last minute (in seconds)\",\"labels\":[\"HOST\",\"CORE\"],\"value\":\"USER_PCT\",\"unit\":\"percent\",\"type\":\"gauge\"},{\"name\":\"hanadb_cpu_system\",\"description\":\"Percentage of CPU time spent by HANA DB in Kernel space, over the last minute (in seconds)\",\"labels\":[\"HOST\",\"CORE\"],\"value\":\"SYSTEM_PCT\",\"unit\":\"percent\",\"type\":\"gauge\"},{\"name\":\"hanadb_cpu_waitio\",\"description\":\"Percentage of CPU time spent by HANA DB in IO mode, over the last minute (in seconds)\",\"labels\":[\"HOST\",\"CORE\"],\"value\":\"WAITIO_PCT\",\"unit\":\"percent\",\"type\":\"gauge\"},{\"name\":\"hanadb_cpu_busy\",\"description\":\"Percentage of CPU time spent by HANA DB, over the last minute (in seconds)\",\"labels\":[\"HOST\",\"CORE\"],\"value\":\"BUSY_PCT\",\"unit\":\"percent\",\"type\":\"gauge\"},{\"name\":\"hanadb_cpu_idle\",\"description\":\"Percentage of CPU time not spent by HANA DB, over the last minute (in seconds)\",\"labels\":[\"HOST\",\"CORE\"],\"value\":\"IDLE_PCT\",\"unit\":\"percent\",\"type\":\"gauge\"}]}}
   ```

   如需指標查詢的詳細資訊，請參閱 GitHub 上的 [https://github.com/SUSE/hanadb_exporter/blob/master/metrics.json](https://github.com/SUSE/hanadb_exporter/blob/master/metrics.json) 儲存庫。

1. 導覽至 [SSM Distributor](https://console.aws.amazon.com/systems-manager/distributor) 主控台，並開啟 **Owned by Amazon** (由 Amazon 擁有) 索引標籤。選取 **AWSObservabilityExporter-SAP-HANADBExporterInstallAndConfigure\$1**，然後選擇 **Install one time** (一次性安裝)。

1. 以下列方式取代「其他引數」，更新您在第一個步驟中建立的 SSM 參數：

   ```
   {
     "SSM_EXPORTER_CONFIG": "{{ssm:<*SSM_CONFIGURATIONS_PARAMETER_STORE_NAME>*}}",
     "SSM_SID": "<SAP_DATABASE_SID>",
     "SSM_EXPORTER_METRICS_1": "{{ssm:<SSM_FIRST_METRICS_PARAMETER_STORE_NAME>}}",
     "SSM_EXPORTER_METRICS_2": "{{ssm:<SSM_SECOND_METRICS_PARAMETER_STORE_NAME>}}"
   }
   ```

1. 選取具有 SAP HANA 資料庫的 Amazon EC2 執行個體，然後選擇 **Run** (執行)。

## `AWSObservabilityExporter-HAClusterExporterInstallAndConfigure`
<a name="appinsights-ssm-sap-prometheus-ha"></a>

您可以從 [Prometheus HANA 叢集匯出工具](https://prometheus.io/docs/instrumenting/exporters/#third-party-exporters)為 Application Insights 擷取工作負載特定的高可用性 (HA) 叢集指標，進而設定和監控警示，以進行 SAP HANA 資料庫高可用性設定。如需詳細資訊，請參閱本指南中的 [設定您的 SAP HANA 資料庫以進行監控](appinsights-tutorial-sap-hana.md#appinsights-tutorial-sap-hana-set-up)。

若要使用 [AWS Systems Manager Distributor](https://docs.aws.amazon.com/systems-manager/latest/userguide/distributor.html) 來封裝、安裝和設定獨立於 Application Insights AWS提供的 Prometheus HA 叢集匯出工具套件，請完成下列步驟。

**使用 Prometheus HA 叢集匯出工具 SSM 套件的先決條件**
+ 已安裝 SSM agent 2.3.1550.0 版或更新版本
+ 適用於 Pacemaker、Corosync、SBD 和 DRBD 的 HA 叢集
+ Linux 作業系統 (SUSE Linux、RedHat Linux)

**安裝和設定 `AWSObservabilityExporter-HAClusterExporterInstallAndConfigure` 套件**  
`AWSObservabilityExporter-HAClusterExporterInstallAndConfigure` 封裝是一種 SSM Distributor 套件，您可將其用於安裝和設定 Prometheus HA Cluster Exporter。當叢集指標由 Prometheus HANA 資料庫匯出工具傳送時，您可以設定 CloudWatch 代理程式來擷取 CloudWatch 服務的指標。

1. 在 [SSM 參數存放區](https://console.aws.amazon.com/systems-manager/parameters)中建立 SSM 參數，以使用 JSON 格式存放匯出工具組態。以下是範例參數值。

   ```
   {\"port\":\"9664\",\"address\":\"0.0.0.0\",\"log-level\":\"info\",\"crm-mon-path\":\"/usr/sbin/crm_mon\",\"cibadmin-path\":\"/usr/sbin/cibadmin\",\"corosync-cfgtoolpath-path\":\"/usr/sbin/corosync-cfgtool\",\"corosync-quorumtool-path\":\"/usr/sbin/corosync-quorumtool\",\"sbd-path\":\"/usr/sbin/sbd\",\"sbd-config-path\":\"/etc/sysconfig/sbd\",\"drbdsetup-path\":\"/sbin/drbdsetup\",\"enable-timestamps\":false}
   ```

   如需匯出工具組態的詳細資訊，請參閱 GitHub 上的 [https://github.com/ClusterLabs/ha_cluster_exporter/blob/master/ha_cluster_exporter.yaml](https://github.com/ClusterLabs/ha_cluster_exporter/blob/master/ha_cluster_exporter.yaml) 儲存庫。

1. 導覽至 [SSM Distributor](https://console.aws.amazon.com/systems-manager/distributor) 主控台，並開啟 **Owned by Amazon** (由 Amazon 擁有) 索引標籤。選取 **AWSObservabilityExporter-HAClusterExporterInstallAndConfigure\$1**，然後選擇 **Install one time** (一次性安裝)。

1. 以下列方式取代「其他引數」，更新您在第一個步驟中建立的 SSM 參數：

   ```
   {
     "SSM_EXPORTER_CONFIG": "{{ssm:<*SSM_CONFIGURATIONS_PARAMETER_STORE_NAME>*}}"
   }
   ```

1. 選取具有 SAP HANA 資料庫的 Amazon EC2 執行個體，然後選擇 **Run** (執行)。

## `AWSObservabilityExporter-SAP-SAPHostExporterInstallAndConfigure`
<a name="appinsights-ssm-sap-host-exporter"></a>

您可以從 [Prometheus SAP 主機匯出程式](https://prometheus.io/docs/instrumenting/exporters/#third-party-exporters)為 Application Insights 擷取工作負載特定的 SAP NetWeaver 指標，進而為 SAP NetWeaver 分散式和高可用性部署設定並監控警示。

若要使用 [AWS Systems Manager Distributor](https://docs.aws.amazon.com/systems-manager/latest/userguide/distributor.html) 封裝、安裝和設定 SAP 主機匯出程式套件 (獨立於 Application Insights)，請完成下列步驟。

**使用 Prometheus SAP 主機匯出程式 SSM 套件的先決條件**
+ 已安裝 SSM agent 2.3.1550.0 版或更新版本
+ SAP NetWeaver 應用程式伺服器
+ Linux 作業系統 (SUSE Linux、RedHat Linux)

**安裝和設定 `AWSObservabilityExporter-SAP-SAPHostExporterInstallAndConfigure` 套件**  
`AWSObservabilityExporter-SAP-SAPHostExporterInstallAndConfigure` 套件是 SSM Distributor 套件，可用於安裝和設定 SAP NetWeaver Prometheus 指標匯出程式。如果 Prometheus 匯出程式傳送了 SAP NetWeaver 指標，您可以設定 CloudWatch 代理程式來擷取 CloudWatch 服務的指標。

1. 在 [SSM 參數存放區](https://console.aws.amazon.com/systems-manager/parameters)中建立 SSM 參數，以使用 JSON 格式存放匯出工具組態。以下是範例參數值。

   ```
   {\"address\":\"0.0.0.0\",\"port\":\"9680\",\"log-level\":\"info\",\"is-HA\":false}
   ```
   + **address**

     將 Prometheus 指標傳送到的目標地址。預設值為 `localhost`。
   + **port**

     將 Prometheus 指標傳送到的目標連接埠。預設值為 `9680`。
   + **is-HA**

     對於 SAP NetWeaver 高可用性部署，為 `true`。對於所有其他部署，為 `false`。

1. 導覽至 [SSM Distributor](https://console.aws.amazon.com/systems-manager/distributor) 主控台，並開啟 **Owned by Amazon** (由 Amazon 擁有) 索引標籤。選取 **AWSObservabilityExporter-SAP-SAPHostExporterInstallAndConfigure**，然後選擇 **Install one time** (一次安裝)。

1. 以下列方式取代「其他引數」，更新您在第一個步驟中建立的 SSM 參數：

   ```
   {
     "SSM_EXPORTER_CONFIG": "{{ssm:<SSM_CONFIGURATIONS_PARAMETER_STORE_NAME>}}",
     "SSM_SID": "<SAP_DATABASE_SID>",
     "SSM_INSTANCES_NUM": "<instances_number seperated by comma>"
   }
   ```

   **範例**

   ```
   {
     "SSM_EXPORTER_CONFIG": "{{ssm:exporter_config_paramter}}",
     "SSM_INSTANCES_NUM": "11,12,10",
     "SSM_SID": "PR1"
   }
   ```

1. 選取具有 SAP NetWeaver 應用程式的 Amazon EC2 執行個體，然後選 **Run** (執行)。

**注意**  
Prometheus 匯出程式會在本機端點上提供 SAP NetWeaver 指標。本機端點只能由 Amazon EC2 執行個體上的作業系統使用者存取。因此，在安裝匯出程式套件之後，所有作業系統使用者都可以使用這些指標。預設本機端點為 `localhost:9680/metrics`。

## `AWSObservabilityExporter-SQLExporterInstallAndConfigure`
<a name="appinsights-ssm-sql-prometheus"></a>

您可以從 [Prometheus SQL 匯出程式](https://prometheus.io/docs/instrumenting/exporters/#third-party-exporters)中為 Application Insights 擷取工作負載特定的 SQL Server 指標，進而監控關鍵指標。

若要使用 [AWS Systems Manager Distributor](https://docs.aws.amazon.com/systems-manager/latest/userguide/distributor.html) 封裝、安裝和設定 SQL 匯出程式套件 (獨立於 Application Insights)，請完成下列步驟。

**使用 Prometheus SQL Exporter SSM 套件的先決條件**
+ 已安裝 SSM agent 2.3.1550.0 版或更新版本
+ 在啟用 SQL Server 使用者身分驗證的 Windows 中執行 SQL Server 的 Amazon EC2 執行個體。
+ 具有下列許可的 SQL Server 使用者：

  ```
  GRANT VIEW ANY DEFINITION TO
  ```

  ```
  GRANT VIEW SERVER STATE TO
  ```
+ 使用 AWS Secrets Manager包含資料庫連線字串的機密。如需建立機密的詳細資訊，請參閱《*AWS Secrets Manager 使用者指南*》中的[建立機密](https://docs.aws.amazon.com/secretsmanager/latest/userguide/manage_create-basic-secret.html)。機密的格式必須如下：

  ```
  {
    "data_source_name":"sqlserver://<username>:<password>@localhost:1433"
  }
  ```
**注意**  
如果密碼或使用者名稱包含特殊字元，則必須對特殊字元進行百分比編碼，以確保資料庫連線成功。

**安裝和設定 `AWSObservabilityExporter-SQLExporterInstallAndConfigure` 套件**  
`AWSObservabilityExporter-SQLExporterInstallAndConfigure` 套件是 SSM Distributor 套件，可用於安裝和設定 SQL Prometheus 指標匯出程式。當指標由 Prometheus 匯出程式傳送時，您可以設定 CloudWatch 代理程式來擷取 CloudWatch 服務的指標。

1. 根據您的偏好設定，準備 SQL Exporter YAML 組態。下列範例組態已設定單一指標。使用[範例組態](https://github.com/burningalchemist/sql_exporter/blob/master/examples/sql_exporter.yml)以利用其他指標來更新組態或建立您自己的組態。

   ```
   ---
   global:
     scrape_timeout_offset: 500ms
     min_interval: 0s
     max_connections: 3
     max_idle_connections: 3
   target:
     aws_secret_name: <SECRET_NAME>
     collectors:
       - mssql_standard
   collectors:
     - collector_name: mssql_standard
       metrics: 
       - metric_name: mssql_batch_requests
         type: counter
         help: 'Number of command batches received.'
         values: [cntr_value]
         query: |
           SELECT cntr_value
           FROM sys.dm_os_performance_counters WITH (NOLOCK)
           WHERE counter_name = 'Batch Requests/sec'
   ```

1. 將編碼為 Base64 的 Prometheus SQL Exporter YAML 組態檔案複製到 [SSM 參數存放區](https://console.aws.amazon.com/systems-manager/parameters)中的新 SSM 參數。

1. 導覽至 [SSM Distributor](https://console.aws.amazon.com/systems-manager/distributor) 主控台，並開啟 **Owned by Amazon** (由 Amazon 擁有) 索引標籤。選取 **AWSObservabilityExporter-SQLExporterInstallAndConfigure** 並選擇**一次性安裝**。

1. 使用下列資訊取代「其他引數」。`SSM_PARAMETER_NAME` 是您在步驟 2 中建立的參數名稱。

   ```
   {
     "SSM_EXPORTER_CONFIGURATION": 
       "{{ssm:<SSM_PARAMETER_STORE_NAME>}}",
       "SSM_PROMETHEUS_PORT": "9399",
       "SSM_WORKLOAD_NAME": "SQL"                         
   }
   ```

1. 選取帶有 SQL Server 資料庫的 Amazon EC2 執行個體，然後選擇執行。

# AWS CloudWatch Application Insights 使用的 Systems Manager (SSM) 文件
<a name="appinsights-ssm-documents"></a>

Application Insights 使用本節中列出的 SSM 文件來定義 AWS Systems Manager 在受控執行個體上執行的動作。這些文件使用 Systems Manager 的 `Run Command` 功能，將執行 Application Insights 監控功能所需的任務自動化。這些文件的執行排程由 Application Insights 維護，且無法變更。

如需 SSM 文件的詳細資訊，請參閱《AWS Systems Manager 使用者指南》**中的 [AWS Systems Manager 文件](https://docs.aws.amazon.com/systems-manager/latest/userguide/documents.html)。

## CloudWatch Application Insights 管理的文件
<a name="ssm-documents-appinsights-managed"></a>

下表列出 Application Insights 管理的 SSM 文件。


| 文件名稱 | Description | 執行排程 | 
| --- | --- | --- | 
|  `AWSEC2-DetectWorkload`  |  自動偵測應用程式環境中執行的應用程式，這些應用程式可設定為由 Application Insights 監控。  |  本文件會在您的應用程式環境中每小時執行一次，以取得最新的應用程式詳細資訊。  | 
|  `AWSEC2-CheckPerformanceCounterSets`  |  檢查 Amazon EC2 Windows 執行個體是否已啟用效能計數器命名空間。  |  本文件會在您的應用程式環境中每小時執行一次，而且只有在啟用對應的命名空間時才會監控效能計數器指標。  | 
|  `AWSEC2-ApplicationInsightsCloudwatchAgentInstallAndConfigure`  |  根據應用程式元件的監控組態來安裝和設定 CloudWatch 代理程式。  |  本文件每 30 分鐘執行一次，以確保 CloudWatch 代理程式組態始終準確且最新。此文件也會在對應用程式監控設定 (例如新增或移除指標或更新日誌組態) 進行變更後立即執行。  | 

## 管理的文件 AWS Systems Manager
<a name="ssm-documents-aws-managed"></a>

下列文件由 CloudWatch Application Insights 使用，並由 Systems Manager 管理。

**`AWS-ConfigureAWSPackage`**  
Application Insights 使用本文件來安裝和解除安裝 Prometheus 匯出程式經銷商套件，收集工作負載特定指標，以及對客戶 Amazon EC2 執行個體上的工作負載進行全面監控。只有在執行個體上執行相關的目標工作負載時，CloudWatch Application Insights 才會安裝 Prometheus 匯出程式經銷商套件。

下表列出 Prometheus 匯出程式經銷商套件及相關的目標工作負載。


| Prometheus 匯出程式經銷商套件名稱 | 目標工作負載 | 
| --- | --- | 
|  `AWSObservabilityExporter-HAClusterExporterInstallAndConfigure`  |  SAP HANA HA  | 
|  `AWSObservabilityExporter-JMXExporterInstallAndConfigure`  |  Java/JMX  | 
|  `AWSObservabilityExporter-SAP-HANADBExporterInstallAndConfigure`  |  SAP HANA  | 
|  `AWSObservabilityExporter-SAP-SAPHostExporterInstallAndConfigure`  |  NetWeaver  | 
|  `AWSObservabilityExporter-SQLExporterInstallAndConfigure`  |  SQL Server (Windows) 和 SAP ASE (Linux)  | 

**`AmazonCloudWatch-ManageAgent`**  
Application Insights 使用本文件來管理執行個體上 CloudWatch 代理程式的狀態和組態，並從不同作業系統的 Amazon EC2 執行個體中收集內部系統層級指標和日誌。

# 存取 CloudWatch Application Insights 所需的先決條件、IAM 政策和許可
<a name="appinsights-accessing"></a>

若要開始使用 CloudWatch Application Insights，請確認已滿足以下先決條件、已建立 IAM 政策並且已連接許可 (如果需要)。

**Topics**
+ [設定應用程式以進行監控的先決條件](appinsights-prereqs.md)
+ [CloudWatch Application Insights 的 IAM 政策](appinsights-iam.md)
+ [帳戶型應用程式上架的 IAM 角色許可](appinsights-account-based-onboarding-permissions.md)

# 設定應用程式以進行監控的先決條件
<a name="appinsights-prereqs"></a>

您必須完成以下事前準備，使用 CloudWatch Application Insights 設定應用程式：
+ **AWS Systems Manager enablement** – 在 Amazon EC2 執行個體上安裝 Systems Manager Agent (SSM Agent)，並為 SSM 啟用執行個體。如需有關如何安裝 SSM Agent 的資訊，請參閱*《AWS Systems Manager 使用者指南》*中的[設定 AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-setting-up.html)。
+ **EC2 執行個體角色** — 您必須連接下列 Amazon EC2 執行個體角色才能啟用 Systems Manager
  + 您必須連接 `AmazonSSMManagedInstanceCore` 角色，以啟用 Systems Manager。如需詳細資訊，請參閱 [AWS Systems Manager 以身分為基礎的政策範例](https://docs.aws.amazon.com/systems-manager/latest/userguide/auth-and-access-control-iam-identity-based-access-control.html)。
  + 您必須連接 `CloudWatchAgentServerPolicy` 政策，以便透過 CloudWatch 發出執行個體指標和日誌。如需詳細資訊，請參閱[《建立 IAM 角色和使用者以使用 CloudWatch 代理程式》](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-iam-roles-for-cloudwatch-agent.html)。
+ **AWS 資源群組** – 若要將應用程式加入 CloudWatch Application Insights，請建立資源群組，其中包含應用程式堆疊所使用的所有相關 AWS 資源。這包括 Application Load Balancer、執行 IIS 和網路前端的 Amazon EC2 執行個體、.NET 工作者層和 SQL Server 資料庫。如需有關 Application Insights 支援的應用程式元件和技術堆疊的詳細資訊，請參閱 [支援的應用程式元件](appinsights-what-is.md#appinsights-components)。CloudWatch Application Insights 會自動納入和您資源群組使用相同標籤或 CloudFormation 堆疊的 Auto Scaling 群組，因為 CloudFormation 資源群組不支援 Auto Scaling 群組。如需詳細資訊，請參閱[《 AWS Resource Groups 入門》](https://docs.aws.amazon.com/ARG/latest/userguide/gettingstarted.html)。
+ **IAM 許可** – 對於沒有管理存取權的使用者，您必須建立允許 Application Insights 建立服務連結角色並將其連接到使用者身分的 AWS Identity and Access Management (IAM) 政策。如需有關如何建立 IAM 政策的詳細資訊，請參閱 [CloudWatch Application Insights 的 IAM 政策](appinsights-iam.md)。
+ **服務連結角色** – Application Insights 使用 AWS Identity and Access Management (IAM) 服務連結角色。系統會在您於 Application Insights 主控台建立第一個 Application Insights 應用程式時，為您建立服務連結角色。如需詳細資訊，請參閱[針對 CloudWatch Application Insights 使用服務連結角色](CHAP_using-service-linked-roles-appinsights.md)。
+ **效能計數器指標支援 EC2 Windows 執行個體** — 若要監控 Amazon EC2 Windows 執行個體上的效能計數器指標，執行個體上必須安裝效能計數器。如需效能計數器指標和對應的效能計數器集名稱，請參閱[效能計數器指標](application-insights-performance-counter.md)。如需效能計數器的詳細資訊，請參閱[效能計數器](https://docs.microsoft.com/en-us/windows/win32/perfctrs/performance-counters-portal)。
+ **Amazon CloudWatch 代理程式** — Application Insights 會安裝並設定 CloudWatch 代理程式。若您已安裝 CloudWatch 代理程式，Application Insights 會保留您的組態。若要避免合併衝突，請從現有的 CloudWatch 代理程式組態檔案中移除您要在 Application Insights 中使用的資源組態。如需詳細資訊，請參閱[手動建立或編輯 CloudWatch 代理程式組態檔案](CloudWatch-Agent-Configuration-File-Details.md)。

# CloudWatch Application Insights 的 IAM 政策
<a name="appinsights-iam"></a>

若要使用 CloudWatch Application Insights，您必須建立 [AWS Identity and Access Management (IAM) 政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html)並將其連接到您的使用者、群組或角色。如需有關使用者、群組及角色的詳細資訊，請參閱 [IAM 身分 (使用者、群組及角色)](https://docs.aws.amazon.com/IAM/latest/UserGuide/id.html)。IAM 政策會定義使用者許可。

**使用主控台建立 IAM 政策**  
若要使用 IAM 主控台建立 IAM 政策，請執行下列步驟。

1. 前往 [IAM 主控台](https://console.aws.amazon.com/iam/home)。在左導覽窗格中，選取 **Policies (政策)**。

1. 在頁面頂端，選取 **Create policy (建立政策)**。

1. 選取 **JSON** 標籤。

1. 複製下列 JSON 文件並貼在 **JSON** 標籤下。

------
#### [ JSON ]

****  

   ```
   {
       "Version":"2012-10-17",		 	 	 
       "Statement": [
           {
               "Action": [
                   "applicationinsights:*",
                   "iam:CreateServiceLinkedRole",
                   "iam:ListRoles",
                   "resource-groups:ListGroups"
               ],
               "Effect": "Allow",
               "Resource": "*"
           }
       ]
   }
   ```

------

1. 選取 **Review Policy (檢閱政策)**。

1. 輸入政策的 **Name (名稱)**，例如 “AppInsightsPolicy”。或者輸入 **Description (描述)**。

1. 選取 **Create Policy (建立政策)**。

1. 在左側導覽窗格中，選取**使用者群組**、**使用者**或**角色**。

1. 選取您要連接政策之使用者群組、使用者或角色的名稱。

1. 選取 **Add permissions (新增許可)**。

1. 選取**直接連接現有政策**。

1. 搜尋剛剛建立的政策，然後選取該政策名稱左側的核取方塊。

1. 選取 **Next: Review (下一步：檢閱)**。

1. 確定列出正確的政策，然後選取 **Add permissions (新增許可)**。

1. 當您使用 CloudWatch Application Insights 時，請務必以與剛建立政策相關聯的使用者身分登入。

**使用 建立 IAM 政策 AWS CLI**  
若要使用 建立 IAM 政策 AWS CLI，請使用上述 JSON 文件做為目前資料夾中的檔案，從命令列執行 [create-policy](https://docs.aws.amazon.com/cli/latest/reference/iam/create-policy.html) 操作。

**使用 建立 IAM 政策 AWS Tools for Windows PowerShell**  
若要使用 建立 IAM 政策 AWS Tools for Windows PowerShell，請使用上述 JSON 文件做為目前資料夾中的檔案來執行 [New-IAMPolicy](https://docs.aws.amazon.com/powershell/latest/reference/items/New-IAMPolicy.html) cmdlt。

# 帳戶型應用程式上架的 IAM 角色許可
<a name="appinsights-account-based-onboarding-permissions"></a>

如果想要將帳戶中的所有資源上架，而且選擇不使用 [Application Insights 受管政策](security-iam-awsmanpol-appinsights.md)完整存取 Application Insights 功能，則您必須將下列許可連接至 IAM 角色，以便 Application Insights 能夠探索您帳戶中的所有資源：

```
"ec2:DescribeInstances" 
"ec2:DescribeNatGateways"
"ec2:DescribeVolumes"
"ec2:DescribeVPCs"
"rds:DescribeDBInstances"
"rds:DescribeDBClusters"
"sqs:ListQueues"
"elasticloadbalancing:DescribeLoadBalancers"
"autoscaling:DescribeAutoScalingGroups"
"lambda:ListFunctions"
"dynamodb:ListTables"
"s3:ListAllMyBuckets"
"sns:ListTopics"
"states:ListStateMachines"
"apigateway:GET"
"ecs:ListClusters"
"ecs:DescribeTaskDefinition" 
"ecs:ListServices"
"ecs:ListTasks"
"eks:ListClusters"
"eks:ListNodegroups"
"fsx:DescribeFileSystems"
"route53:ListHealthChecks"
"route53:ListHostedZones"
"route53:ListQueryLoggingConfigs"
"route53resolver:ListFirewallRuleGroups"
"route53resolver:ListFirewallRuleGroupAssociations"
"route53resolver:ListResolverEndpoints"
"route53resolver:ListResolverQueryLogConfigs"
"route53resolver:ListResolverQueryLogConfigAssociations"
"logs:DescribeLogGroups"
"resource-explorer:ListResources"
```

# 使用 設定用於監控的應用程式 AWS 管理主控台
<a name="appinsights-setting-up"></a>

本節提供使用主控台、 和 設定、設定 AWS CLI和管理 CloudWatch Application Insights 應用程式的步驟 AWS Tools for Windows PowerShell。

**Topics**
+ [主控台步驟](appinsights-setting-up-console.md)
+ [命令列步驟](appinsights-setting-up-command.md)
+ [事件](appinsights-cloudwatch-events.md)
+ [通知](appinsights-problem-notifications.md)

# 從 CloudWatch 主控台安裝、設定及管理應用程式以進行監控
<a name="appinsights-setting-up-console"></a>

本節提供安裝、設定和管理應用程式以從 CloudWatch 主控台進行監控的步驟。

**Topics**
+ [新增並設定應用程式](#appinsights-add-configure)
+ [啟用 Application Insights 進行 Amazon ECS 和 Amazon EKS 資源監控](#appinsights-container-insights)
+ [停用應用程式元件的監控](#appinsights-disable-monitoring)
+ [刪除應用程式](#appinsights-delete-app)

## 新增並設定應用程式
<a name="appinsights-add-configure"></a>

**從 CloudWatch 主控台新增和設定應用程式**  
若要從 CloudWatch 主控台開始使用 CloudWatch Application Insights，請遵循以下步驟。

1. **啟動。**開啟 [CloudWatch 主控台登陸頁面](https://console.aws.amazon.com/cloudwatch)。從左側導覽窗格中，選擇 **Insights** 下的 **Application Insights**。開啟的頁面會顯示 CloudWatch Application Insights 監控的應用程式清單，以及它們的監控狀態。

1. **新增應用程式。**若要設定應用程式的監控，請選擇 **Add an application** (新增應用程式)。當您選擇 **Add an application** (新增應用程式) 時，系統會提示您 **Choose Application Type** (選擇應用程式類型)。
   + **以資源群組為基礎的應用程式**。選取此選項時，您可以選擇此帳戶中要監控的資源群組。若要在元件上使用多個應用程式，您必須使用資源群組型監控。
   + **以帳戶為基礎的應用程式**。選取此選項時，您可以監控此帳戶中的所有資源。如果您想要監控帳戶中的所有資源，建議使用此選項，而不是以資源群組為基礎的選項，因為應用程式上架程序會更快。
**注意**  
您無法使用 Application Insights，將以資源群組為基礎的監控與以帳戶為基礎的監控結合。若要變更應用程式類型，您必須刪除所有受監控的應用程式，並 **Choose Application Type** (選擇應用程式類型)。

   當您新增第一個應用程式進行監控時，CloudWatch Application Insights 會在您的帳戶中建立服務連結角色，以授予 Application Insights 代表您呼叫其他 AWS 服務的許可。如需 Application Insights 在您帳戶中所建服務連結角色的詳細資訊，請參閱 [針對 CloudWatch Application Insights 使用服務連結角色](CHAP_using-service-linked-roles-appinsights.md)。

1. 

------
#### [ Resource-based application monitoring ]

   1. **選取應用程式或資源群組。**在**指定應用程式詳細資訊**頁面上，從下拉式清單中選取包含應用程式資源 AWS 的資源群組。這些資源包括前端伺服器、負載平衡器、自動調整規模群組和資料庫伺服器。

      如果尚未建立應用程式的資源群組，您可以透過選擇 **Create new resource group** (建立新的資源群組) 建立一個。如需建立資源群組的詳細資訊，請參閱《[https://docs.aws.amazon.com/ARG/latest/userguide/welcome.html](https://docs.aws.amazon.com/ARG/latest/userguide/welcome.html)》。

   1. **問題洞察通知。**若要檢視並在偵測到所選應用程式的問題時收到通知，請選取 Amazon SNS 通知或 Systems Manager OpsCenter Opsitems。

      1. **設定 Amazon SNS 通知 (推薦)。**選擇**選取現有主題**或**建立新主題**。

      1. **與 ​ AWS Systems Manager OpsCenter 整合。**在**進階設定**下，選取**為補救動作產生 Systems Manager OpsCenter OpsItems**核取方塊。若要追蹤解決與您 AWS 資源相關的操作工作項目 (OpsItems) 所採取的操作，請提供 Amazon SNS 主題 ARN。

   1. **監控 CloudWatch Events**。選取核取方塊以將 Application Insights 監控與 CloudWatch Events 整合，以取得 Amazon EBS、Amazon EC2、 AWS CodeDeploy、Amazon ECS、 AWS Health API 和通知、Amazon RDS、Amazon S3 和 AWS Step Functions的洞察。

   1. **標籤 – 選用**。CloudWatch Application Insights 支援標籤型和 CloudFormation 型資源群組 (Auto Scaling 群組除外)。如需詳細資訊，請參閱[使用標籤編輯器](https://docs.aws.amazon.com/ARG/latest/userguide/tag-editor.html)。

   1. 選擇**下一步**。

      會以下列格式為應用程式產生 [ARN](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html)。

      ```
      arn:partition:applicationinsights:region:account-id:application/resource-group/resource-group-name
      ```

      範例

      ```
      arn:aws:applicationinsights:us-east-1:123456789012:application/resource-group/my-resource-group
      ```

   1. 在**檢閱偵測到的元件**頁面的**檢閱元件以供監控之用**下，表格會列出偵測到的元件及其關聯的偵測到的工作負載。
**注意**  
對於支援多個自訂工作負載的元件，您最多可為每個元件監控五個工作負載。這些工作負載將與元件分開監控。  
![\[CloudWatch Application Insights 主控台的「偵測到的元件」區段：偵測到的元件和關聯的工作負載之概觀。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-multiapp-review-component.png)

      在**關聯的工作負載**下，如果未列出工作負載，畫面上會出現幾個可能的訊息。
      + **無法偵測工作負載** – 嘗試偵測工作負載時發生問題。確定您已完成 [設定應用程式以進行監控的先決條件](appinsights-prereqs.md)。如果您需要新增工作負載，請選擇**編輯元件**。
      + **未偵測到工作負載** – 我們未偵測到任何工作負載。您可能需要新增工作負載。若要這麼做，請選擇**編輯元件**。
      + **不適用** – 元件不支援自訂工作負載，且會使用預設指標、警示和日誌進行監控。您無法將工作負載新增至這些元件。

   1. 若要編輯元件，請選取元件，然後選擇**編輯元件**。側邊面板隨即開啟，且在元件上偵測到工作負載。在此面板中，您可以編輯元件詳細資料並新增工作負載。  
![\[CloudWatch Application Insights 主控台的「檢閱偵測到的元件」區段：可編輯關聯的工作負載。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-multiapp-edit-component.png)
      + 若要編輯工作負載類型或名稱，請使用下拉式清單。  
![\[CloudWatch Application Insights 主控台的「編輯元件」區段：工作負載類型的下拉式清單。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-multiapp-edit-name-type.png)
      + 若要將工作負載新增至元件，請選擇**新增工作負載**。  
![\[CloudWatch Application Insights 主控台的「編輯元件」區段：可加入新工作負載的左下角按鈕。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-multiapp-add-workload.png)
        + 如果未顯示**新增工作負載**，則此元件不支援多個工作負載。
        + 如果未顯示**關聯的工作負載**標題，則此元件不支援自訂工作負載。
      + 若要移除工作負載，請選擇您要從監控中移除之工作負載旁的**移除**。  
![\[CloudWatch Application Insights 主控台的「編輯元件」區段：移除工作負載。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-multiapp-remove-workload.png)
      + 若要停用整個元件的監控，請清除**監控**核取方塊。  
![\[可停用監控功能的 CloudWatch Application Insights 核取方塊的編輯元件區段。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-multiapp-disable-monitoring.png)
      + 編輯完元件後，請選擇右下角的**儲存變更**。對元件的工作負載所做的任何變更，都會顯示在**關聯工作負載**下的**檢閱元件以供監控之用**表格中。

   1. 在**檢閱偵測到的元件**頁面上，選擇**下一步**。

   1. **指定元件詳細資料**頁面包含具有上一個步驟可自訂關聯工作負載的所有元件。
**注意**  
如果元件標頭有*選擇性*標籤，則該元件中工作負載的其他詳細資料為選擇性。

      如果元件未出現在此頁面上，表示元件沒有可在此步驟中指定的任何其他詳細資料。

   1. 選擇**下一步**。

   1. 在**檢閱並提交**頁面上，檢閱所有監督的元件和工作負載詳細資訊。

   1. 選擇**提交**。

------
#### [ Account-based application monitoring ]

   1. **應用程式名稱**。輸入帳戶型應用程式的名稱。

   1. **自動監控新資源**。根據預設，在上架應用程式之後，Application Insights 會使用建議的設定為新增至帳戶的資源元件設定監控。您可以清除核取方塊，以排除上架應用程式之後新增的資源監控。

   1. **監控 CloudWatch Events**。選取核取方塊以將 Application Insights 監控與 CloudWatch Events 整合，以取得 Amazon EBS、Amazon EC2、 AWS CodeDeploy、Amazon ECS、 AWS Health API 和通知、Amazon RDS、Amazon S3 和 AWS Step Functions的洞察。

   1. **與 ​ AWS Systems Manager OpsCenter 整合。**若要檢視並在偵測到所選應用程式的問題時收到通知，請選取 **Generate Systems Manager OpsCenter OpsItems for remedial actions** (產生 Systems Manager OpsCenter OpsItems 以進行補救動作) 核取方塊。若要追蹤解決與您 AWS 資源相關的操作工作項目 (OpsItems) 所採取的操作，請提供 SNS 主題 ARN。

   1. **標籤 – 選用**。CloudWatch Application Insights 支援標籤型和 CloudFormation 型資源群組 (Auto Scaling 群組除外)。如需詳細資訊，請參閱[使用標籤編輯器](https://docs.aws.amazon.com/ARG/latest/userguide/tag-editor.html)。

   1. **探索的資源**。您帳戶中找到的所有資源都會新增至此清單。如果 Application Insights 無法找到您帳戶中的所有資源，頁面頂端會出現錯誤訊息。此訊息包含[如何新增所需許可的文件](appinsights-account-based-onboarding-permissions.md)連結。

   1. 選擇**下一步**。

      會以下列格式為應用程式產生 [ARN](https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html)。

      ```
      arn:partition:applicationinsights:region:account-id:application/TBD/application-name
      ```

      範例

      ```
      arn:aws:applicationinsights:us-east-1:123456789012:application/TBD/my-application
      ```

------

1. 在您提交應用程式監控組態之後，您會來到應用程式的詳細資訊頁面，您可以在此檢視 **Application summary** (應用程式摘要)、**Monitored components** (受監控元件) 清單和 **Unmonitored components** (未受監控元件)，以及透過選取 **Components** (元件)、**Configuration history** (組態歷史記錄)、**Log patterns** (日誌模式) 和任何已套用 **Tags** (標籤) 旁的索引標籤檢視。

   若要檢視應用程式的洞察，請選擇 **View Insights** (檢視洞察)。

   您可以選擇**編輯**，以更新 CloudWatch Events 監控和與 AWS Systems Manager OpsCenter 整合的選擇。

   在 **Components** (元件) 下，您可以選取 **Actions** (動作) 選單建立、修改或解除執行個體群組。

   您可以管理元件的監控，包括應用程式層、日誌群組、事件日誌、指標和自訂警示，方法是選取元件旁的項目符號並選擇 **Manage monitoring** (管理監控)。

## 啟用 Application Insights 進行 Amazon ECS 和 Amazon EKS 資源監控
<a name="appinsights-container-insights"></a>

您可以從 Container Insights 主控台啟用 Application Insights 以監控容器化應用程式和微型服務。Application Insights 支援監控下列資源：
+ Amazon ECS 叢集
+ Amazon ECS 服務
+ Amazon ECS 任務
+ Amazon EKS 叢集

啟用 Application Insights 後，它會提供建議的指標和日誌、偵測潛在問題、產生 CloudWatch Events，以及為您的容器化應用程式和微型服務建立自動儀表板。

您可以從 Container Insights 或 Application Insights 主控台為容器化資源啟用 Application Insights。

**從 Container Insights 主控台啟用 Application Insights**  
從 Container Insights 主控台的 Container Insights **Performance monitoring** (效能監控) 儀表板，選擇 **Auto-configure Application Insights** (自動設定 Application Insights)。啟用 Application Insights 時，會顯示偵測到問題的詳細資訊。

**從 Application Insights 主控台啟用 Application Insights**  
當 ECS 叢集出現在元件清單中時，Application Insights 會自動啟用具有 Container Insights 的其他容器監控。

對於 EKS 叢集，您可以啟用具有 Container Insights 的其他監控，以提供診斷資訊，例如容器重新啟動故障，協助您隔離和解決問題。設定 EKS 的 Container Insights 需要其他步驟。如需相關資訊，請參閱設定 EKS 上 Container Insights 的 [在 Amazon EKS 和 Kubernetes 上設定 Container Insights](deploy-container-insights-EKS.md) 步驟。

使用 EKS 的 Linux 執行個體支援對具有 Container Insights 的 EKS 進行額外監控。

如需 ECS 和 EKS 叢集 Container Insights 支援的詳細資訊，請參閱 [Container Insights](ContainerInsights.md)。

## 停用應用程式元件的監控
<a name="appinsights-disable-monitoring"></a>

若要停用應用程式元件的監控，請從應用程式詳細資訊頁面選取您要停用監控的元件。選擇 **Actions** (動作)，然後 **Remove from monitoring** (從監控移除)。

## 刪除應用程式
<a name="appinsights-delete-app"></a>

若要偵測應用程式，請從 CloudWatch 儀表板的左側導覽窗格，選擇 **Insights** 下的 **Application Insights**。選取您要刪除的應用程式。在 **Actions** (動作) 下，選擇 **Delete application** (刪除應用程式)。這會刪除監控並刪除所有已儲存的應用程式元件監控。不會刪除應用程式資源。

# 使用命令列安裝、設定及管理應用程式以進行監控
<a name="appinsights-setting-up-command"></a>

本節提供設定、設定和管理應用程式的步驟，以便使用 AWS CLI 和 進行監控 AWS Tools for Windows PowerShell。

**Topics**
+ [新增及管理應用程式](#appinsights-config-app-command)
+ [管理和更新監控](#appinsights-monitoring)
+ [設定 SQL Always On 可用性群組的監控](#configure-sql)
+ [設定監控 MySQL RDS](#configure-mysql-rds)
+ [設定監控 MySQL EC2](#configure-mysql-ec2)
+ [設定 PostgreSQL RDS 的監控](#configure-postgresql-rds)
+ [設定 PostgreSQL EC2 的監控](#configure-postgresql-ec2)
+ [設定 Oracle RDS 的監控](#configure-oracle-rds)
+ [設定 Oracle EC2 的監控](#configure-oracle-ec2)

## 新增及管理應用程式
<a name="appinsights-config-app-command"></a>

您可以使用命令列新增、取得相關資訊、管理和設定您的 Application Insights 應用程式。

**Topics**
+ [新增應用程式](#appinsights-add-app)
+ [描述應用程式](#appinsights-describe-app)
+ [列出應用程式中的元件](#appinsights-list-components)
+ [描述元件](#appinsights-describe-components)
+ [將類似資源分組到自訂元件](#appinsights-group-resources-components)
+ [取消群組自訂元件](#appinsights-ungroup-resources-components)
+ [更新應用程式](#appinsights-update-app)
+ [更新自訂元件](#appinsights-update-component)

### 新增應用程式
<a name="appinsights-add-app"></a>

**使用 新增應用程式 AWS CLI**  
若要使用 AWS CLI 為名為 的資源群組新增應用程式`my-resource-group`，並啟用 OpsCenter 將建立的 opsItem 交付至 SNS 主題 ARN ` arn:aws:sns:us-east-1:123456789012:MyTopic`，請使用下列命令。

```
aws application-insights create-application --resource-group-name my-resource-group --ops-center-enabled --ops-item-sns-topic-arn arn:aws:sns:us-east-1:123456789012:MyTopic
```

**使用 新增應用程式 AWS Tools for Windows PowerShell**  
若要使用 AWS Tools for Windows PowerShell 為已啟用 `my-resource-group` OpsCenter 的資源群組新增應用程式，以將建立的 opsItem 交付至 SNS 主題 ARN `arn:aws:sns:us-east-1:123456789012:MyTopic`，請使用下列命令。

```
New-CWAIApplication -ResourceGroupName my-resource-group -OpsCenterEnabled true -OpsItemSNSTopicArn arn:aws:sns:us-east-1:123456789012:MyTopic
```

### 描述應用程式
<a name="appinsights-describe-app"></a>

**使用 描述應用程式 AWS CLI**  
若要使用 AWS CLI 描述在名為 的資源群組上建立的應用程式`my-resource-group`，請使用下列命令。

```
aws application-insights describe-application --resource-group-name my-resource-group
```

**使用 描述應用程式 AWS Tools for Windows PowerShell**  
若要使用 AWS Tools for Windows PowerShell 描述在名為 的資源群組上建立的應用程式`my-resource-group`，請使用下列命令。

```
Get-CWAIApplication -ResourceGroupName my-resource-group
```

### 列出應用程式中的元件
<a name="appinsights-list-components"></a>

**使用 列出應用程式中的元件 AWS CLI**  
若要使用 AWS CLI 列出在名為 的資源群組上建立的元件`my-resource-group`，請使用下列命令。

```
aws application-insights list-components --resource-group-name my-resource-group
```

**使用 列出應用程式中的元件 AWS Tools for Windows PowerShell**  
若要使用 AWS Tools for Windows PowerShell 列出在名為 的資源群組上建立的元件`my-resource-group`，請使用下列命令。

```
Get-CWAIComponentList -ResourceGroupName my-resource-group
```

### 描述元件
<a name="appinsights-describe-components"></a>

**使用 描述元件 AWS CLI**  
您可以使用下列 AWS CLI 命令來描述名為 的元件`my-component`，該元件屬於在名為 的資源群組上建立的應用程式`my-resource-group`。

```
aws application-insights describe-component --resource-group-name my-resource-group --component-name my-component
```

**使用 描述元件 AWS Tools for Windows PowerShell**  
您可以使用下列 AWS Tools for Windows PowerShell 命令來描述名為 的元件`my-component`，該元件屬於在名為 的資源群組上建立的應用程式`my-resource-group`。

```
Get-CWAIComponent -ComponentName my-component -ResourceGroupName my-resource-group
```

### 將類似資源分組到自訂元件
<a name="appinsights-group-resources-components"></a>

建議您將類似的資源 (例如 .NET Web 伺服器執行個體) 分組到自訂元件，以實現更輕鬆的安裝和更好的監控與洞見。CloudWatch Application Insights 支援 EC2 執行個體的自訂群組。

**使用 將資源分組到自訂元件 AWS CLI**  
若要使用 AWS CLI 將三個執行個體 (`arn:aws:ec2:us-east-1:123456789012:instance/i-11111`、 `arn:aws:ec2:us-east-1:123456789012:instance/i-22222`和 `arn:aws:ec2:us-east-1:123456789012:instance/i-33333`) 分組為`my-component`針對名為 的資源群組所建立之應用程式的自訂元件`my-resource-group`，請使用下列命令。

```
aws application-insights create-component --resource-group-name my-resource-group --component-name my-component --resource-list arn:aws:ec2:us-east-1:123456789012:instance/i-11111 arn:aws:ec2:us-east-1:123456789012:instance/i-22222 arn:aws:ec2:us-east-1:123456789012:instance/i-33333
```

**使用 將資源分組到自訂元件 AWS Tools for Windows PowerShell**  
若要使用 AWS Tools for Windows PowerShell 將三個執行個體 (`arn:aws:ec2:us-east-1:123456789012:instance/i-11111`、 `arn:aws:ec2:us-east-1:123456789012:instance/i-22222`和 `arn:aws:ec2:us-east-1:123456789012:instance/i-33333`) 分組為名為 的自訂元件`my-component`，對於為名為 的資源群組建立的應用程式`my-resource-group`，請使用下列命令。

```
New-CWAIComponent -ResourceGroupName my-resource-group -ComponentName my-component -ResourceList arn:aws:ec2:us-east-1:123456789012:instance/i-11111,arn:aws:ec2:us-east-1:123456789012:instance/i-22222,arn:aws:ec2:us-east-1:123456789012:instance/i-33333 
```

### 取消群組自訂元件
<a name="appinsights-ungroup-resources-components"></a>

**使用 取消自訂元件的群組 AWS CLI**  
若要使用 在資源群組`my-component`上建立的應用程式中 AWS CLI 取消群組名為 的自訂元件，`my-resource-group`請使用下列命令。

```
aws application-insights delete-component --resource-group-name my-resource-group --component-name my-new-component
```

**使用 取消自訂元件的群組 AWS Tools for Windows PowerShell**  
若要使用 在資源群組`my-component`上建立的應用程式中 AWS Tools for Windows PowerShell 取消群組名為 的自訂元件，`my-resource-group`請使用下列命令。

```
Remove-CWAIComponent -ComponentName my-component -ResourceGroupName my-resource-group
```

### 更新應用程式
<a name="appinsights-update-app"></a>

**使用 更新應用程式 AWS CLI**  
您可以使用 AWS CLI 更新應用程式，針對應用程式偵測到的問題產生 AWS Systems Manager OpsCenter OpsItems，並使用`arn:aws:sns:us-east-1:123456789012:MyTopic`下列命令將建立的 OpsItems 與 SNS 主題 建立關聯。

```
aws application-insights update-application --resource-group-name my-resource-group --ops-center-enabled --ops-item-sns-topic-arn arn:aws:sns:us-east-1:123456789012:MyTopic
```

**使用 AWS Tools for Windows PowerShell 更新應用程式**  
您可以使用 AWS Tools for Windows PowerShell 更新應用程式，針對應用程式偵測到的問題產生 AWS SSM OpsCenter OpsItems，並使用下列命令將建立的 OpsItems 與 SNS 主題 `arn:aws:sns:us-east-1:123456789012:MyTopic` 建立關聯。

```
Update-CWAIApplication -ResourceGroupName my-resource-group -OpsCenterEnabled true -OpsItemSNSTopicArn arn:aws:sns:us-east-1:123456789012:MyTopic
```

### 更新自訂元件
<a name="appinsights-update-component"></a>

**使用 更新自訂元件 AWS CLI**  
您可以使用下列命令，使用`my-component`新的元件名稱 `my-new-component`和更新的執行個體群組來 AWS CLI 更新名為 的自訂元件。

```
aws application-insights update-component --resource-group-name my-resource-group --component-name my-component --new-component-name my-new-component --resource-list arn:aws:ec2:us-east-1:123456789012:instance/i-44444 arn:aws:ec2:us-east-1:123456789012:instance/i-55555
```

**使用 AWS Tools for Windows PowerShell 更新自訂元件**  
您可以使用下列命令，使用`my-component`新的元件名稱 `my-new-component`和更新的執行個體群組來 AWS Tools for Windows PowerShell 更新名為 的自訂元件。

```
Update-CWAIComponent -ComponentName my-component -NewComponentName my-new-component -ResourceGroupName my-resource-group -ResourceList arn:aws:ec2:us-east-1:123456789012:instance/i-44444,arn:aws:ec2:us-east-1:123456789012:instance/i-55555
```

## 管理和更新監控
<a name="appinsights-monitoring"></a>

您可以使用命令列來管理和更新您 Application Insights 應用程式的監控。

**Topics**
+ [列出您應用程式的問題](#appinsights-list-problems-monitoring)
+ [描述應用程式問題](#appinsights-describe-app-problem)
+ [描述與問題相關聯的異常或錯誤](#appinsights-describe-anomalies)
+ [描述應用程式的異常或錯誤](#appinsights-describe-anomalies)
+ [描述元件的監控組態](#appinsights-describe-monitoring)
+ [描述元件的建議監控組態](#appinsights-describe-rec-monitoring)
+ [更新元件的監控組態](#update-monitoring)
+ [從 Application Insights 監控移除指定的資源群組](#update-monitoring)

### 列出您應用程式的問題
<a name="appinsights-list-problems-monitoring"></a>

**使用 列出應用程式的問題 AWS CLI**  
若要針對在名為 的資源群組上建立的應用程式，使用 AWS CLI 列出自 Unix Epoch 起 1，000 到 10，000 毫秒之間偵測到的應用程式問題`my-resource-group`，請使用下列命令。

```
aws application-insights list-problems --resource-group-name my-resource-group --start-time 1000 --end-time 10000
```

**使用 AWS Tools for Windows PowerShell 列出應用程式的問題**  
若要針對在名為 的資源群組上建立的應用程式，使用 AWS Tools for Windows PowerShell 列出自 Unix Epoch 起 1，000 到 10，000 毫秒之間偵測到的應用程式問題`my-resource-group`，請使用下列命令。

```
$startDate = "8/6/2019 3:33:00"
$endDate = "8/6/2019 3:34:00"
Get-CWAIProblemList -ResourceGroupName my-resource-group -StartTime $startDate -EndTime $endDate
```

### 描述應用程式問題
<a name="appinsights-describe-app-problem"></a>

**使用 描述應用程式問題 AWS CLI**  
若要使用 AWS CLI 描述問題 ID 為 的問題`p-1234567890`，請使用下列命令。

```
aws application-insights describe-problem —problem-id p-1234567890
```

**使用 AWS Tools for Windows PowerShell 描述應用程式問題**  
若要使用 AWS Tools for Windows PowerShell 描述問題 ID 為 的問題`p-1234567890`，請使用下列命令。

```
Get-CWAIProblem -ProblemId p-1234567890
```

### 描述與問題相關聯的異常或錯誤
<a name="appinsights-describe-anomalies"></a>

**使用 描述與問題相關的異常或錯誤 AWS CLI**  
若要使用 AWS CLI 來描述與問題 ID 為 的問題相關的異常或錯誤`p-1234567890`，請使用下列命令。

```
aws application-insights describe-problem-observations --problem-id -1234567890
```

**使用 描述與問題相關的異常或錯誤 AWS Tools for Windows PowerShell**  
若要使用 AWS Tools for Windows PowerShell 來描述與問題 ID 為 的問題相關的異常或錯誤`p-1234567890`，請使用下列命令。

```
Get-CWAIProblemObservation -ProblemId p-1234567890
```

### 描述應用程式的異常或錯誤
<a name="appinsights-describe-anomalies"></a>

**使用 CLI AWS 描述應用程式的異常或錯誤**  
若要使用 AWS CLI 來描述觀察 ID 為 的應用程式異常或錯誤`o-1234567890`，請使用下列命令。

```
aws application-insights describe-observation —observation-id o-1234567890
```

**使用 AWS Tools for Windows PowerShell 描述應用程式的異常或錯誤**  
若要使用 AWS Tools for Windows PowerShell 來描述觀察 ID 為 的應用程式異常或錯誤`o-1234567890`，請使用下列命令。

```
Get-CWAIObservation -ObservationId o-1234567890
```

### 描述元件的監控組態
<a name="appinsights-describe-monitoring"></a>

**使用 描述元件的監控組態 AWS CLI**  
若要使用 AWS CLI 來描述`my-component`在資源群組 上建立的應用程式中名為 之元件的監控組態`my-resource-group`，請使用下列命令。

```
aws application-insights describe-component-configuration —resource-group-name my-resource-group —component-name my-component
```

**使用 AWS Tools for Windows PowerShell 描述元件的監控組態**  
若要使用 AWS Tools for Windows PowerShell 來描述名為 之元件的監控組態`my-component`，請在資源群組 上建立的應用程式`my-resource-group`中使用下列命令。

```
Get-CWAIComponentConfiguration -ComponentName my-component -ResourceGroupName my-resource-group
```

如需元件組態的詳細資訊和範例 JSON 檔案，請參閱 [使用元件組態](component-config.md)。

### 描述元件的建議監控組態
<a name="appinsights-describe-rec-monitoring"></a>

**使用 描述元件的建議監控組態 AWS CLI**  
當元件是 .NET 工作者應用程式的一部分時，您可以使用下列命令`my-resource-group`， AWS CLI 描述`my-component`在資源群組 上建立的應用程式中所呼叫元件的建議監控組態。

```
aws application-insights describe-component-configuration-recommendation --resource-group-name my-resource-group --component-name my-component --tier DOT_NET_WORKER
```

**使用 描述元件的建議監控組態 AWS Tools for Windows PowerShell**  
當元件是 .NET 工作者應用程式的一部分時，您可以使用下列命令`my-resource-group`， AWS Tools for Windows PowerShell 描述`my-component`在資源群組 上建立的應用程式中所呼叫元件的建議監控組態。

```
Get-CWAIComponentConfigurationRecommendation -ComponentName my-component -ResourceGroupName my-resource-group -Tier DOT_NET_WORKER
```

如需元件組態的詳細資訊和範例 JSON 檔案，請參閱 [使用元件組態](component-config.md)。

### 更新元件的監控組態
<a name="update-monitoring"></a>

**使用 更新元件的監控組態 AWS CLI**  
若要使用 AWS CLI 在名為 的資源群組上建立`my-component`的應用程式中更新名為 的元件`my-resource-group`，請使用下列命令。命令包含這些動作：

1. 啟用元件的監控。

1. 將元件的層設為 `.NET Worker`。

1. 將元件的 JSON 組態更新為從本機檔案 `configuration.txt` 讀取。

```
aws application-insights update-component-configuration --resource-group-name my-resource-group --component-name my-component --tier DOT_NET_WORKER --monitor --component-configuration "file://configuration.txt"
```

**使用 更新元件的監控組態 AWS Tools for Windows PowerShell**  
若要使用 AWS Tools for Windows PowerShell 在名為 的資源群組上建立`my-component`的應用程式中更新名為 的元件`my-resource-group`，請使用下列命令。命令包含這些動作：

1. 啟用元件的監控。

1. 將元件的層設為 `.NET Worker`。

1. 將元件的 JSON 組態更新為從本機檔案 `configuration.txt` 讀取。

```
[string]$config = Get-Content -Path configuration.txt
Update-CWAIComponentConfiguration -ComponentName my-component -ResourceGroupName my-resource-group -Tier DOT_NET_WORKER -Monitor 1 -ComponentConfiguration $config
```

如需元件組態的詳細資訊和範例 JSON 檔案，請參閱 [使用元件組態](component-config.md)。

### 從 Application Insights 監控移除指定的資源群組
<a name="update-monitoring"></a>

**使用 從 Application Insights 監控中移除指定的資源群組 AWS CLI**  
若要使用 AWS CLI 從監控中移除在名為 `my-resource-group` 的資源群組上建立的應用程式，請使用下列命令。

```
aws application-insights delete-application --resource-group-name my-resource-group
```

**使用 從 Application Insights 監控中移除指定的資源群組 AWS Tools for Windows PowerShell**  
若要使用 AWS Tools for Windows PowerShell 從監控中移除在名為 `my-resource-group` 的資源群組上建立的應用程式，請使用下列命令。

```
Remove-CWAIApplication -ResourceGroupName my-resource-group
```

## 設定 SQL Always On 可用性群組的監控
<a name="configure-sql"></a>

1. 為資源群組建立具有 SQL HA EC2 執行個體的應用程式。

   ```
   aws application-insights create-application ‐-region <REGION> ‐-resource-group-name  <RESOURCE_GROUP_NAME>
   ```

1. 透過建立新的應用程式元件，來定義代表 SQL HA 叢集的 EC2 執行個體。

   ```
   aws application-insights create-component ‐-resource-group-name  "<RESOURCE_GROUP_NAME>" ‐-component-name SQL_HA_CLUSTER ‐-resource-list  "arn:aws:ec2:<REGION>:<ACCOUNT_ID>:instance/<CLUSTER_INSTANCE_1_ID>" "arn:aws:ec2:<REGION>:<ACCOUNT_ID>:instance/<CLUSTER_INSTANCE_2_ID>
   ```

1. 設定 SQL HA 元件。

   ```
   aws application-insights  update-component-configuration ‐-resource-group-name "<RESOURCE_GROUP_NAME>" ‐-region <REGION> ‐-component-name "SQL_HA_CLUSTER" ‐-monitor ‐-tier SQL_SERVER_ALWAYSON_AVAILABILITY_GROUP ‐-monitor  ‐-component-configuration '{
     "subComponents" : [ {
       "subComponentType" : "AWS::EC2::Instance",
       "alarmMetrics" : [ {
         "alarmMetricName" : "CPUUtilization",
         "monitor" : true
       }, {
         "alarmMetricName" : "StatusCheckFailed",
         "monitor" : true
       }, {
         "alarmMetricName" : "Processor % Processor Time",
         "monitor" : true
       }, {
         "alarmMetricName" : "Memory % Committed Bytes In Use",
         "monitor" : true
       }, {
         "alarmMetricName" : "Memory Available Mbytes",
         "monitor" : true
       }, {
         "alarmMetricName" : "Paging File % Usage",
         "monitor" : true
       }, {
         "alarmMetricName" : "System Processor Queue Length",
         "monitor" : true
       }, {
         "alarmMetricName" : "Network Interface Bytes Total/sec",
         "monitor" : true
       }, {
         "alarmMetricName" : "PhysicalDisk % Disk Time",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:Buffer Manager Buffer cache hit ratio",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:Buffer Manager Page life expectancy",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:General Statistics Processes blocked",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:General Statistics User Connections",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:Locks Number of Deadlocks/sec",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:SQL Statistics Batch Requests/sec",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:Database Replica File Bytes Received/sec",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:Database Replica Log Bytes Received/sec",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:Database Replica Log remaining for undo",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:Database Replica Log Send Queue",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:Database Replica Mirrored Write Transaction/sec",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:Database Replica Recovery Queue",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:Database Replica Redo Bytes Remaining",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:Database Replica Redone Bytes/sec",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:Database Replica Total Log requiring undo",
         "monitor" : true
       }, {
         "alarmMetricName" : "SQLServer:Database Replica Transaction Delay",
         "monitor" : true
       } ],
       "windowsEvents" : [ {
         "logGroupName" : "WINDOWS_EVENTS-Application-<RESOURCE_GROUP_NAME>",
         "eventName" : "Application",
         "eventLevels" : [ "WARNING", "ERROR", "CRITICAL", "INFORMATION" ],
         "monitor" : true
       }, {
         "logGroupName" : "WINDOWS_EVENTS-System-<RESOURCE_GROUP_NAME>",
         "eventName" : "System",
         "eventLevels" : [ "WARNING", "ERROR", "CRITICAL" ],
         "monitor" : true
       }, {
         "logGroupName" : "WINDOWS_EVENTS-Security-<RESOURCE_GROUP_NAME>",
         "eventName" : "Security",
         "eventLevels" : [ "WARNING", "ERROR", "CRITICAL" ],
         "monitor" : true
       } ],
       "logs" : [ {
         "logGroupName" : "SQL_SERVER_ALWAYSON_AVAILABILITY_GROUP-<RESOURCE_GROUP_NAME>",
         "logPath" : "C:\\Program Files\\Microsoft SQL Server\\MSSQL**.MSSQLSERVER\\MSSQL\\Log\\ERRORLOG",
         "logType" : "SQL_SERVER",
         "monitor" : true,
         "encoding" : "utf-8"
       } ]
     }, {
       "subComponentType" : "AWS::EC2::Volume",
       "alarmMetrics" : [ {
         "alarmMetricName" : "VolumeReadBytes",
         "monitor" : true
       }, {
       "alarmMetricName" : "VolumeWriteBytes",
         "monitor" : true
       }, {
       "alarmMetricName" : "VolumeReadOps",
         "monitor" : true
       }, {
       "alarmMetricName" : "VolumeWriteOps",
         "monitor" : true
       }, {
       "alarmMetricName" : "VolumeQueueLength",
         "monitor" : true
       }, {
       "alarmMetricName" : "VolumeThroughputPercentage",
         "monitor" : true
       }, {
       "alarmMetricName" : "BurstBalance",
         "monitor" : true
       } ]
     } ]
   }'
   ```

**注意**  
Application Insights 必須導入應用程式事件日誌 (資訊層級)，才能偵測叢集活動，例如容錯移轉。

## 設定監控 MySQL RDS
<a name="configure-mysql-rds"></a>

1. 為資源群組建立具有 RDS MySQL 資料庫執行個體的應用程式。

   ```
   aws application-insights create-application ‐-region <REGION> ‐-resource-group-name  <RESOURCE_GROUP_NAME>
   ```

1. 錯誤日誌預設為啟用。使用資料參數群組可啟用慢查詢日誌。如需詳細資訊，請參閱[存取 MySQL 慢查詢日誌及一般日誌](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.Concepts.MySQL.html#USER_LogAccess.MySQL.Generallog)。
   + `set slow_query_log = 1`
   + `set log_output = FILE`

1. 將要監控的日誌匯出至 CloudWatch Logs。如需詳細資訊，請參閱[將 MySQL 日誌發布到 CloudWatch Logs](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.Concepts.MySQL.html#USER_LogAccess.MySQLDB.PublishtoCloudWatchLogs)。

1. 設定 MySQL RDS 元件。

   ```
   aws application-insights  update-component-configuration ‐-resource-group-name "<RESOURCE_GROUP_NAME>" ‐-region <REGION> ‐-component-name "<DB_COMPONENT_NAME>" ‐-monitor ‐-tier DEFAULT ‐-monitor  ‐-component-configuration "{\"alarmMetrics\":[{\"alarmMetricName\":\"CPUUtilization\",\"monitor\":true}],\"logs\":[{\"logType\":\"MYSQL\",\"monitor\":true},{\"logType\": \"MYSQL_SLOW_QUERY\",\"monitor\":false}]}"
   ```

## 設定監控 MySQL EC2
<a name="configure-mysql-ec2"></a>

1. 為資源群組建立具有 SQL HA EC2 執行個體的應用程式。

   ```
   aws application-insights create-application ‐-region <REGION> ‐-resource-group-name  <RESOURCE_GROUP_NAME>
   ```

1. 錯誤日誌預設為啟用。使用資料參數群組可啟用慢查詢日誌。如需詳細資訊，請參閱[存取 MySQL 慢查詢日誌及一般日誌](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_LogAccess.Concepts.MySQL.html#USER_LogAccess.MySQL.Generallog)。
   + `set slow_query_log = 1`
   + `set log_output = FILE`

1. 設定 MySQL EC2 元件。

   ```
   aws application-insights  update-component-configuration ‐-resource-group-name "<RESOURCE_GROUP_NAME>" ‐-region <REGION> ‐-component-name "<DB_COMPONENT_NAME>" ‐-monitor ‐-tier MYSQL ‐-monitor  ‐-component-configuration "{\"alarmMetrics\":[{\"alarmMetricName\":\"CPUUtilization\",\"monitor\":true}],\"logs\":[{\"logGroupName\":\"<UNIQUE_LOG_GROUP_NAME>\",\"logPath\":\"C:\\\\ProgramData\\\\MySQL\\\\MySQL Server **\\\\Data\\\\<FILE_NAME>.err\",\"logType\":\"MYSQL\",\"monitor\":true,\"encoding\":\"utf-8\"}]}"
   ```

## 設定 PostgreSQL RDS 的監控
<a name="configure-postgresql-rds"></a>

1. 為資源群組建立具有 PostgreSQL RDS 資料庫執行個體的應用程式。

   ```
   aws application-insights create-application ‐-region <REGION> ‐-resource-group-name  <RESOURCE_GROUP_NAME>
   ```

1. 預設不會將 PostgreSQL 日誌發布至 CloudWatch。若要啟用監控，請開啟 RDS 主控台，然後選取要監控的資料庫。選擇右上角的 **Modify** (修改)，然後選取標示為 **PostgreSQL** 日誌的核取方塊。選擇 **Continue** (繼續) 以儲存此設定。

1. 您的 PostgreSQL 日誌會匯出至 CloudWatch。

1. 設定 PostgreSQL RDS 元件。

   ```
   aws application-insights update-component-configuration --region <REGION> --resource-group-name <RESOURCE_GROUP_NAME> --component-name <DB_COMPONENT_NAME> --monitor --tier DEFAULT --component-configuration 
   "{
      \"alarmMetrics\":[
         {
            \"alarmMetricName\": \"CPUUtilization\",
            \"monitor\": true
         }
      ],
      \"logs\":[
         {
            \"logType\": \"POSTGRESQL\",
            \"monitor\": true
         }
      ]
   }"
   ```

## 設定 PostgreSQL EC2 的監控
<a name="configure-postgresql-ec2"></a>

1. 為資源群組建立具有 PostgreSQL EC2 執行個體的應用程式。

   ```
   aws application-insights create-application ‐-region <REGION> ‐-resource-group-name  <RESOURCE_GROUP_NAME>
   ```

1. 設定 PostgreSQL EC2 元件。

   ```
   aws application-insights update-component-configuration ‐-region <REGION> ‐-resource-group-name <RESOURCE_GROUP_NAME> ‐-component-name <DB_COMPONENT_NAME> ‐-monitor ‐-tier POSTGRESQL ‐-component-configuration 
   "{
      \"alarmMetrics\":[
         {
            \"alarmMetricName\":\"CPUUtilization\",
            \"monitor\":true
         }
      ],
      \"logs\":[
         {
            \"logGroupName\":\"<UNIQUE_LOG_GROUP_NAME>\",
            \"logPath\":\"/var/lib/pgsql/data/log/\",
            \"logType\":\"POSTGRESQL\",
            \"monitor\":true,
            \"encoding\":\"utf-8\"
         }
      ]
   }"
   ```

## 設定 Oracle RDS 的監控
<a name="configure-oracle-rds"></a>

1. 為資源群組建立具有 Oracle RDS 資料庫執行個體的應用程式。

   ```
   aws application-insights create-application ‐-region <REGION> ‐-resource-group-name  <RESOURCE_GROUP_NAME>
   ```

1. 預設不會將 Oracle 日誌發布至 CloudWatch。若要啟用監控，請開啟 RDS 主控台，然後選取要監控的資料庫。選擇右上角的 **Modify** (修改)，然後選取標示為 **Alert** (提醒) 日誌和 **Listener** (接聽程式) 日誌的核取方塊。選擇 **Continue** (繼續) 以儲存此設定。

1. 您的 Oracle 日誌會匯出至 CloudWatch。

1. 設定 Oracle RDS 元件。

   ```
   aws application-insights update-component-configuration --region <REGION> --resource-group-name <RESOURCE_GROUP_NAME> --component-name <DB_COMPONENT_NAME> --monitor --tier DEFAULT --component-configuration 
   "{
      \"alarmMetrics\":[
         {
            \"alarmMetricName\": \"CPUUtilization\",
            \"monitor\": true
         }
      ],
      \"logs\":[
         {
            \"logType\": \"ORACLE_ALERT\",
            \"monitor\": true
         },
         {
            \"logType\": \"ORACLE_LISTENER\",
            \"monitor\": true
         }
      ]
   }"
   ```

## 設定 Oracle EC2 的監控
<a name="configure-oracle-ec2"></a>

1. 為資源群組建立具有 Oracle EC2 執行個體的應用程式。

   ```
   aws application-insights create-application ‐-region <REGION> ‐-resource-group-name  <RESOURCE_GROUP_NAME>
   ```

1. 設定 Oracle EC2 元件。

   ```
   aws application-insights update-component-configuration ‐-region <REGION> ‐-resource-group-name <RESOURCE_GROUP_NAME> ‐-component-name <DB_COMPONENT_NAME> ‐-monitor ‐-tier ORACLE ‐-component-configuration 
   "{
      \"alarmMetrics\":[
         {
            \"alarmMetricName\":\"CPUUtilization\",
            \"monitor\":true
         }
      ],
      \"logs\":[
         {
            \"logGroupName\":\"<UNIQUE_LOG_GROUP_NAME>\",
            \"logPath\":\"/opt/oracle/diag/rdbms/*/*/trace\",
            \"logType\":\"ORACLE_ALERT\",
            \"monitor\":true,
         },
         {
            \"logGroupName\":\"<UNIQUE_LOG_GROUP_NAME>\",
            \"logPath\":\"/opt/oracle/diag/tnslsnr/$HOSTNAME/listener/trace/\",
            \"logType\":\"ORACLE_ALERT\",
            \"monitor\":true,
         }
      ]
   }"
   ```

# 偵測到的問題的 Application Insights CloudWatch Events
<a name="appinsights-cloudwatch-events"></a>

針對新增到 CloudWatch Application Insights 的每個應用程式，下列事件會全力發布 CloudWatch Event：
+ **問題建立。**當 CloudWatch Application Insights 偵測到新問題時發出。
  + 詳細資訊類型：**「偵測到 Application Insights 問題」**
  + 詳細資訊：
    + `problemId`：偵測到的問題 ID。
    + `region`：建立問題的 AWS 區域。
    + `resourceGroupName`：偵測到問題的已註冊應用程式資源群組。
    + `status`：問題狀態。可能的狀態和定義如下：
      + `In progress`：已發現新問題。問題仍在接受觀察。
      + `Recovering`：問題在穩定下來。當問題處於此狀態時，您可以手動解決問題。
      + `Resolved`：問題已解決。沒有關於這個問題的新觀察。
      + `Recurring`：問題已在過去 24 小時內解決。由於有其他觀察結果，問題已重新開啟。
    + `severity`：問題嚴重性。
    + `problemUrl`：問題的主控台 URL。
+ **問題更新。**使用新觀察更新問題後，或更新現有觀察並隨後更新問題時發出；更新包括解決方案或關閉問題。
  + 詳細資訊類型：**「已更新 Application Insights 問題」**
  + 詳細資訊：
    + `problemId`：建立的問題 ID。
    + `region`：建立問題的 AWS 區域。
    + `resourceGroupName`：偵測到問題的已註冊應用程式資源群組。
    + `status`：問題狀態。
    + `severity`：問題嚴重性。
    + `problemUrl`：問題的主控台 URL。

# 接收偵測到問題的通知
<a name="appinsights-problem-notifications"></a>

可以使用 Amazon SNS 通知、Systems Manager OpsCenter 或 CloudWatch Events 來接收應用程式中偵測到問題的通知。

**已偵測到的問題的 CloudWatch Application Insights Amazon SNS 通知**  
您可以使用 AWS 管理主控台 或 設定 Amazon SNS 通知 AWS CLI。若要使用 設定通知 AWS 管理主控台，您必須擁有必要的 Amazon SNS 許可，如下列範例所示。

------
#### [ JSON ]

****  

```
{
    "Version":"2012-10-17",		 	 	 
    "Statement": [
      {
        "Effect": "Allow",
        "Action": [
          "sns:ListTopics",
          "sns:Subscribe",
          "sns:CreateTopic"
        ],    
        "Resource": [
          "*" 
        ]
      }
    ]    
}
```

------

設定 Amazon SNS 通知後，會在建立或解決問題時收到電子郵件通知。當新的觀測結果新增至現有問題時，也會收到通知。

下列範例顯示電子郵件通知的內容。

```
    You are receiving this email because Problem "p-1234567" has been CREATED by Amazon CloudWatch Application Insights
    
    Problem Details: 
    Problem URL: https:////console.aws.amazon.com/cloudwatch/home?region=us-east-1#settings:AppInsightsSettings/problemDetails?problemId=p-1234567
    Problem Summary: Title of the problem
    Severity: HIGH
    Insights: Something specific is broken
    Status : RESOLVED
    AffectedResource: arn:aws:ec2:us-east-1:555555555555:host/testResource
    Region: us-east-1
    RecurringCount: 0
    StartTime: 2019-03-23T10:42:57.777Z
    LastUpdatedTime: 2019-03-23T21:49:37.777Z
    LastRecurrenceTime: 
    StopTime: 2019-03-23T21:49:37.777Z
    
    Recent Issues
    - TelemetryArn:alarm1
      StartTime: 2024-08-15T22:12:46.007Z
      StopTime:
    - TelemetryArn:log-group1
      StartTime: 2024-08-15T22:12:46.007Z
      StopTime: 2024-08-15T22:12:46.007Z
```

**如何使用 Systems Manager 接收問題通知**  
**透過 執行動作 AWS Systems Manager。**CloudWatch Application Insights 提供與 Systems Manager OpsCenter 的內建整合。如果您選擇針對應用程式使用此整合，OpsCenter 主控台就會針對應用程式偵測到的每個問題建立 OpsItem。您可以從 OpsCenter 主控台檢視由 CloudWatch Application Insights 偵測到的問題的摘要資訊，並挑選一個 Systems Manager Automation Runbook 以採取修復動作，或進一步識別造成應用程式資源問題的 Windows 程序。

**如何使用 CloudWatch Events 接收問題通知**  
從 CloudWatch 主控台，在左側的導覽窗格，選取 **Events** (事件) 下的 **Rules** (規則)。從 **Rules (規則)** 頁面中選取 **Create rule (建立規則)**。從 **Service Name** (服務名稱) 下拉式清單中選擇 **Amazon CloudWatch Application Insights**，然後選擇 **Event Type** (事件類型)。接著，選擇 **Add target (新增目標)**，並選取目標和參數，例如 **SNS topic (SNS 主題)** 或 **Lambda function (Lambda 函數)**。

# Application Insights 跨帳戶觀察
<a name="appinsights-cross-account"></a>

透過 CloudWatch Application Insights 跨帳戶可觀測性，您可以監控和疑難排解單一區域中跨多個 AWS 帳戶的應用程式。

您可以使用 Amazon CloudWatch Observability Access Manager 將一或多個 AWS 帳戶設定為監控帳戶。您可以在監控帳戶中建立接收器，讓監控帳戶能夠檢視來源帳戶中的資料。可以使用此接收器建立從來源帳戶到監控帳戶的連結。如需詳細資訊，請參閱[CloudWatch 跨帳戶觀察功能](CloudWatch-Unified-Cross-Account.md)。

**必要的資源**  
為使 CloudWatch Application Insights 跨帳戶觀察功能正確發揮作用，請確保透過 CloudWatch Observability Access Manager 共用下列遙測類型。
+ CloudWatch Application Insights 中的應用程式
+ Amazon CloudWatch 中的指標
+ Amazon CloudWatch Logs 中的日誌群組
+ [AWS X-Ray](https://docs.aws.amazon.com/xray/latest/devguide/aws-xray.html) 中的追蹤

# 使用元件組態
<a name="component-config"></a>

元件組態是 JSON 格式的文字檔案，描述元件的組態設定。本節提供了範例範本片段、元件組態區段的描述和範例元件組態。

**Topics**
+ [範本片段](component-config-json.md)
+ [章節](component-config-sections.md)
+ [相關服務的組態範例](component-configuration-examples.md)

# 元件組態範本片段
<a name="component-config-json"></a>

下列範例顯示 JSON 格式的範本片段。

```
{
  "alarmMetrics" : [
    list of alarm metrics
  ],
  "logs" : [
    list of logs
  ],
  "processes" : [
   list of processes
  ],
  "windowsEvents" : [
    list of windows events channels configurations
  ],
  "alarms" : [
    list of CloudWatch alarms
  ],
  "jmxPrometheusExporter": {
    JMX Prometheus Exporter configuration
  },
  "hanaPrometheusExporter": {
      SAP HANA Prometheus Exporter configuration
  },
  "haClusterPrometheusExporter": {
      HA Cluster Prometheus Exporter configuration
  },
  "netWeaverPrometheusExporter": {
      SAP NetWeaver Prometheus Exporter configuration
  },
  "subComponents" : [
    {
      "subComponentType" : "AWS::EC2::Instance" ...
      component nested instances configuration
    },
    {
      "subComponentType" : "AWS::EC2::Volume" ...
      component nested volumes configuration
    }
  ]
}
```

# 元件組態區段
<a name="component-config-sections"></a>

元件組態包含數個主要區段。元件組態中的區段可以任何順序列出。
+ **alarmMetrics (選用)**

  要針對元件監控的[指標](#component-config-metric)清單 。所有元件類型都可以有 alarmMetrics 區段。
+ **日誌 (選用)**

  要針對元件監控的[日誌](#component-configuration-log)清單 。只有 EC2 執行個體可以有日誌區段。
+ **processes (選用)**

  要針對元件監控的[程式](#component-configuration-process)清單。只有 EC2 執行個體可以有程式區段。
+ **subComponents (選用)**

  元件的巢狀執行個體和磁碟區子元件組態。下列類型的元件可以有巢狀執行個體和子元件區段：ELB、ASG、自訂分組的 EC2 執行個體和 EC2 執行個體。
+ **alarms (optional) (警示 (選用))**

  監控元件的[警示](#component-configuration-alarms)清單。所有元件類型都可以有 alarm (警示) 區段。
+ **windowsEvents (選用)**

  要監控元件的 [Windows 事件](#windows-events)清單。只有 EC2 執行個體上的 Windows 才有 `windowsEvents` 區段。
+ **JMXPrometheusExporter (選用)**

  JMXPrometheus Exporter 組態。
+ **hanaPrometheusExporter (選用)**

  SAP HANA Prometheus Exporter 組態。
+ **haClusterPrometheusExporter (選用)**

  HA Cluster Prometheus Exporter 組態。
+ **netWeaverPrometheusExporter (選用)**

  SAP NetWeaver Prometheus 匯出程式組態。
+ **sapAsePrometheusExporter (選用)**

  SAP ASE Prometheus Exporter 組態。

以下範例以 JSON 格式顯示**子元件區段片段**的語法。

```
[
  {
    "subComponentType" : "AWS::EC2::Instance",
    "alarmMetrics" : [
      list of alarm metrics
    ],
    "logs" : [
      list of logs
    ],
    "processes": [
      list of processes
    ],
    "windowsEvents" : [
      list of windows events channels configurations
    ]
  },
  {
    "subComponentType" : "AWS::EC2::Volume",
    "alarmMetrics" : [
      list of alarm metrics
    ]
  }
]
```

## 元件組態區段屬性
<a name="component-config-properties"></a>

本節提供了個元件組態區段的屬性。

**Topics**
+ [指標](#component-config-metric)
+ [Log](#component-configuration-log)
+ [流程](#component-configuration-process)
+ [JMX Prometheus Exporter](#component-configuration-prometheus)
+ [HANA Prometheus Exporter](#component-configuration-hana-prometheus)
+ [HA Cluster Prometheus Exporter](#component-configuration-ha-cluster-prometheus)
+ [NetWeaver Prometheus 匯出程式](#component-configuration-netweaver-prometheus)
+ [SAP ASE Prometheus Exporter](#component-configuration-sap-ase-prometheus)
+ [Windows 事件](#windows-events)
+ [警示](#component-configuration-alarms)

### 指標
<a name="component-config-metric"></a>

定義要針對元件監控的指標。

**JSON** 

```
{
  "alarmMetricName" : "monitoredMetricName",
  "monitor" : true/false
}
```

**屬性**
+ **alarmMetricName (必要)**

  要針對元件監控的指標名稱。如需 Application Insights 支援的指標，請參閱 [Amazon CloudWatch Application Insights 支援的日誌和指標](appinsights-logs-and-metrics.md)。
+ **monitor (選用)**

  布林值，指出是否要監控該指標。預設值為 `true`。

### Log
<a name="component-configuration-log"></a>

定義要針對元件監控的日誌。

**JSON** 

```
{
  "logGroupName" : "logGroupName",
  "logPath" : "logPath",
  "logType" : "logType",
  "encoding" : "encodingType",
  "monitor" : true/false
}
```

**屬性**
+ **logGroupName (必要)**

  要與受監控日誌關聯的 CloudWatch 日誌群組名稱。如需日誌群組名稱限制條件，請參閱 [CreateLogGroup](https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_CreateLogGroup.html)。
+ **logPath (若為 EC2 執行個體元件則為必要；若為未使用 CloudWatch Agent 的元件 (例如 AWS Lambda) 則不需要)**

  要監控的日誌路徑。日誌路徑必須是 Windows 系統的檔案絕對路徑。如需詳細資訊，請參閱 [CloudWatch 代理程式組態檔案：日誌區段](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html#CloudWatch-Agent-Configuration-File-Logssection)。
+ **logType (必要)**

  日誌類型會決定 Application Insights 用來分析日誌的日誌模式。日誌類型可從下列選項中選取：
  + `SQL_SERVER`
  + `MYSQL`
  + `MYSQL_SLOW_QUERY`
  + `POSTGRESQL`
  + `ORACLE_ALERT`
  + `ORACLE_LISTENER`
  + `IIS`
  + `APPLICATION`
  + `WINDOWS_EVENTS`
  + `WINDOWS_EVENTS_ACTIVE_DIRECTORY`
  + `WINDOWS_EVENTS_DNS`
  + `WINDOWS_EVENTS_IIS`
  + `WINDOWS_EVENTS_SHAREPOINT`
  + `SQL_SERVER_ALWAYSON_AVAILABILITY_GROUP`
  + `SQL_SERVER_FAILOVER_CLUSTER_INSTANCE`
  + `DEFAULT`
  + `CUSTOM`
  + `STEP_FUNCTION`
  + `API_GATEWAY_ACCESS`
  + `API_GATEWAY_EXECUTION`
  + `SAP_HANA_LOGS`
  + `SAP_HANA_TRACE`
  + `SAP_HANA_HIGH_AVAILABILITY`
  + `SAP_NETWEAVER_DEV_TRACE_LOGS`
  + `PACEMAKER_HIGH_AVAILABILITY`
+ **encoding (選用)**

  要監控的日誌編碼類型。指定的編碼應包含在 [CloudWatch 代理程式支援的編碼](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/AgentReference.html)清單中。若未提供，CloudWatch Application Insights 會使用 utf-8 類型的預設編碼，但下列狀況除外：
  +  `SQL_SERVER`：utf-16 編碼
  +  `IIS`：ascii 編碼
+ **monitor (選用)**

  布林值，指出是否監控日誌。預設值為 `true`。

### 流程
<a name="component-configuration-process"></a>

定義要針對元件監控的程式。

**JSON** 

```
{
  "processName" : "monitoredProcessName",
  "alarmMetrics" : [
      list of alarm metrics
  ] 
}
```

**屬性**
+ **processName (必填)**

  要針對元件監控的程式名稱。程式名稱不得包含程式主體，例如 `sqlservr` 或者 `sqlservr.exe`。
+ **alarmMetrics (必填)**

  針對此程式要監控的[指標](#component-config-metric)清單。若要檢視 CloudWatch Application Insights 支援的程式指標，請參閱 [Amazon Elastic Compute Cloud (EC2)](appinsights-metrics-ec2.md)。

### JMX Prometheus Exporter
<a name="component-configuration-prometheus"></a>

定義 JMX Prometheus Exporter 設定。

**JSON** 

```
"JMXPrometheusExporter": {
  "jmxURL" : "JMX URL",
  "hostPort" : "The host and port",
  "prometheusPort" : "Target port to emit Prometheus metrics"
}
```

**屬性**
+ **jmxURL (選用)**

  要連線的完整 JMX URL。
+ **hostPort (選用)**

  透過遠端 JMX 連線的主機和連接埠。只能指定其中一個 `hostPort` 和 `jmxURL`。
+ **prometheusPort (選用)**

  要傳送 Prometheus 指標的目標連接埠。如果未指定，則會使用預設連接埠 9404。

### HANA Prometheus Exporter
<a name="component-configuration-hana-prometheus"></a>

定義 HANA Prometheus Exporter 設定。

**JSON** 

```
"hanaPrometheusExporter": {
    "hanaSid": "SAP HANA  SID",
    "hanaPort": "HANA database port",
    "hanaSecretName": "HANA secret name",
    "prometheusPort": "Target port to emit Prometheus metrics"
}
```

**屬性**
+ **hanaSid**

  SAP HANA 系統的三個字元 SAP 系統 ID (SID)。
+ **hanaPort**

  匯出工具會用來查詢 HANA 指標的 HANA 資料庫連接埠。
+ **hanaSecretName**

  存放 HANA 監控使用者登入資料的 AWS Secrets Manager 秘密。HANA Prometheus 匯出工具會使用這些憑證來連線至資料庫並查詢 HANA 指標。
+ **prometheusPort (選用)**

  要 Prometheus 要傳送指標的目標連接埠。如果未指定，則會使用預設連接埠 9668。

### HA Cluster Prometheus Exporter
<a name="component-configuration-ha-cluster-prometheus"></a>

定義 HA Cluster Prometheus Exporter 設定。

**JSON** 

```
"haClusterPrometheusExporter": {
    "prometheusPort": "Target port to emit Prometheus metrics"
}
```

**屬性**
+ **prometheusPort (選用)**

  要 Prometheus 要傳送指標的目標連接埠。如果未指定，則會使用預設連接埠 9664。

### NetWeaver Prometheus 匯出程式
<a name="component-configuration-netweaver-prometheus"></a>

定義 NetWeaver Prometheus 匯出程式設定。

**JSON** 

```
"netWeaverPrometheusExporter": {
    "sapSid": "SAP NetWeaver  SID",
    "instanceNumbers": [ "Array of instance Numbers of SAP NetWeaver system "],
"prometheusPort": "Target port to emit Prometheus metrics"
}
```

**屬性**
+ **sapSid**

  SAP NetWeaver 系統的三個字元 SAP 系統 ID (SID)。
+ **instanceNumbers**

  SAP NetWeaver 系統的執行個體編號陣列。

  **範例：**`"instanceNumbers": [ "00", "01"]`
+ **prometheusPort (選用)**

  將 Prometheus 指標傳送到的目標連接埠。如果未指定，則會使用預設連接埠 `9680`。

### SAP ASE Prometheus Exporter
<a name="component-configuration-sap-ase-prometheus"></a>

定義 SAP ASE Prometheus Exporter 設定。

**JSON** 

```
"sapASEPrometheusExporter": {
    "sapAseSid": "SAP ASE SID",
    "sapAsePort": "SAP ASE database port",
    "sapAseSecretName": "SAP ASE secret name",
    "prometheusPort": "Target port to emit Prometheus metrics",
    "agreeToEnableASEMonitoring": true
}
```

**屬性**
+ **sapAseSid**

  SAP ASE 系統的三個字元 SAP 系統 ID (SID)。
+ **sapAsePort**

  匯出工具會用來查詢 ASE 指標的 SAP ASE 資料庫連接埠。
+ **sapAseSecretName**

  存放 ASE 監控使用者登入資料的 AWS Secrets Manager 秘密。SAP ASE Prometheus 匯出工具會使用這些憑證來連線至資料庫並查詢 ASE 指標。
+ **prometheusPort (選用)**

  要 Prometheus 要傳送指標的目標連接埠。如果未指定，則會使用預設連接埠 9399。如果有另一個使用預設連接埠的 ASE 資料庫，則我們將使用 9499。

### Windows 事件
<a name="windows-events"></a>

定義欲記錄的 Windows 事件。

**JSON** 

```
{
  "logGroupName" : "logGroupName",
  "eventName" : "eventName",
  "eventLevels" : ["ERROR","WARNING","CRITICAL","INFORMATION","VERBOSE"],
  "monitor" : true/false
}
```

**屬性**
+ **logGroupName (必要)**

  要與受監控日誌關聯的 CloudWatch 日誌群組名稱。如需日誌群組名稱限制條件，請參閱 [CreateLogGroup](https://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_CreateLogGroup.html)。
+ **eventName (必要)**

  欲記錄的 Windows 事件類型。這和 Windows 事件日誌頻道名稱相同，例如 System、Security、CustomEventName 等。要記錄的每個 Windows 事件類型都需要此欄位。
+ **eventLevels (必要)**

  欲記錄的事件層級。您必須指定要記錄的每個層級。可能的值包括 `INFORMATION`、`WARNING`、`ERROR`、`CRITICAL` 及 `VERBOSE`。要記錄的每個 Windows 事件類型都需要此欄位。
+ **monitor (選用)**

  布林值，指出是否監控日誌。預設值為 `true`。

### 警示
<a name="component-configuration-alarms"></a>

定義要監控的元件 CloudWatch 警示。

**JSON** 

```
{
  "alarmName" : "monitoredAlarmName",
  "severity" : HIGH/MEDIUM/LOW
}
```

**屬性**
+ **警示名稱 (必填)**

  要監控的元件 CloudWatch 警示名稱。
+ **嚴重性 (選用)**

  指示警示影響的範圍程度。

# 元件組態範例
<a name="component-configuration-examples"></a>

以下範例顯示相關服務的 JSON 格式元件組態。

**Topics**
+ [Amazon DynamoDB 資料表](component-configuration-examples-dynamo.md)
+ [Amazon EC2 Auto Scaling (ASG)](component-configuration-examples-asg.md)
+ [Amazon EKS 叢集](component-configuration-examples-eks-cluster.md)
+ [Amazon Elastic Compute Cloud (EC2) 執行個體](component-configuration-examples-ec2.md)
+ [Amazon Elastic Container Service (Amazon ECS)](component-configuration-examples-ecs.md)
+ [Amazon ECS 服務](component-configuration-examples-ecs-service.md)
+ [Amazon ECS 任務](component-configuration-examples-ecs-task.md)
+ [Amazon Elastic File System (Amazon EFS)](component-configuration-examples-efs.md)
+ [Amazon FSx](component-configuration-examples-fsx.md)
+ [Amazon Relational Database Service (RDS) Aurora MySQL](component-configuration-examples-rds-aurora.md)
+ [Amazon Relational Database Service (RDS) 執行個體](component-configuration-examples-rds.md)
+ [Amazon Route 53 運作狀態檢查](component-configuration-examples-health-check.md)
+ [Amazon Route 53 託管區域](component-configuration-examples-hosted-zone.md)
+ [Amazon Route 53 Resolver endpoint](component-configuration-examples-resolver-endpoint.md)
+ [Amazon Route 53 Resolver 查詢記錄組態](component-configuration-examples-resolver-query-logging.md)
+ [Amazon S3 儲存貯體](component-configuration-examples-s3.md)
+ [Amazon Simple Queue Service (SQS)](component-configuration-examples-sqs.md)
+ [Amazon SNS 主題](component-configuration-examples-sns.md)
+ [Amazon Virtual Private Cloud (Amazon VPC)](component-configuration-examples-vpc.md)
+ [Amazon VPC 網路位址轉譯 (NAT) 閘道](component-configuration-examples-nat-gateway.md)
+ [API Gateway REST API 階段](component-configuration-examples-api-gateway.md)
+ [Application Elastic Load Balancing](component-configuration-examples-application-elb.md)
+ [AWS Lambda 函數](component-configuration-examples-lambda.md)
+ [AWS Network Firewall 規則群組](component-configuration-examples-firewall-rule-group.md)
+ [AWS Network Firewall 規則群組關聯](component-configuration-examples-firewall-rule-group-assoc.md)
+ [AWS Step Functions](component-configuration-examples-step-functions.md)
+ [客戶分組的 Amazon EC2 執行個體](component-configuration-examples-grouped-ec2.md)
+ [Elastic Load Balancing](component-configuration-examples-elb.md)
+ [Java](component-configuration-examples-java.md)
+ [Amazon EC2 上的 Kubernetes](component-configuration-examples-kubernetes-ec2.md)
+ [RDS MariaDB 和 RDS MySQL](component-configuration-examples-mysql.md)
+ [RDS Oracle](component-configuration-examples-oracle.md)
+ [RDS PostgreSQL](component-configuration-examples-rds-postgre-sql.md)
+ [Amazon EC2 上的 SAP ASE](component-configuration-examples-sap-ase.md)
+ [在 Amazon EC2 上的 SAP ASE 高可用性](component-configuration-examples-sap-ase-ha.md)
+ [Amazon EC2 上的 SAP HANA](component-configuration-examples-hana.md)
+ [在 Amazon EC2 上的 SAP HANA 高可用性](component-configuration-examples-hana-ha.md)
+ [Amazon EC2 上的 SAP NetWeaver](component-configuration-examples-netweaver.md)
+ [在 Amazon EC2 上的 SAP NetWeaver 高可用性](component-configuration-examples-netweaver-ha.md)
+ [SQL Always On 可用性群組](component-configuration-examples-sql.md)
+ [SQL 容錯移轉叢集執行個體](component-configuration-examples-sql-failover-cluster.md)

# Amazon DynamoDB 資料表
<a name="component-configuration-examples-dynamo"></a>

下列範例顯示 Amazon DynamoDB 資料表 JSON 格式的元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "SystemErrors",
      "monitor": false
    },
    {
      "alarmMetricName": "UserErrors",
      "monitor": false
    },
    {
      "alarmMetricName": "ConsumedReadCapacityUnits",
      "monitor": false
    },
    {
      "alarmMetricName": "ConsumedWriteCapacityUnits",
      "monitor": false
    },
    {
      "alarmMetricName": "ReadThrottleEvents",
      "monitor": false
    },
    {
      "alarmMetricName": "WriteThrottleEvents",
      "monitor": false
    },
    {
      "alarmMetricName": "ConditionalCheckFailedRequests",
      "monitor": false
    },
    {
      "alarmMetricName": "TransactionConflict",
      "monitor": false
    }
  ],
  "logs": []
}
```

# Amazon EC2 Auto Scaling (ASG)
<a name="component-configuration-examples-asg"></a>

下列範例顯示 Amazon EC2 Auto Scaling (ASG) JSON 格式的元件組態。

```
{
    "alarmMetrics" : [
      {
        "alarmMetricName" : "CPUCreditBalance"
      }, {
        "alarmMetricName" : "EBSIOBalance%"
      }
    ],
    "subComponents" : [
      {
        "subComponentType" : "AWS::EC2::Instance",
        "alarmMetrics" : [
          {
            "alarmMetricName" : "CPUUtilization"
          }, {
            "alarmMetricName" : "StatusCheckFailed"
          }
        ],
        "logs" : [
          {
            "logGroupName" : "my_log_group",
            "logPath" : "C:\\LogFolder\\*",
            "logType" : "APPLICATION"
          }
        ],
        "processes" : [
          {
            "processName" : "my_process",
            "alarmMetrics" : [
              {
                  "alarmMetricName" : "procstat cpu_usage",
                  "monitor" : true
              }, {
                  "alarmMetricName" : "procstat memory_rss",
                  "monitor" : true
              }
          ]
      }
  ],
        "windowsEvents" : [
          {
            "logGroupName" : "my_log_group_2",
            "eventName" : "Application",
            "eventLevels" : [ "ERROR", "WARNING", "CRITICAL" ]
          }
        ]
      }, {
        "subComponentType" : "AWS::EC2::Volume",
        "alarmMetrics" : [
          {
            "alarmMetricName" : "VolumeQueueLength"
          }, {
            "alarmMetricName" : "BurstBalance"
          }
        ]
      }
    ],
    "alarms" : [
      {
        "alarmName" : "my_asg_alarm",
        "severity" : "LOW"
      }
    ]
  }
```

# Amazon EKS 叢集
<a name="component-configuration-examples-eks-cluster"></a>

下列範例顯示 Amazon EKS 叢集 JSON 格式的元件組態。

```
{
    "alarmMetrics":[
       {
          "alarmMetricName": "cluster_failed_node_count",
          "monitor":true
       },
       {
          "alarmMetricName": "node_cpu_reserved_capacity",
          "monitor":true
       },
       {
          "alarmMetricName": "node_cpu_utilization",
          "monitor":true
       },
       {
          "alarmMetricName": "node_filesystem_utilization",
          "monitor":true
       },
       {
          "alarmMetricName": "node_memory_reserved_capacity",
          "monitor":true
       },
       {
          "alarmMetricName": "node_memory_utilization",
          "monitor":true
       },
       {
          "alarmMetricName": "node_network_total_bytes",
          "monitor":true
       },
       {
          "alarmMetricName": "pod_cpu_reserved_capacity",
          "monitor":true
       },
       {
          "alarmMetricName": "pod_cpu_utilization",
          "monitor":true
       },
       {
          "alarmMetricName": "pod_cpu_utilization_over_pod_limit",
          "monitor":true
       },
       {
          "alarmMetricName": "pod_memory_reserved_capacity",
          "monitor":true
       },
       {
          "alarmMetricName": "pod_memory_utilization",
          "monitor":true
       },
       {
          "alarmMetricName": "pod_memory_utilization_over_pod_limit",
          "monitor":true
       },
       {
          "alarmMetricName": "pod_network_rx_bytes",
          "monitor":true
       },
       {
          "alarmMetricName": "pod_network_tx_bytes",
          "monitor":true
       }
    ],
    "logs":[
       {
          "logGroupName": "/aws/containerinsights/kubernetes/application",
          "logType":"APPLICATION",
          "monitor":true,
          "encoding":"utf-8"
       }
    ],
    "subComponents":[
       {
          "subComponentType":"AWS::EC2::Instance",
          "alarmMetrics":[
             {
                "alarmMetricName":"CPUUtilization",
                "monitor":true
             },
             {
                "alarmMetricName":"StatusCheckFailed",
                "monitor":true
             },
             {
                "alarmMetricName":"disk_used_percent",
                "monitor":true
             },
             {
                "alarmMetricName":"mem_used_percent",
                "monitor":true
             }
          ],
          "logs":[
             {
                "logGroupName":"APPLICATION-KubernetesClusterOnEC2-IAD",
                "logPath":"",
                "logType":"APPLICATION",
                "monitor":true,
                "encoding":"utf-8"
             }
          ],
          "processes" : [
            {
                "processName" : "my_process",
                "alarmMetrics" : [
                    {
                        "alarmMetricName" : "procstat cpu_usage",
                        "monitor" : true
                    }, {
                        "alarmMetricName" : "procstat memory_rss",
                        "monitor" : true
                    }
                ]
            }
        ],
          "windowsEvents":[
             {
                "logGroupName":"my_log_group_2",
                "eventName":"Application",
                "eventLevels":[
                   "ERROR",
                   "WARNING",
                   "CRITICAL"
                ],
                "monitor":true
             }
          ]
       },
       {
          "subComponentType":"AWS::AutoScaling::AutoScalingGroup",
          "alarmMetrics":[
             {
                "alarmMetricName":"CPUCreditBalance",
                "monitor":true
             },
             {
                "alarmMetricName":"EBSIOBalance%",
                "monitor":true
             }
          ]
       },
       {
          "subComponentType":"AWS::EC2::Volume",
          "alarmMetrics":[
             {
                "alarmMetricName":"VolumeReadBytes",
                "monitor":true
             },
             {
                "alarmMetricName":"VolumeWriteBytes",
                "monitor":true
             },
             {
                "alarmMetricName":"VolumeReadOps",
                "monitor":true
             },
             {
                "alarmMetricName":"VolumeWriteOps",
                "monitor":true
             },
             {
                "alarmMetricName":"VolumeQueueLength",
                "monitor":true
             },
             {
                "alarmMetricName":"BurstBalance",
                "monitor":true
             }
          ]
       }
    ]
 }
```

**注意**  
`AWS::EC2::Instance`、`AWS::EC2::Volume` 和 `AWS::AutoScaling::AutoScalingGroup` 的 `subComponents` 區段僅適用於在 EC2 啟動類型上執行的 Amazon EKS 叢集。
`subComponents` 中的 `AWS::EC2::Instance` 的 `windowsEvents` 區段僅適用於在 Amazon EC2 執行個體上執行的 Windows。

# Amazon Elastic Compute Cloud (EC2) 執行個體
<a name="component-configuration-examples-ec2"></a>

下列範例顯示 Amazon EC2 執行個體 JSON 格式的元件組態。

**重要**  
當 Amazon EC2 執行個體進入 `stopped` 狀態時，系統便會將其從監控中移除。當其回到 `running` 狀態時，便會新增到在 CloudWatch Application Insights 主控台 **Application details** (應用程式詳細資訊) 頁面上的 **Unmonitored components** (未受監控的元件) 清單。如果為應用程序啟用對新資源的自動監控，則會將執行個體新增到 **Monitored components** (受監控的元件)。但是，系統會將工作負載的日誌和指標設為預設值。不會儲存先前的日誌和指標組態。

```
{
    "alarmMetrics" : [
      {
        "alarmMetricName" : "CPUUtilization",
        "monitor" : true
      }, {
        "alarmMetricName" : "StatusCheckFailed"
      }
    ],
    "logs" : [
      {
        "logGroupName" : "my_log_group",
        "logPath" : "C:\\LogFolder\\*",
        "logType" : "APPLICATION",
        "monitor" : true
      },
      {
        "logGroupName" : "my_log_group_2",
        "logPath" : "C:\\LogFolder2\\*",
        "logType" : "IIS",
        "encoding" : "utf-8"
      }
    ],
    "processes" : [
        {
            "processName" : "my_process",
            "alarmMetrics" : [
                {
                    "alarmMetricName" : "procstat cpu_usage",
                    "monitor" : true
                }, {
                    "alarmMetricName" : "procstat memory_rss",
                    "monitor" : true
                }
            ]
        }
    ],
    "windowsEvents" : [
      {
        "logGroupName" : "my_log_group_3",
        "eventName" : "Application",
        "eventLevels" : [ "ERROR", "WARNING", "CRITICAL" ],
        "monitor" : true
      }, {
        "logGroupName" : "my_log_group_4",
        "eventName" : "System",
        "eventLevels" : [ "ERROR", "WARNING", "CRITICAL" ],
        "monitor" : true
    }],
     "alarms" : [
      {
        "alarmName" : "my_instance_alarm_1",
        "severity" : "HIGH"
      },
      {
        "alarmName" : "my_instance_alarm_2",
        "severity" : "LOW"
      }
    ],
     "subComponents" : [
     {
       "subComponentType" : "AWS::EC2::Volume",
       "alarmMetrics" : [
       {
         "alarmMetricName" : "VolumeQueueLength",
         "monitor" : "true"
       },
       {
         "alarmMetricName" : "VolumeThroughputPercentage",
         "monitor" : "true"
       },
       {
         "alarmMetricName" : "BurstBalance",
         "monitor" : "true"
       }]
    }]
  }
```

# Amazon Elastic Container Service (Amazon ECS)
<a name="component-configuration-examples-ecs"></a>

下列範例顯示 Amazon Elastic Container Service (Amazon ECS) JSON 格式的元件組態。

```
{
    "alarmMetrics":[
       {
          "alarmMetricName":"CpuUtilized",
          "monitor":true
       },
       {
          "alarmMetricName":"MemoryUtilized",
          "monitor":true
       },
       {
          "alarmMetricName":"NetworkRxBytes",
          "monitor":true
       },
       {
          "alarmMetricName":"NetworkTxBytes",
          "monitor":true
       },
       {
          "alarmMetricName":"RunningTaskCount",
          "monitor":true
       },
       {
          "alarmMetricName":"PendingTaskCount",
          "monitor":true
       },
       {
          "alarmMetricName":"StorageReadBytes",
          "monitor":true
       },
       {
          "alarmMetricName":"StorageWriteBytes",
          "monitor":true
       }
    ],
    "logs":[
       {
          "logGroupName":"/ecs/my-task-definition",
          "logType":"APPLICATION",
          "monitor":true
       }
    ],
    "subComponents":[
       {
          "subComponentType":"AWS::ElasticLoadBalancing::LoadBalancer",
          "alarmMetrics":[
             {
                "alarmMetricName":"HTTPCode_Backend_4XX",
                "monitor":true
             },
             {
                "alarmMetricName":"HTTPCode_Backend_5XX",
                "monitor":true
             },
             {
                "alarmMetricName":"Latency",
                "monitor":true
             },
             {
                "alarmMetricName":"SurgeQueueLength",
                "monitor":true
             },
             {
                "alarmMetricName":"UnHealthyHostCount",
                "monitor":true
             }
          ]
       },
       {
          "subComponentType":"AWS::ElasticLoadBalancingV2::LoadBalancer",
          "alarmMetrics":[
             {
                "alarmMetricName":"HTTPCode_Target_4XX_Count",
                "monitor":true
             },
             {
                "alarmMetricName":"HTTPCode_Target_5XX_Count",
                "monitor":true
             },
             {
                "alarmMetricName":"TargetResponseTime",
                "monitor":true
             },
             {
                "alarmMetricName":"UnHealthyHostCount",
                "monitor":true
             }
          ]
       },
       {
          "subComponentType":"AWS::EC2::Instance",
          "alarmMetrics":[
             {
                "alarmMetricName":"CPUUtilization",
                "monitor":true
             },
             {
                "alarmMetricName":"StatusCheckFailed",
                "monitor":true
             },
             {
                "alarmMetricName":"disk_used_percent",
                "monitor":true
             },
             {
                "alarmMetricName":"mem_used_percent",
                "monitor":true
             }
          ],
          "logs":[
             {
                "logGroupName":"my_log_group",
                "logPath":"/mylog/path",
                "logType":"APPLICATION",
                "monitor":true
             }
          ],
          "processes" : [
             {
                "processName" : "my_process",
                "alarmMetrics" : [
                    {
                        "alarmMetricName" : "procstat cpu_usage",
                        "monitor" : true
                    }, {
                        "alarmMetricName" : "procstat memory_rss",
                        "monitor" : true
                    }
                 ]
             }
          ],
          "windowsEvents":[
             {
                "logGroupName":"my_log_group_2",
                "eventName":"Application",
                "eventLevels":[
                   "ERROR",
                   "WARNING",
                   "CRITICAL"
                ],
                "monitor":true
             }
          ]
       },
       {
          "subComponentType":"AWS::EC2::Volume",
          "alarmMetrics":[
             {
                "alarmMetricName":"VolumeQueueLength",
                "monitor":"true"
             },
             {
                "alarmMetricName":"VolumeThroughputPercentage",
                "monitor":"true"
             },
             {
                "alarmMetricName":"BurstBalance",
                "monitor":"true"
             }
          ]
       }
    ]
 }
```

**注意**  
`AWS::EC2::Instance` 和 `AWS::EC2::Volume` 的 `subComponents` 區段僅適用於具有在 EC2 啟動類型上執行的 ECS 服務或 ECS 任務的 Amazon ECS 叢集。
`subComponents` 中的 `AWS::EC2::Instance` 的 `windowsEvents` 區段僅適用於在 Amazon EC2 執行個體上執行的 Windows。

# Amazon ECS 服務
<a name="component-configuration-examples-ecs-service"></a>

下列範例顯示 Amazon ECS 服務 JSON 格式的元件組態。

```
{
    "alarmMetrics":[
       {
          "alarmMetricName":"CPUUtilization",
          "monitor":true
       },
       {
          "alarmMetricName":"MemoryUtilization",
          "monitor":true
       },
       {
          "alarmMetricName":"CpuUtilized",
          "monitor":true
       },
       {
          "alarmMetricName":"MemoryUtilized",
          "monitor":true
       },
       {
          "alarmMetricName":"NetworkRxBytes",
          "monitor":true
       },
       {
          "alarmMetricName":"NetworkTxBytes",
          "monitor":true
       },
       {
          "alarmMetricName":"RunningTaskCount",
          "monitor":true
       },
       {
          "alarmMetricName":"PendingTaskCount",
          "monitor":true
       },
       {
          "alarmMetricName":"StorageReadBytes",
          "monitor":true
       },
       {
          "alarmMetricName":"StorageWriteBytes",
          "monitor":true
       }
    ],
    "logs":[
       {
          "logGroupName":"/ecs/my-task-definition",
          "logType":"APPLICATION",
          "monitor":true
       }
    ],
    "subComponents":[
       {
          "subComponentType":"AWS::ElasticLoadBalancing::LoadBalancer",
          "alarmMetrics":[
             {
                "alarmMetricName":"HTTPCode_Backend_4XX",
                "monitor":true
             },
             {
                "alarmMetricName":"HTTPCode_Backend_5XX",
                "monitor":true
             },
             {
                "alarmMetricName":"Latency",
                "monitor":true
             },
             {
                "alarmMetricName":"SurgeQueueLength",
                "monitor":true
             },
             {
                "alarmMetricName":"UnHealthyHostCount",
                "monitor":true
             }
          ]
       },
       {
          "subComponentType":"AWS::ElasticLoadBalancingV2::LoadBalancer",
          "alarmMetrics":[
             {
                "alarmMetricName":"HTTPCode_Target_4XX_Count",
                "monitor":true
             },
             {
                "alarmMetricName":"HTTPCode_Target_5XX_Count",
                "monitor":true
             },
             {
                "alarmMetricName":"TargetResponseTime",
                "monitor":true
             },
             {
                "alarmMetricName":"UnHealthyHostCount",
                "monitor":true
             }
          ]
       },
       {
          "subComponentType":"AWS::EC2::Instance",
          "alarmMetrics":[
             {
                "alarmMetricName":"CPUUtilization",
                "monitor":true
             },
             {
                "alarmMetricName":"StatusCheckFailed",
                "monitor":true
             },
             {
                "alarmMetricName":"disk_used_percent",
                "monitor":true
             },
             {
                "alarmMetricName":"mem_used_percent",
                "monitor":true
             }
          ],
          "logs":[
             {
                "logGroupName":"my_log_group",
                "logPath":"/mylog/path",
                "logType":"APPLICATION",
                "monitor":true
             }
          ],
          "processes" : [
             {
                "processName" : "my_process",
                "alarmMetrics" : [
                {
                    "alarmMetricName" : "procstat cpu_usage",
                    "monitor" : true
                }, {
                    "alarmMetricName" : "procstat memory_rss",
                    "monitor" : true
                }
            ]
        }
    ],
          "windowsEvents":[
             {
                "logGroupName":"my_log_group_2",
                "eventName":"Application",
                "eventLevels":[
                   "ERROR",
                   "WARNING",
                   "CRITICAL"
                ],
                "monitor":true
             }
          ]
       },
       {
          "subComponentType":"AWS::EC2::Volume",
          "alarmMetrics":[
             {
                "alarmMetricName":"VolumeQueueLength",
                "monitor":"true"
             },
             {
                "alarmMetricName":"VolumeThroughputPercentage",
                "monitor":"true"
             },
             {
                "alarmMetricName":"BurstBalance",
                "monitor":"true"
             }
          ]
       }
    ]
 }
```

**注意**  
`AWS::EC2::Instance` 和 `AWS::EC2::Volume` 的 `subComponents` 區段僅適用於在 EC2 啟動類型上執行的 Amazon ECS。
`subComponents` 中的 `AWS::EC2::Instance` 的 `windowsEvents` 區段僅適用於在 Amazon EC2 執行個體上執行的 Windows。

# Amazon ECS 任務
<a name="component-configuration-examples-ecs-task"></a>

下列範例顯示 Amazon ECS 任務 JSON 格式的元件組態。

```
{
    "logs":[
       {
          "logGroupName":"/ecs/my-task-definition",
          "logType":"APPLICATION",
          "monitor":true
       }
    ],
    "processes" : [
        {
            "processName" : "my_process",
            "alarmMetrics" : [
                {
                    "alarmMetricName" : "procstat cpu_usage",
                    "monitor" : true
                }, {
                    "alarmMetricName" : "procstat memory_rss",
                    "monitor" : true
                }
            ]
        }
    ]
 }
```

# Amazon Elastic File System (Amazon EFS)
<a name="component-configuration-examples-efs"></a>

下列範例顯示 Amazon EFS JSON 格式的元件組態。

```
{
   "alarmMetrics": [
     {
       "alarmMetricName": "BurstCreditBalance",
       "monitor": true
     },
     {
       "alarmMetricName": "PercentIOLimit",
       "monitor": true
     },
     {
       "alarmMetricName": "PermittedThroughput",
       "monitor": true
     },
     {
       "alarmMetricName": "MeteredIOBytes",
       "monitor": true
     },
     {
       "alarmMetricName": "TotalIOBytes",
       "monitor": true
     },
     {
       "alarmMetricName": "DataWriteIOBytes",
       "monitor": true
     },
     {
       "alarmMetricName": "DataReadIOBytes",
       "monitor": true
     },
     {
       "alarmMetricName": "MetadataIOBytes",
       "monitor": true
     },
     {
       "alarmMetricName": "ClientConnections",
       "monitor": true
     },
     {
       "alarmMetricName": "TimeSinceLastSync",
       "monitor": true
     },
     {
       "alarmMetricName": "Throughput",
       "monitor": true
     },
     {
       "alarmMetricName": "PercentageOfPermittedThroughputUtilization",
       "monitor": true
     },
     {
       "alarmMetricName": "ThroughputIOPS",
       "monitor": true
     },
     {
       "alarmMetricName": "PercentThroughputDataReadIOBytes",
       "monitor": true
     },
     {
       "alarmMetricName": "PercentThroughputDataWriteIOBytes",
       "monitor": true
     },
     {
       "alarmMetricName": "PercentageOfIOPSDataReadIOBytes",
       "monitor": true
     },
     {
       "alarmMetricName": "PercentageOfIOPSDataWriteIOBytes",
       "monitor": true
     },
     {
       "alarmMetricName": "AverageDataReadIOBytesSize",
       "monitor": true
     },
     {
       "alarmMetricName": "AverageDataWriteIOBytesSize",
       "monitor": true
     }
   ],
   "logs": [
    {
    "logGroupName": "/aws/efs/utils",
    "logType": "EFS_MOUNT_STATUS",
    "monitor": true,
    }
   ]
 }
```

# Amazon FSx
<a name="component-configuration-examples-fsx"></a>

下列範例顯示 Amazon FSx JSON 格式的元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "DataReadBytes",
      "monitor": true
    },
    {
      "alarmMetricName": "DataWriteBytes",
      "monitor": true
    },
    {
      "alarmMetricName": "DataReadOperations",
      "monitor": true
    },
    {
      "alarmMetricName": "DataWriteOperations",
      "monitor": true
    },
    {
      "alarmMetricName": "MetadataOperations",
      "monitor": true
    },
    {
      "alarmMetricName": "FreeStorageCapacity",
      "monitor": true
    }
  ]
}
```

# Amazon Relational Database Service (RDS) Aurora MySQL
<a name="component-configuration-examples-rds-aurora"></a>

下列範例顯示 Amazon RDS Aurora MySQL 執行個體 JSON 格式的元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "CPUUtilization",
      "monitor": true
    },
    {
      "alarmMetricName": "CommitLatency",
      "monitor": true
    }
  ],
  "logs": [
    {
      "logType": "MYSQL",
      "monitor": true,
    },
    {
      "logType": "MYSQL_SLOW_QUERY",
      "monitor": false
    }
  ]
}
```

# Amazon Relational Database Service (RDS) 執行個體
<a name="component-configuration-examples-rds"></a>

下列範例顯示 Amazon RDS 執行個體 JSON 格式的元件組態。

```
{
  "alarmMetrics" : [
    {
      "alarmMetricName" : "BurstBalance",
      "monitor" : true
    }, {
      "alarmMetricName" : "WriteThroughput",
      "monitor" : false
    }
  ],

  "alarms" : [
    {
      "alarmName" : "my_rds_instance_alarm",
      "severity" : "MEDIUM"
    }
  ]
}
```

# Amazon Route 53 運作狀態檢查
<a name="component-configuration-examples-health-check"></a>

下列範例顯示 Amazon Route 53 運作狀態檢查的 JSON 格式元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "ChildHealthCheckHealthyCount",
      "monitor": true
    },
    {
      "alarmMetricName": "ConnectionTime",
      "monitor": true
    },
    {
      "alarmMetricName": "HealthCheckPercentageHealthy",
      "monitor": true
    },
    {
      "alarmMetricName": "HealthCheckStatus",
      "monitor": true
    },
    {
      "alarmMetricName": "SSLHandshakeTime",
      "monitor": true
    },
    {
      "alarmMetricName": "TimeToFirstByte",
      "monitor": true
    }
  ]  
}
```

# Amazon Route 53 託管區域
<a name="component-configuration-examples-hosted-zone"></a>

下列範例顯示 Amazon Route 53 託管區域 的 JSON 格式元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "DNSQueries",
      "monitor": true
    },
    {
      "alarmMetricName": "DNSSECInternalFailure",
      "monitor": true
    },
    {
      "alarmMetricName": "DNSSECKeySigningKeysNeedingAction",
      "monitor": true
    },
    {
      "alarmMetricName": "DNSSECKeySigningKeyMaxNeedingActionAge",
      "monitor": true
    },
    {
      "alarmMetricName": "DNSSECKeySigningKeyAge",
      "monitor": true
    }
  ],
  "logs": [
    {
      "logGroupName":"/hosted-zone/logs",
      "logType": "ROUTE53_DNS_PUBLIC_QUERY_LOGS",
      "monitor": true
    }
  ]
}
```

# Amazon Route 53 Resolver endpoint
<a name="component-configuration-examples-resolver-endpoint"></a>

下列範例顯示 Amazon Route 53 Resolver 端點的 JSON 格式元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "EndpointHealthyENICount",
      "monitor": true
    },
    {
      "alarmMetricName": "EndpointUnHealthyENICount",
      "monitor": true
    },
    {
      "alarmMetricName": "InboundQueryVolume",
      "monitor": true
    },
    {
      "alarmMetricName": "OutboundQueryVolume",
      "monitor": true
    },
    {
      "alarmMetricName": "OutboundQueryAggregateVolume",
      "monitor": true
    }
  ]  
}
```

# Amazon Route 53 Resolver 查詢記錄組態
<a name="component-configuration-examples-resolver-query-logging"></a>

下列範例顯示 Amazon Route 53 Resolver 查詢日誌記錄組態的 JSON 格式元件組態。

```
{
  "logs": [
    {
      "logGroupName": "/resolver-query-log-config/logs",
      "logType": "ROUTE53_RESOLVER_QUERY_LOGS",
      "monitor": true
    }
  ]  
}
```

# Amazon S3 儲存貯體
<a name="component-configuration-examples-s3"></a>

下列範例顯示 Amazon S3 儲存貯體 JSON 格式的元件組態。

```
{
    "alarmMetrics" : [
        {
            "alarmMetricName" : "ReplicationLatency",
            "monitor" : true
        }, {
            "alarmMetricName" : "5xxErrors",
            "monitor" : true
        }, {
            "alarmMetricName" : "BytesDownloaded"
            "monitor" : true
        }
    ]
}
```

# Amazon Simple Queue Service (SQS)
<a name="component-configuration-examples-sqs"></a>

下列範例顯示 Amazon Simple Queue Service JSON 格式的元件組態。

```
{
  "alarmMetrics" : [
    {
      "alarmMetricName" : "ApproximateAgeOfOldestMessage"
    }, {
      "alarmMetricName" : "NumberOfEmptyReceives"
    }
  ],
  "alarms" : [
    {
      "alarmName" : "my_sqs_alarm",
      "severity" : "MEDIUM"
    }
  ]
}
```

# Amazon SNS 主題
<a name="component-configuration-examples-sns"></a>

下列範例顯示 Amazon SNS 主題 JSON 格式的元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "NumberOfNotificationsFailed",
      "monitor": true
    },
    {
      "alarmMetricName": "NumberOfNotificationsFilteredOut-InvalidAttributes",
      "monitor": true
    },
    {
      "alarmMetricName": "NumberOfNotificationsFilteredOut-NoMessageAttributes",
      "monitor": true
    },
    {
      "alarmMetricName": "NumberOfNotificationsFailedToRedriveToDlq",
      "monitor": true
    }
  ]
}
```

# Amazon Virtual Private Cloud (Amazon VPC)
<a name="component-configuration-examples-vpc"></a>

下列範例顯示 Amazon VPC 的 JSON 格式元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "NetworkAddressUsage",
      "monitor": true
    },
    {
      "alarmMetricName": "NetworkAddressUsagePeered",
      "monitor": true
    },
    {
      "alarmMetricName": "VPCFirewallQueryVolume",
      "monitor": true
    }
  ]
}
```

# Amazon VPC 網路位址轉譯 (NAT) 閘道
<a name="component-configuration-examples-nat-gateway"></a>

下列範例顯示 NAT 閘道的 JSON 格式元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "ErrorPortAllocation",
      "monitor": true
    },
    {
      "alarmMetricName": "IdleTimeoutCount",
      "monitor": true
    }
  ]
}
```

# API Gateway REST API 階段
<a name="component-configuration-examples-api-gateway"></a>

下列範例顯示 API Gateway REST API 階段 JSON 格式的元件組態。

```
{ 
     "alarmMetrics" : [ 
         {
             "alarmMetricName" : "4XXError",   
             "monitor" : true
         }, 
         {
             "alarmMetricName" : "5XXError",   
             "monitor" : true
         } 
     ],
    "logs" : [
        { 
            "logType" : "API_GATEWAY_EXECUTION",   
            "monitor" : true  
        },
        { 
            "logType" : "API_GATEWAY_ACCESS",   
            "monitor" : true  
        }
    ]
}
```

# Application Elastic Load Balancing
<a name="component-configuration-examples-application-elb"></a>

下列範例顯示 Application Elastic Load Balancing JSON 格式的元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "ActiveConnectionCount",
    }, {
      "alarmMetricName": "TargetResponseTime"
    }
  ],  
  "subComponents": [
    {
      "subComponentType": "AWS::EC2::Instance",
      "alarmMetrics": [
        {
          "alarmMetricName": "CPUUtilization",
        }, {
          "alarmMetricName": "StatusCheckFailed"
        }
      ],
      "logs": [
        {
          "logGroupName": "my_log_group",
          "logPath": "C:\\LogFolder\\*",
          "logType": "APPLICATION",
        }
      ],
      "windowsEvents": [
        {
          "logGroupName": "my_log_group_2",
          "eventName": "Application",
          "eventLevels": [ "ERROR", "WARNING", "CRITICAL" ]
        }
      ]
    }, {
      "subComponentType": "AWS::EC2::Volume",
      "alarmMetrics": [
        {
          "alarmMetricName": "VolumeQueueLength",
        }, {
          "alarmMetricName": "BurstBalance"
        }
      ]
    }
  ],

  "alarms": [
    {
      "alarmName": "my_alb_alarm",
      "severity": "LOW"
    }
  ]
}
```

# AWS Lambda 函數
<a name="component-configuration-examples-lambda"></a>

下列範例顯示 AWS Lambda Function JSON 格式的元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "Errors",
      "monitor": true
    },
    {
      "alarmMetricName": "Throttles",
      "monitor": true
    },
    {
      "alarmMetricName": "IteratorAge",
      "monitor": true
    },
    {
      "alarmMetricName": "Duration",
      "monitor": true
    }
  ],
  "logs": [
    {
      "logType": "DEFAULT",
      "monitor": true
    }
  ]
}
```

# AWS Network Firewall 規則群組
<a name="component-configuration-examples-firewall-rule-group"></a>

下列範例顯示 AWS Network Firewall 規則群組的 JSON 格式元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "FirewallRuleGroupQueryVolume",
      "monitor": true
    }
  ]
}
```

# AWS Network Firewall 規則群組關聯
<a name="component-configuration-examples-firewall-rule-group-assoc"></a>

下列範例顯示 AWS Network Firewall 規則群組關聯的 JSON 格式元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "FirewallRuleGroupQueryVolume",
      "monitor": true
    }
  ]
}
```

# AWS Step Functions
<a name="component-configuration-examples-step-functions"></a>

下列範例顯示 AWS Step Functions JSON 格式的元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "ExecutionsFailed",
      "monitor": true
    },
    {
      "alarmMetricName": "LambdaFunctionsFailed",
      "monitor": true
    },
    {
      "alarmMetricName": "ProvisionedRefillRate",
      "monitor": true
    }
  ],
  "logs": [
    {
     "logGroupName": "/aws/states/HelloWorld-Logs",
      "logType": "STEP_FUNCTION",
      "monitor": true,
    }
  ]
}
```

# 客戶分組的 Amazon EC2 執行個體
<a name="component-configuration-examples-grouped-ec2"></a>

下列範例顯示客戶分組之 Amazon EC2 執行個體 JSON 格式的元件組態。

```
{
    "subComponents": [
      {
        "subComponentType": "AWS::EC2::Instance",
        "alarmMetrics": [
          {
            "alarmMetricName": "CPUUtilization",
          }, 
          {
            "alarmMetricName": "StatusCheckFailed"
          }
        ],
        "logs": [
          {
            "logGroupName": "my_log_group",
            "logPath": "C:\\LogFolder\\*",
            "logType": "APPLICATION",
          }
        ],
        "processes": [
            {
                "processName": "my_process",
                "alarmMetrics": [
                    {
                        "alarmMetricName": "procstat cpu_usage",
                        "monitor": true
                    }, {
                        "alarmMetricName": "procstat memory_rss",
                        "monitor": true
                    }
                ]
            }
        ],
        "windowsEvents": [
          {
            "logGroupName": "my_log_group_2",
            "eventName": "Application",
            "eventLevels": [ "ERROR", "WARNING", "CRITICAL" ]
          }
        ]
      }, {
        "subComponentType": "AWS::EC2::Volume",
        "alarmMetrics": [
          {
            "alarmMetricName": "VolumeQueueLength",
          }, {
            "alarmMetricName": "BurstBalance"
          }
        ]
      }
    ],
    "alarms": [
      {
        "alarmName": "my_alarm",
        "severity": "MEDIUM"
      }
    ]
  }
```

# Elastic Load Balancing
<a name="component-configuration-examples-elb"></a>

下列範例顯示 Elastic Load Balancing JSON 格式的元件組態。

```
{
    "alarmMetrics": [
      {
        "alarmMetricName": "EstimatedALBActiveConnectionCount"
      }, {
        "alarmMetricName": "HTTPCode_Backend_5XX"
      }
    ],
    "subComponents": [
      {
        "subComponentType": "AWS::EC2::Instance",
        "alarmMetrics": [
          {
            "alarmMetricName": "CPUUtilization"
          }, {
            "alarmMetricName": "StatusCheckFailed"
          }
        ],
        "logs": [
          {
            "logGroupName": "my_log_group",
            "logPath": "C:\\LogFolder\\*",
            "logType": "APPLICATION"
          }
        ],
        "processes": [
          {
            "processName": "my_process",
            "alarmMetrics": [
                {
                  "alarmMetricName": "procstat cpu_usage",
                  "monitor": true
                }, {
                  "alarmMetricName": "procstat memory_rss",
                  "monitor": true
                }
              ]
          }
        ],
        "windowsEvents": [
          {
            "logGroupName": "my_log_group_2",
            "eventName": "Application",
            "eventLevels": [ "ERROR", "WARNING", "CRITICAL" ],
            "monitor": true
          }
        ]
      }, {
        "subComponentType": "AWS::EC2::Volume",
        "alarmMetrics": [
          {
            "alarmMetricName": "VolumeQueueLength"
          }, {
            "alarmMetricName": "BurstBalance"
          }
        ]
      }
    ],
  
    "alarms": [
      {
        "alarmName": "my_elb_alarm",
        "severity": "HIGH"
      }
    ]
  }
```

# Java
<a name="component-configuration-examples-java"></a>

下列範例顯示 Java JSON 格式的元件組態。

```
{
  "alarmMetrics": [ {
    "alarmMetricName": "java_lang_threading_threadcount",
    "monitor": true
  },
  {
    "alarmMetricName": "java_lang_memory_heapmemoryusage_used",
    "monitor": true
  },
  {
    "alarmMetricName": "java_lang_memory_heapmemoryusage_committed",
    "monitor": true
  }],
  "logs": [ ],
  "JMXPrometheusExporter": {
      "hostPort": "8686",
      "prometheusPort": "9404"
  }
}
```

**注意**  
Application Insights 不支援為 Prometheus JMX Exporter 設定身分驗證。如需如何設定身分驗證的資訊，請參閱 [Prometheus JMX Exporter 範例組態](https://github.com/prometheus/jmx_exporter#configuration)。

# Amazon EC2 上的 Kubernetes
<a name="component-configuration-examples-kubernetes-ec2"></a>

下列範例顯示 Amazon EC2 上 Kubernetes JSON 格式的元件組態。

```
{
    "alarmMetrics":[
       {
          "alarmMetricName":"cluster_failed_node_count",
          "monitor":true
       },
       {
          "alarmMetricName":"node_cpu_reserved_capacity",
          "monitor":true
       },
       {
          "alarmMetricName":"node_cpu_utilization",
          "monitor":true
       },
       {
          "alarmMetricName":"node_filesystem_utilization",
          "monitor":true
       },
       {
          "alarmMetricName":"node_memory_reserved_capacity",
          "monitor":true
       },
       {
          "alarmMetricName":"node_memory_utilization",
          "monitor":true
       },
       {
          "alarmMetricName":"node_network_total_bytes",
          "monitor":true
       },
       {
          "alarmMetricName":"pod_cpu_reserved_capacity",
          "monitor":true
       },
       {
          "alarmMetricName":"pod_cpu_utilization",
          "monitor":true
       },
       {
          "alarmMetricName":"pod_cpu_utilization_over_pod_limit",
          "monitor":true
       },
       {
          "alarmMetricName":"pod_memory_reserved_capacity",
          "monitor":true
       },
       {
          "alarmMetricName":"pod_memory_utilization",
          "monitor":true
       },
       {
          "alarmMetricName":"pod_memory_utilization_over_pod_limit",
          "monitor":true
       },
       {
          "alarmMetricName":"pod_network_rx_bytes",
          "monitor":true
       },
       {
          "alarmMetricName":"pod_network_tx_bytes",
          "monitor":true
       }
    ],
    "logs":[
       {
          "logGroupName":"/aws/containerinsights/kubernetes/application",
          "logType":"APPLICATION",
          "monitor":true,
          "encoding":"utf-8"
       }
    ],
    "subComponents":[
       {
          "subComponentType":"AWS::EC2::Instance",
          "alarmMetrics":[
             {
                "alarmMetricName":"CPUUtilization",
                "monitor":true
             },
             {
                "alarmMetricName":"StatusCheckFailed",
                "monitor":true
             },
             {
                "alarmMetricName":"disk_used_percent",
                "monitor":true
             },
             {
                "alarmMetricName":"mem_used_percent",
                "monitor":true
             }
          ],
          "logs":[
             {
                "logGroupName":"APPLICATION-KubernetesClusterOnEC2-IAD",
                "logPath":"",
                "logType":"APPLICATION",
                "monitor":true,
                "encoding":"utf-8"
             }
          ],
          "processes" : [
            {
                "processName" : "my_process",
                "alarmMetrics" : [
                    {
                        "alarmMetricName" : "procstat cpu_usage",
                        "monitor" : true
                    }, {
                        "alarmMetricName" : "procstat memory_rss",
                        "monitor" : true
                    }
                ]
            }
        ]
       },
       {
          "subComponentType":"AWS::EC2::Volume",
          "alarmMetrics":[
             {
                "alarmMetricName":"VolumeReadBytes",
                "monitor":true
             },
             {
                "alarmMetricName":"VolumeWriteBytes",
                "monitor":true
             },
             {
                "alarmMetricName":"VolumeReadOps",
                "monitor":true
             },
             {
                "alarmMetricName":"VolumeWriteOps",
                "monitor":true
             },
             {
                "alarmMetricName":"VolumeQueueLength",
                "monitor":true
             },
             {
                "alarmMetricName":"BurstBalance",
                "monitor":true
             }
          ]
       }
    ]
 }
```

# RDS MariaDB 和 RDS MySQL
<a name="component-configuration-examples-mysql"></a>

下列範例顯示 RDS MariaDB 和 RDS MySQL 之 JSON 格式的元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "CPUUtilization",
      "monitor": true
    }
  ],
  "logs": [
    {
      "logType": "MYSQL",
      "monitor": true,
    },
    {
      "logType": "MYSQL_SLOW_QUERY",
      "monitor": false
    }
  ]
}
```

# RDS Oracle
<a name="component-configuration-examples-oracle"></a>

下列範例顯示 RDS Oracle 執行個體 JSON 格式的元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "CPUUtilization",
      "monitor": true
    }
  ],
  "logs": [
    {
      "logType": "ORACLE_ALERT",
      "monitor": true,
    },
    {
      "logType": "ORACLE_LISTENER",
      "monitor": false
    }
  ]
}
```

# RDS PostgreSQL
<a name="component-configuration-examples-rds-postgre-sql"></a>

下列範例顯示 RDS PostgreSQL JSON 格式的元件組態。

```
{
  "alarmMetrics": [
    {
      "alarmMetricName": "CPUUtilization",
      "monitor": true
    }
  ],
  "logs": [
    {
      "logType": "POSTGRESQL",
      "monitor": true
    }
  ]
}
```

# Amazon EC2 上的 SAP ASE
<a name="component-configuration-examples-sap-ase"></a>

下列範例顯示 Amazon EC2 上 SAP ASE JSON 格式的元件組態。

```
{
  "subComponents": [
    {
      "subComponentType": "AWS::EC2::Instance",
      "alarmMetrics": [
        {
          "alarmMetricName": "asedb_database_availability",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_trunc_log_on_chkpt_enabled",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_last_db_backup_age_in_days",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_last_transaction_log_backup_age_in_hours",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_suspected_database",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_db_space_usage_percent",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_db_log_space_usage_percent",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_locked_login",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_data_cache_hit_ratio",
          "monitor": true
        }
      ],
      "logs": [
        {
          "logGroupName": "SAP_ASE_SERVER_LOGS-my-resource-group",
          "logPath": "/sybase/SY2/ASE-*/install/SY2.log",
          "logType": "SAP_ASE_SERVER_LOGS",
          "monitor": true,
          "encoding": "utf-8"
        },
        {
          "logGroupName": "SAP_ASE_BACKUP_SERVER_LOGS-my-resource-group",
          "logPath": "/sybase/SY2/ASE-*/install/SY2_BS.log",
          "logType": "SAP_ASE_BACKUP_SERVER_LOGS",
          "monitor": true,
          "encoding": "utf-8"
        }
  ],
  "sapAsePrometheusExporter": {
    "sapAseSid": "ASE",
    "sapAsePort": "4901",
    "sapAseSecretName": "ASE_DB_CREDS",
    "prometheusPort": "9399",
    "agreeToEnableASEMonitoring": true
}
```

# 在 Amazon EC2 上的 SAP ASE 高可用性
<a name="component-configuration-examples-sap-ase-ha"></a>

下列範例顯示在 Amazon EC2 上的 SAP ASE 高可用性 JSON 格式的元件組態。

```
{
  "subComponents": [
    {
      "subComponentType": "AWS::EC2::Instance",
      "alarmMetrics": [
        {
          "alarmMetricName": "asedb_database_availability",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_trunc_log_on_chkpt_enabled",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_last_db_backup_age_in_days",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_last_transaction_log_backup_age_in_hours",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_suspected_database",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_db_space_usage_percent",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_ha_replication_state",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_ha_replication_mode",
          "monitor": true
        },
        {
          "alarmMetricName": "asedb_ha_replication_latency_in_minutes",
          "monitor": true
        }
      ],
      "logs": [
        {
          "logGroupName": "SAP_ASE_SERVER_LOGS-my-resource-group",
          "logPath": "/sybase/SY2/ASE-*/install/SY2.log",
          "logType": "SAP_ASE_SERVER_LOGS",
          "monitor": true,
          "encoding": "utf-8"
        },
        {
          "logGroupName": "SAP_ASE_BACKUP_SERVER_LOGS-my-resource-group",
          "logPath": "/sybase/SY2/ASE-*/install/SY2_BS.log",
          "logType": "SAP_ASE_BACKUP_SERVER_LOGS",
          "monitor": true,
          "encoding": "utf-8"
        },
        {
          "logGroupName": "SAP_ASE_REP_SERVER_LOGS-my-resource-group",
          "logPath": "/sybase/SY2/DM/repservername/repservername.log",
          "logType": "SAP_ASE_REP_SERVER_LOGS",
          "monitor": true,
          "encoding": "utf-8"
        },
        {
          "logGroupName": "SAP_ASE_RMA_AGENT_LOGS-my-resource-group",
          "logPath": "/sybase/SY2/DM/RMA-*/instances/AgentContainer/logs/",
          "logType": "SAP_ASE_RMA_AGENT_LOGS",
          "monitor": true,
          "encoding": "utf-8"
        },
        {
          "logGroupName": "SAP_ASE_FAULT_MANAGER_LOGS-my-resource-group",
          "logPath": "/opt/sap/FaultManager/dev_sybdbfm",
          "logType": "SAP_ASE_FAULT_MANAGER_LOGS",
          "monitor": true,
          "encoding": "utf-8"
        }
  ],
  "sapAsePrometheusExporter": {
    "sapAseSid": "ASE",
    "sapAsePort": "4901",
    "sapAseSecretName": "ASE_DB_CREDS",
    "prometheusPort": "9399",
    "agreeToEnableASEMonitoring": true
}
```

# Amazon EC2 上的 SAP HANA
<a name="component-configuration-examples-hana"></a>

下列範例顯示 Amazon EC2 上 SAP HANA JSON 格式的元件組態。

```
{
  "subComponents": [
    {
      "subComponentType": "AWS::EC2::Instance",
      "alarmMetrics": [
        {
          "alarmMetricName": "hanadb_server_startup_time_variations_seconds",
          "monitor": true
        },
        {
          "alarmMetricName": "hanadb_level_5_alerts_count",
          "monitor": true
        },
        {
          "alarmMetricName": "hanadb_level_4_alerts_count",
          "monitor": true
        },
        {
          "alarmMetricName": "hanadb_out_of_memory_events_count",
          "monitor": true
        },
        {
          "alarmMetricName": "hanadb_max_trigger_read_ratio_percent",
          "monitor": true
        },
        {
          "alarmMetricName": "hanadb_table_allocation_limit_used_percent",
          "monitor": true
        },
        {
          "alarmMetricName": "hanadb_cpu_usage_percent",
          "monitor": true
        },
        {
          "alarmMetricName": "hanadb_plan_cache_hit_ratio_percent",
          "monitor": true
        },
        {
          "alarmMetricName": "hanadb_last_data_backup_age_days",
          "monitor": true
        }
      ],
      "logs": [
        {
          "logGroupName": "SAP_HANA_TRACE-my-resourge-group",
          "logPath": "/usr/sap/HDB/HDB00/*/trace/*.trc",
          "logType": "SAP_HANA_TRACE",
          "monitor": true,
          "encoding": "utf-8"
        },
        {
          "logGroupName": "SAP_HANA_LOGS-my-resource-group",
          "logPath": "/usr/sap/HDB/HDB00/*/trace/*.log",
          "logType": "SAP_HANA_LOGS",
          "monitor": true,
          "encoding": "utf-8"
        }
      ]
    }
  ],
  "hanaPrometheusExporter": {
    "hanaSid": "HDB",
    "hanaPort": "30013",
    "hanaSecretName": "HANA_DB_CREDS",
    "prometheusPort": "9668"
  }
}
```

# 在 Amazon EC2 上的 SAP HANA 高可用性
<a name="component-configuration-examples-hana-ha"></a>

下列範例顯示在 Amazon EC2 上的 SAP HANA 高可用性 JSON 格式的元件組態。

```
{
  "subComponents": [
    {
      "subComponentType": "AWS::EC2::Instance",
      "alarmMetrics": [
        {
          "alarmMetricName": "hanadb_server_startup_time_variations_seconds",
          "monitor": true
        },
        {
          "alarmMetricName": "hanadb_level_5_alerts_count",
          "monitor": true
        },
        {
          "alarmMetricName": "hanadb_level_4_alerts_count",
          "monitor": true
        },
        {
          "alarmMetricName": "hanadb_out_of_memory_events_count",
          "monitor": true
        },
        {
          "alarmMetricName": "ha_cluster_pacemaker_stonith_enabled",
          "monitor": true
        }
      ],
      "logs": [
        {
          "logGroupName": "SAP_HANA_TRACE-my-resourge-group",
          "logPath": "/usr/sap/HDB/HDB00/*/trace/*.trc",
          "logType": "SAP_HANA_TRACE",
          "monitor": true,
          "encoding": "utf-8"
        },
        {
          "logGroupName": "SAP_HANA_HIGH_AVAILABILITY-my-resource-group",
          "logPath": "/var/log/pacemaker/pacemaker.log",
          "logType": "SAP_HANA_HIGH_AVAILABILITY",
          "monitor": true,
          "encoding": "utf-8"
        }
      ]
    }
  ],
  "hanaPrometheusExporter": {
    "hanaSid": "HDB",
    "hanaPort": "30013",
    "hanaSecretName": "HANA_DB_CREDS",
    "prometheusPort": "9668"
  },
  "haClusterPrometheusExporter": {
    "prometheusPort": "9664"
  }
}
```

# Amazon EC2 上的 SAP NetWeaver
<a name="component-configuration-examples-netweaver"></a>

下列範例顯示 Amazon EC2 上 SAP NetWeaver 的 JSON 格式的元件組態。

```
{
  "subComponents": [
    {
      "subComponentType": "AWS::EC2::Instance",
      "alarmMetrics": [
        {
          "alarmMetricName": "CPUUtilization",
          "monitor": true
        },
        {
          "alarmMetricName": "StatusCheckFailed",
          "monitor": true
        },
        {
          "alarmMetricName": "disk_used_percent",
          "monitor": true
        },
        {
          "alarmMetricName": "mem_used_percent",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_ResponseTime",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_ResponseTimeDialog",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_ResponseTimeDialogRFC",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_DBRequestTime",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_LongRunners",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_AbortedJobs",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_BasisSystem",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_Database",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_Security",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_System",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_QueueTime",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_Availability",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_start_service_processes",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_dispatcher_queue_now",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_dispatcher_queue_max",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_enqueue_server_locks_max",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_enqueue_server_locks_now",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_enqueue_server_locks_state",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_enqueue_server_replication_state",
          "monitor": true
        }
      ],
      "logs": [
        {
          "logGroupName": "SAP_NETWEAVER_DEV_TRACE_LOGS-NetWeaver-ML4",
          "logPath": "/usr/sap/ML4/*/work/dev_w*",
          "logType": "SAP_NETWEAVER_DEV_TRACE_LOGS",
          "monitor": true,
          "encoding": "utf-8"
        }
      ]
    }
  ],
  "netWeaverPrometheusExporter": {
    "sapSid": "ML4",
    "instanceNumbers": [
      "00",
      "11"
    ],
    "prometheusPort": "9680"
  }
}
```

# 在 Amazon EC2 上的 SAP NetWeaver 高可用性
<a name="component-configuration-examples-netweaver-ha"></a>

下列範例顯示 Amazon EC2 上 SAP NetWeaver 高可用性的 JSON 格式的元件組態。

```
{
  "subComponents": [
    {
      "subComponentType": "AWS::EC2::Instance",
      "alarmMetrics": [
        {
          "alarmMetricName": "ha_cluster_corosync_ring_errors",
          "monitor": true
        },
        {
          "alarmMetricName": "ha_cluster_pacemaker_fail_count",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_HA_check_failover_config_state",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_HA_get_failover_config_HAActive",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_AbortedJobs",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_Availability",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_BasisSystem",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_DBRequestTime",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_Database",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_FrontendResponseTime",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_LongRunners",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_QueueTime",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_ResponseTime",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_ResponseTimeDialog",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_ResponseTimeDialogRFC",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_Security",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_Shortdumps",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_SqlError",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_alerts_System",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_enqueue_server_replication_state",
          "monitor": true
        },
        {
          "alarmMetricName": "sap_start_service_processes",
          "monitor": true
        }
      ],
      "logs": [
        {
          "logGroupName": "SAP_NETWEAVER_DEV_TRACE_LOGS-NetWeaver-PR1",
          "logPath": "/usr/sap/<SID>/D*/work/dev_w*",
          "logType": "SAP_NETWEAVER_DEV_TRACE_LOGS",
          "monitor": true,
          "encoding": "utf-8"
        }
      ]
    }
  ],
  "haClusterPrometheusExporter": {
    "prometheusPort": "9664"
  },
  "netWeaverPrometheusExporter": {
    "sapSid": "PR1",
    "instanceNumbers": [
      "11",
      "12"
    ],
    "prometheusPort": "9680"
  }
}
```

# SQL Always On 可用性群組
<a name="component-configuration-examples-sql"></a>

下列範例顯示 SQL Always On 可用性群組 JSON 格式的元件組態。

```
{
  "subComponents" : [ {
    "subComponentType" : "AWS::EC2::Instance",
    "alarmMetrics" : [ {
      "alarmMetricName" : "CPUUtilization",
      "monitor" : true
    }, {
      "alarmMetricName" : "StatusCheckFailed",
      "monitor" : true
    }, {
      "alarmMetricName" : "Processor % Processor Time",
      "monitor" : true
    }, {
      "alarmMetricName" : "Memory % Committed Bytes In Use",
      "monitor" : true
    }, {
      "alarmMetricName" : "Memory Available Mbytes",
      "monitor" : true
    }, {
      "alarmMetricName" : "Paging File % Usage",
      "monitor" : true
    }, {
      "alarmMetricName" : "System Processor Queue Length",
      "monitor" : true
    }, {
      "alarmMetricName" : "Network Interface Bytes Total/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "PhysicalDisk % Disk Time",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:Buffer Manager Buffer cache hit ratio",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:Buffer Manager Page life expectancy",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:General Statistics Processes blocked",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:General Statistics User Connections",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:Locks Number of Deadlocks/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:SQL Statistics Batch Requests/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:Database Replica File Bytes Received/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:Database Replica Log Bytes Received/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:Database Replica Log remaining for undo",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:Database Replica Log Send Queue",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:Database Replica Mirrored Write Transaction/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:Database Replica Recovery Queue",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:Database Replica Redo Bytes Remaining",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:Database Replica Redone Bytes/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:Database Replica Total Log requiring undo",
      "monitor" : true
    }, {
      "alarmMetricName" : "SQLServer:Database Replica Transaction Delay",
      "monitor" : true
    } ],
    "windowsEvents" : [ {
      "logGroupName" : "WINDOWS_EVENTS-Application-<RESOURCE_GROUP_NAME>",
      "eventName" : "Application",
      "eventLevels" : [ "WARNING", "ERROR", "CRITICAL", "INFORMATION" ],
      "monitor" : true
    }, {
      "logGroupName" : "WINDOWS_EVENTS-System-<RESOURCE_GROUP_NAME>",
      "eventName" : "System",
      "eventLevels" : [ "WARNING", "ERROR", "CRITICAL" ],
      "monitor" : true
    }, {
      "logGroupName" : "WINDOWS_EVENTS-Security-<RESOURCE_GROUP_NAME>",
      "eventName" : "Security",
      "eventLevels" : [ "WARNING", "ERROR", "CRITICAL" ],
      "monitor" : true
    } ],
    "logs" : [ {
      "logGroupName" : "SQL_SERVER_ALWAYSON_AVAILABILITY_GROUP-<RESOURCE_GROUP_NAME>",
      "logPath" : "C:\\Program Files\\Microsoft SQL Server\\MSSQL**.MSSQLSERVER\\MSSQL\\Log\\ERRORLOG",
      "logType" : "SQL_SERVER",
      "monitor" : true,
      "encoding" : "utf-8"
    } ]
  }, {
    "subComponentType" : "AWS::EC2::Volume",
    "alarmMetrics" : [ {
      "alarmMetricName" : "VolumeReadBytes",
      "monitor" : true
    }, {
    "alarmMetricName" : "VolumeWriteBytes",
      "monitor" : true
    }, {
    "alarmMetricName" : "VolumeReadOps",
      "monitor" : true
    }, {
    "alarmMetricName" : "VolumeWriteOps",
      "monitor" : true
    }, {
    "alarmMetricName" : "VolumeQueueLength",
      "monitor" : true
    }, {
    "alarmMetricName" : "VolumeThroughputPercentage",
      "monitor" : true
    }, {
    "alarmMetricName" : "BurstBalance",
      "monitor" : true
    } ]
  } ]
}
```

# SQL 容錯移轉叢集執行個體
<a name="component-configuration-examples-sql-failover-cluster"></a>

下列範例顯示 SQL 容錯移轉叢集執行個體 JSON 格式的元件組態。

```
{
  "subComponents" : [ {
    "subComponentType" : "AWS::EC2::Instance",
    "alarmMetrics" : [ {
      "alarmMetricName" : "CPUUtilization",
      "monitor" : true
    }, {
      "alarmMetricName" : "StatusCheckFailed",
      "monitor" : true
    }, {
      "alarmMetricName" : "Processor % Processor Time",
      "monitor" : true
    }, {
      "alarmMetricName" : "Memory % Committed Bytes In Use",
      "monitor" : true
    }, {
      "alarmMetricName" : "Memory Available Mbytes",
      "monitor" : true
    }, {
      "alarmMetricName" : "Paging File % Usage",
      "monitor" : true
    }, {
      "alarmMetricName" : "System Processor Queue Length",
      "monitor" : true
    }, {
      "alarmMetricName" : "Network Interface Bytes Total/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "PhysicalDisk % Disk Time",
      "monitor" : true
    }, {
      "alarmMetricName" : "Bytes Received/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "Normal Messages Queue Length/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "Urgent Message Queue Length/se",
      "monitor" : true
    }, {
      "alarmMetricName" : "Reconnect Count",
      "monitor" : true
    }, {
      "alarmMetricName" : "Unacknowledged Message Queue Length/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "Messages Outstanding",
      "monitor" : true
    }, {
      "alarmMetricName" : "Messages Sent/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "Database Update Messages/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "Update Messages/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "Flushes/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "Crypto Checkpoints Saved/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "Crypto Checkpoints Restored/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "Registry Checkpoints Restored/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "Registry Checkpoints Saved/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "Cluster API Calls/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "Resource API Calls/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "Cluster Handles/sec",
      "monitor" : true
    }, {
      "alarmMetricName" : "Resource Handles/sec",
      "monitor" : true
    } ],
    "windowsEvents" : [ {
      "logGroupName" : "WINDOWS_EVENTS-Application-<RESOURCE_GROUP_NAME>",
      "eventName" : "Application",
      "eventLevels" : [ "WARNING", "ERROR", "CRITICAL"],
      "monitor" : true
    }, {
      "logGroupName" : "WINDOWS_EVENTS-System-<RESOURCE_GROUP_NAME>",
      "eventName" : "System",
      "eventLevels" : [ "WARNING", "ERROR", "CRITICAL", "INFORMATION" ],
      "monitor" : true
    }, {
      "logGroupName" : "WINDOWS_EVENTS-Security-<RESOURCE_GROUP_NAME>",
      "eventName" : "Security",
      "eventLevels" : [ "WARNING", "ERROR", "CRITICAL" ],
      "monitor" : true
    } ],
    "logs" : [ {
      "logGroupName" : "SQL_SERVER_FAILOVER_CLUSTER_INSTANCE-<RESOURCE_GROUP_NAME>",
      "logPath" : "\\\\amznfsxjmzbykwn.mydomain.aws\\SQLDB\\MSSQL**.MSSQLSERVER\\MSSQL\\Log\\ERRORLOG",
      "logType" : "SQL_SERVER",
      "monitor" : true,
      "encoding" : "utf-8"
    } ]
  }, {
    "subComponentType" : "AWS::EC2::Volume",
    "alarmMetrics" : [ {
      "alarmMetricName" : "VolumeReadBytes",
      "monitor" : true
    }, {
    "alarmMetricName" : "VolumeWriteBytes",
      "monitor" : true
    }, {
    "alarmMetricName" : "VolumeReadOps",
      "monitor" : true
    }, {
    "alarmMetricName" : "VolumeWriteOps",
      "monitor" : true
    }, {
    "alarmMetricName" : "VolumeQueueLength",
      "monitor" : true
    }, {
    "alarmMetricName" : "VolumeThroughputPercentage",
      "monitor" : true
    }, {
    "alarmMetricName" : "BurstBalance",
      "monitor" : true
    } ]
  } ]
}
```

# 使用 CloudFormation 範本建立和設定 CloudWatch Application Insights 監控
<a name="appinsights-cloudformation"></a>

您可以直接從 AWS CloudFormation 範本將 Application Insights 監控新增至應用程式、資料庫和 Web 伺服器，包括關鍵指標和遙測。

本節提供 JSON 和 YAML 格式的範例 CloudFormation 範本，協助您建立和設定 Application Insights 監控。

若要檢視 Application Insights 資源和*《CloudFormation 使用者指南》*，請參閱 [ApplicationInsights 資源類型參考](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/AWS_ApplicationInsights.html)。

**Topics**
+ [為整個 CloudFormation 堆疊建立 Application Insights 應用程式](#appinsights-cloudformation-apply-to-stack)
+ [建立具有詳細設定的 Application Insights 應用程式](#appinsights-cloudformation-apply-detailed)
+ [使用 `CUSTOM` 模式元件組態建立 Application Insights 應用程式](#appinsights-cloudformation-custom)
+ [使用 `DEFAULT` 模式元件組態建立 Application Insights 應用程式](#appinsights-cloudformation-default)
+ [使用 `DEFAULT_WITH_OVERWRITE` 模式元件組態建立 Application Insights 應用程式](#appinsights-cloudformation-default-with-overwrite)

## 為整個 CloudFormation 堆疊建立 Application Insights 應用程式
<a name="appinsights-cloudformation-apply-to-stack"></a>

若要套用下列範本，您必須建立 AWS 資源和一或多個資源群組，以從中建立 Application Insights 應用程式來監控這些資源。如需詳細資訊，請參閱[《 AWS Resource Groups 入門》](https://docs.aws.amazon.com/ARG/latest/userguide/gettingstarted.html)。

下列範本的前兩個部分會指定資源和資源群組。範本的最後一部分會為資源群組建立 Application Insights 應用程式，但不會設定應用程式或套用監控。如需詳細資訊，請參閱 *Amazon CloudWatch Application Insights API 參考*中的 [CreateApplication](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_CreateApplication.html) 命令詳細資訊。

**JSON 格式的範本**

```
{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Test Resource Group stack",
    "Resources": {
        "EC2Instance": {
            "Type": "AWS::EC2::Instance",
            "Properties": {
                "ImageId" : "ami-abcd1234efgh5678i",
                "SecurityGroupIds" : ["sg-abcd1234"]
            }
        },
        ...
        "ResourceGroup": {
            "Type": "AWS::ResourceGroups::Group",
            "Properties": {
                "Name": "my_resource_group"
            }
        },
        "AppInsightsApp": {
            "Type": "AWS::ApplicationInsights::Application",
            "Properties": {
                "ResourceGroupName": "my_resource_group"
            },
            "DependsOn" : "ResourceGroup"
        }
    }
}
```

**YAML 格式的範本**

```
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Test Resource Group stack
Resources:
  EC2Instance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-abcd1234efgh5678i
      SecurityGroupIds:
      - sg-abcd1234
  ...
  ResourceGroup:
    Type: AWS::ResourceGroups::Group
    Properties:
      Name: my_resource_group
  AppInsightsApp:
    Type: AWS::ApplicationInsights::Application
    Properties:
      ResourceGroupName: my_resource_group
    DependsOn: ResourceGroup
```

下列範本區段會將預設監控組態套用至 Application Insights 應用程式。如需詳細資訊，請參閱 *Amazon CloudWatch Application Insights API 參考*中的 [CreateApplication](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_CreateApplication.html) 命令詳細資訊。

在將 `AutoConfigurationEnabled` 設定為 `true` 時，則會使用該 `DEFAULT` 應用程式層的建議監控設定值來設定應用程式的所有元件。如需詳細資訊，請參閱 *Amazon CloudWatch Application Insights API 參考*中的 [DescribeComponentConfigurationRecommendation](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_DescribeComponentConfigurationRecommendation.html) 和 [UpdateComponentConfiguration](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_UpdateComponentConfiguration.html)。

**JSON 格式的範本**

```
{
    "AWSTemplateFormatVersion": "2010-09-09",
    "Description": "Test Application Insights Application stack",
    "Resources": {
        "AppInsightsApp": {
            "Type": "AWS::ApplicationInsights::Application",
            "Properties": {
                "ResourceGroupName": "my_resource_group",
                "AutoConfigurationEnabled": true
            }
        }
    }
}
```

**YAML 格式的範本**

```
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Test Application Insights Application stack
Resources:
  AppInsightsApp:
    Type: AWS::ApplicationInsights::Application
    Properties:
      ResourceGroupName: my_resource_group
      AutoConfigurationEnabled: true
```

## 建立具有詳細設定的 Application Insights 應用程式
<a name="appinsights-cloudformation-apply-detailed"></a>

下列範本會執行這些動作：
+ 建立 Application Insights 應用程式，並啟用 CloudWatch Events 通知並啟用 OpsCenter。如需詳細資訊，請參閱 *Amazon CloudWatch Application Insights API 參考*中的 [CreateApplication](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_CreateApplication.html) 命令詳細資訊。
+ 使用兩個標籤來標記應用程式，其中一個標籤沒有標籤值。如需詳細資訊，請參閱《Amazon CloudWatch Application Insights API 參考》**中的 [TagResource](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_TagResource.html)。
+ 建立兩個自訂執行個體群組元件。如需詳細資訊，請參閱《Amazon CloudWatch Application Insights API 參考》**中的 [CreateComponent](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_CreateComponent.html)。
+ 建立兩個日誌模式集。如需詳細資訊，請參閱《Amazon CloudWatch Application Insights API 參考》**中的 [CreateLogPattern](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_CreateLogPattern.html)。
+ 設定 `AutoConfigurationEnabled` 為 `true`，此設定應用程式的所有元件，並使用該 `DEFAULT` 層的建議監控設定值。如需詳細資訊，請參閱《Amazon CloudWatch Application Insights API 參考》**中的 [DescribeComponentConfigurationRecommendation](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_DescribeComponentConfigurationRecommendation.html)。

**JSON 格式的範本**

```
{
    "Type": "AWS::ApplicationInsights::Application",
    "Properties": {
        "ResourceGroupName": "my_resource_group",
        "CWEMonitorEnabled": true,
        "OpsCenterEnabled": true,
        "OpsItemSNSTopicArn": "arn:aws:sns:us-east-1:123456789012:my_topic",
        "AutoConfigurationEnabled": true,
        "Tags": [
            {
                "Key": "key1",
                "Value": "value1"
            },
            {
                "Key": "key2",
                "Value": ""
            }
        ],
        "CustomComponents": [
            {
                "ComponentName": "test_component_1",
                "ResourceList": [
                    "arn:aws:ec2:us-east-1:123456789012:instance/i-abcd1234efgh5678i"
                ]
            },
            {
                "ComponentName": "test_component_2",
                "ResourceList": [
                    "arn:aws:ec2:us-east-1:123456789012:instance/i-abcd1234efgh5678i",
                    "arn:aws:ec2:us-east-1:123456789012:instance/i-abcd1234efgh5678i"
                ]
            }
        ],
        "LogPatternSets": [
            {
                "PatternSetName": "pattern_set_1",
                "LogPatterns": [
                    {
                        "PatternName": "deadlock_pattern",
                        "Pattern": ".*\\sDeadlocked\\sSchedulers(([^\\w].*)|($))",
                        "Rank": 1
                    }
                ]    
            },
            {
                "PatternSetName": "pattern_set_2",
                "LogPatterns": [
                    {
                        "PatternName": "error_pattern",
                        "Pattern": ".*[\\s\\[]ERROR[\\s\\]].*",
                        "Rank": 1
                    },
                    {
                        "PatternName": "warning_pattern",
                        "Pattern": ".*[\\s\\[]WARN(ING)?[\\s\\]].*",
                        "Rank": 10
                    }
                ]
            }
        ]
    }
}
```

**YAML 格式的範本**

```
---
Type: AWS::ApplicationInsights::Application
Properties:
  ResourceGroupName: my_resource_group
  CWEMonitorEnabled: true
  OpsCenterEnabled: true
  OpsItemSNSTopicArn: arn:aws:sns:us-east-1:123456789012:my_topic
  AutoConfigurationEnabled: true
  Tags:
  - Key: key1
    Value: value1
  - Key: key2
    Value: ''
  CustomComponents:
  - ComponentName: test_component_1
    ResourceList:
    - arn:aws:ec2:us-east-1:123456789012:instance/i-abcd1234efgh5678i
  - ComponentName: test_component_2
    ResourceList:
    - arn:aws:ec2:us-east-1:123456789012:instance/i-abcd1234efgh5678i
    - arn:aws:ec2:us-east-1:123456789012:instance/i-abcd1234efgh5678i
  LogPatternSets:
  - PatternSetName: pattern_set_1
    LogPatterns:
    - PatternName: deadlock_pattern
      Pattern: ".*\\sDeadlocked\\sSchedulers(([^\\w].*)|($))"
      Rank: 1
  - PatternSetName: pattern_set_2
    LogPatterns:
    - PatternName: error_pattern
      Pattern: ".*[\\s\\[]ERROR[\\s\\]].*"
      Rank: 1
    - PatternName: warning_pattern
      Pattern: ".*[\\s\\[]WARN(ING)?[\\s\\]].*"
      Rank: 10
```

## 使用 `CUSTOM` 模式元件組態建立 Application Insights 應用程式
<a name="appinsights-cloudformation-custom"></a>

下列範本會執行這些動作：
+ 建立 Application Insights 應用程式。如需詳細資訊，請參閱《Amazon CloudWatch Application Insights API 參考》**中的 [CreateApplication](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_CreateApplication.html)。
+ 元件 `my_component` 會將 `ComponentConfigurationMode` 設定為 `CUSTOM`，這會導致此元件按照 `CustomComponentConfiguration` 中指定的組態進行設定。如需詳細資訊，請參閱 *Amazon CloudWatch Application Insights API 參考資料*中的 [UpdateComponentConfiguration](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_UpdateComponentConfiguration.html)。

**JSON 格式的範本**

```
{
    "Type": "AWS::ApplicationInsights::Application",
    "Properties": {
        "ResourceGroupName": "my_resource_group,
        "ComponentMonitoringSettings": [
            {
                "ComponentARN": "my_component",
                "Tier": "SQL_SERVER",
                "ComponentConfigurationMode": "CUSTOM",
                "CustomComponentConfiguration": {
                    "ConfigurationDetails": {
                        "AlarmMetrics": [
                            {
                                "AlarmMetricName": "StatusCheckFailed"
                            },
                            ...
                        ],
                        "Logs": [
                            {       
                                "LogGroupName": "my_log_group_1",
                                "LogPath": "C:\\LogFolder_1\\*",
                                "LogType": "DOT_NET_CORE",
                                "Encoding": "utf-8",
                                "PatternSet": "my_pattern_set_1"
                            },      
                            ...     
                        ],      
                        "WindowsEvents": [
                            {       
                                "LogGroupName": "my_windows_event_log_group_1",
                                "EventName": "Application",
                                "EventLevels": [
                                    "ERROR",
                                    "WARNING",
                                    ...     
                                ],       
                                "Encoding": "utf-8",
                                "PatternSet": "my_pattern_set_2"
                            },      
                            ...     
                        ],
                        "Alarms": [
                            {
                                "AlarmName": "my_alarm_name",
                                "Severity": "HIGH"
                            },
                            ...
                        ]
                    },
                    "SubComponentTypeConfigurations": [
                        {
                            "SubComponentType": "EC2_INSTANCE",
                            "SubComponentConfigurationDetails": {
                                "AlarmMetrics": [
                                    {
                                        "AlarmMetricName": "DiskReadOps"
                                    },
                                    ...
                                ],
                                "Logs": [
                                    {
                                        "LogGroupName": "my_log_group_2",
                                        "LogPath": "C:\\LogFolder_2\\*",
                                        "LogType": "IIS",
                                        "Encoding": "utf-8",
                                        "PatternSet": "my_pattern_set_3"
                                    },
                                    ...
                                ],
                                "processes" : [
                                    {
                                        "processName" : "my_process",
                                        "alarmMetrics" : [
                                    {
                                        "alarmMetricName" : "procstat cpu_usage",
                                        "monitor" : true
                                    }, {
                                        "alarmMetricName" : "procstat memory_rss",
                                        "monitor" : true
                                    }
                                ]
                            }
                        ],
                                "WindowsEvents": [
                                    {
                                        "LogGroupName": "my_windows_event_log_group_2",
                                        "EventName": "Application",
                                        "EventLevels": [
                                            "ERROR",
                                            "WARNING",
                                            ...
                                        ],
                                        "Encoding": "utf-8",
                                        "PatternSet": "my_pattern_set_4"
                                    },
                                    ...
                                ]
                            }
                        }   
                    ]
                }
            }
        ]
    }
}
```

**YAML 格式的範本**

```
---
Type: AWS::ApplicationInsights::Application
Properties:
  ResourceGroupName: my_resource_group
  ComponentMonitoringSettings:
  - ComponentARN: my_component
    Tier: SQL_SERVER
    ComponentConfigurationMode: CUSTOM
    CustomComponentConfiguration:
      ConfigurationDetails:
        AlarmMetrics:
        - AlarmMetricName: StatusCheckFailed
        ...
        Logs:
        - LogGroupName: my_log_group_1
          LogPath: C:\LogFolder_1\*
          LogType: DOT_NET_CORE
          Encoding: utf-8
          PatternSet: my_pattern_set_1
        ...
        WindowsEvents:
        - LogGroupName: my_windows_event_log_group_1
          EventName: Application
          EventLevels:
          - ERROR
          - WARNING
          ...
          Encoding: utf-8
          PatternSet: my_pattern_set_2
        ...
        Alarms:
        - AlarmName: my_alarm_name
          Severity: HIGH
        ...
      SubComponentTypeConfigurations:
      - SubComponentType: EC2_INSTANCE
        SubComponentConfigurationDetails:
          AlarmMetrics:
          - AlarmMetricName: DiskReadOps
          ...
          Logs:
          - LogGroupName: my_log_group_2
            LogPath: C:\LogFolder_2\*
            LogType: IIS
            Encoding: utf-8
            PatternSet: my_pattern_set_3
          ...
          Processes:
          - ProcessName: my_process
            AlarmMetrics:
            - AlarmMetricName: procstat cpu_usage
              ...
            ...
          WindowsEvents:
          - LogGroupName: my_windows_event_log_group_2
            EventName: Application
            EventLevels:
            - ERROR
            - WARNING
            ...
            Encoding: utf-8
            PatternSet: my_pattern_set_4
          ...
```

## 使用 `DEFAULT` 模式元件組態建立 Application Insights 應用程式
<a name="appinsights-cloudformation-default"></a>

下列範本會執行這些動作：
+ 建立 Application Insights 應用程式。如需詳細資訊，請參閱《Amazon CloudWatch Application Insights API 參考》**中的 [CreateApplication](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_CreateApplication.html)。
+ 元件 `my_component` 會將 `ComponentConfigurationMode` 設定為 `DEFAULT` 並將 `Tier` 設定為 `SQL_SERVER`，這會使用 Application Insights 建議該 `SQL_Server` 層的組態設定來設定此元件。如需詳細資訊，請參閱《Amazon CloudWatch Application Insights API 參考》**中的 [DescribeComponentConfiguration](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_DescribeComponentConfiguration.html) 和 [UpdateComponentConfiguration](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_UpdateComponentConfiguration.html)。

**JSON 格式的範本**

```
{
    "Type": "AWS::ApplicationInsights::Application",
    "Properties": {
        "ResourceGroupName": "my_resource_group",
        "ComponentMonitoringSettings": [
            {
                "ComponentARN": "my_component",
                "Tier": "SQL_SERVER",
                "ComponentConfigurationMode": "DEFAULT"
            }
        ]
    }
}
```

**YAML 格式的範本**

```
---
Type: AWS::ApplicationInsights::Application
Properties:
  ResourceGroupName: my_resource_group
  ComponentMonitoringSettings:
  - ComponentARN: my_component
    Tier: SQL_SERVER
    ComponentConfigurationMode: DEFAULT
```

## 使用 `DEFAULT_WITH_OVERWRITE` 模式元件組態建立 Application Insights 應用程式
<a name="appinsights-cloudformation-default-with-overwrite"></a>

下列範本會執行這些動作：
+ 建立 Application Insights 應用程式。如需詳細資訊，請參閱《Amazon CloudWatch Application Insights API 參考》**中的 [CreateApplication](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_CreateApplication.html)。
+ 元件 `my_component` 會將 `ComponentConfigurationMode` 設定為 `DEFAULT_WITH_OVERWRITE` 並將 `tier` 設定為 `DOT_NET_CORE`，這會使用 Application Insights 建議該 `DOT_NET_CORE` 層的組態設定來設定此元件。覆寫的組態設定可在 `DefaultOverwriteComponentConfiguration` 中的下列項目中指定：
  + 在元件層級，系統會覆寫 `AlarmMetrics` 設定。
  + 在子元件層級，對於 `EC2_Instance` 類型的子元件，系統會覆寫 `Logs` 設定。

  如需詳細資訊，請參閱 *Amazon CloudWatch Application Insights API 參考資料*中的 [UpdateComponentConfiguration](https://docs.aws.amazon.com/cloudwatch/latest/APIReference/API_UpdateComponentConfiguration.html)。

**JSON 格式的範本**

```
{
    "Type": "AWS::ApplicationInsights::Application",
    "Properties": {
        "ResourceGroupName": "my_resource_group",
        "ComponentMonitoringSettings": [
            {
                "ComponentName": "my_component",
                "Tier": "DOT_NET_CORE",
                "ComponentConfigurationMode": "DEFAULT_WITH_OVERWRITE",
                "DefaultOverwriteComponentConfiguration": {
                    "ConfigurationDetails": {
                        "AlarmMetrics": [
                            {
                                "AlarmMetricName": "StatusCheckFailed"
                            }
                        ]
                    },
                    "SubComponentTypeConfigurations": [
                        {
                            "SubComponentType": "EC2_INSTANCE",
                            "SubComponentConfigurationDetails": {
                                "Logs": [
                                    {
                                        "LogGroupName": "my_log_group",
                                        "LogPath": "C:\\LogFolder\\*",
                                        "LogType": "IIS",
                                        "Encoding": "utf-8",
                                        "PatternSet": "my_pattern_set"
                                    }
                                ]
                            }
                        }   
                    ] 
                } 
            }
        ]
    }
}
```

**YAML 格式的範本**

```
---
Type: AWS::ApplicationInsights::Application
Properties:
  ResourceGroupName: my_resource_group
  ComponentMonitoringSettings:
  - ComponentName: my_component
    Tier: DOT_NET_CORE
    ComponentConfigurationMode: DEFAULT_WITH_OVERWRITE
    DefaultOverwriteComponentConfiguration:
      ConfigurationDetails:
        AlarmMetrics:
        - AlarmMetricName: StatusCheckFailed
      SubComponentTypeConfigurations:
      - SubComponentType: EC2_INSTANCE
        SubComponentConfigurationDetails:
          Logs:
          - LogGroupName: my_log_group
            LogPath: C:\LogFolder\*
            LogType: IIS
            Encoding: utf-8
            PatternSet: my_pattern_set
```

# 教學課程：設定 SAP ASE 的監控
<a name="appinsights-tutorial-sap-ase"></a>

本教學課程示範如何設定 CloudWatch Application Insights，以設定 SAP ASE 資料庫的監控。您可以使用 CloudWatch Application Insights 自動儀表板，以視覺化方式呈現問題詳細資訊、加速疑難排解，並改進 SAP ASE 資料庫的平均解決時間 (MTTR)。

**Topics**
+ [支援的環境](#appinsights-tutorial-sap-ase-supported-environments)
+ [支援的作業系統](#appinsights-tutorial-sap-ase-supported-os)
+ [功能](#appinsights-tutorial-sap-ase-features)
+ [先決條件](#appinsights-tutorial-sap-ase-prerequisites)
+ [設定監控](#appinsights-tutorial-sap-ase-set-up)
+ [管理監控](#appinsights-tutorial-sap-ase-manage)
+ [設定警示閾值](#appinsights-tutorial-sap-hana-configure-alarm-threshold)
+ [檢視與針對 Application Insights 偵測到的 SAP ASE 問題進行疑難排解](#appinsights-tutorial-sap-ase-troubleshooting-problems)
+ [Application Insights 疑難排解](#appinsights-tutorial-sap-ase-troubleshooting-health-dashboard)

## 支援的環境
<a name="appinsights-tutorial-sap-ase-supported-environments"></a>

CloudWatch Application Insights 支援下列系統和模式 AWS 的資源部署。您提供並安裝 SAP ASE 資料庫軟體和支援的 SAP 應用程式軟體。
+ **單一 Amazon EC2 執行個體上的一個或多個 SAP ASE 資料庫** – 單一節點、縱向擴展架構中的 SAP ASE。
+ **跨可用區域 SAP ASE 資料庫高可用性設定** – 使用 SUSE/RHEL 叢集跨兩個可用區域設定高可用性的 SAP ASE。

**注意**  
CloudWatch Application Insights 僅支援單一 SAP 系統 ID (SID) ASE HA 環境。如果連接了多個 ASE HA SID，則僅為偵測到的第一個 SID 設定監控。

## 支援的作業系統
<a name="appinsights-tutorial-sap-ase-supported-os"></a>

適用於 SAP ASE 的 CloudWatch Application Insights 支援下列作業系統上的 x86-64 架構：
+ SuSE Linux 12 SP4
+ SuSE Linux 12 SP5
+ SuSE Linux 15
+ SuSE Linux 15 SP1
+ SuSE Linux 15 SP2
+ SuSE Linux 15 SP3
+ SuSE Linux 15 SP4
+ SuSE Linux 15 SP1 For SAP
+ SuSE Linux 15 SP2 For SAP
+ SuSE Linux 15 SP3 For SAP
+ SuSE Linux 15 SP4 For SAP
+ SuSE Linux 12 SP4 For SAP
+ SuSE Linux 12 SP5 For SAP
+ RedHat Linux 7.6
+ RedHat Linux 7.7
+ RedHat Linux 7.9
+ RedHat Linux 8.1
+ RedHat Linux 8.4
+ RedHat Linux 8.6

## 功能
<a name="appinsights-tutorial-sap-ase-features"></a>

適用於 SAP ASE 的 CloudWatch Application Insights 提供下列功能：
+ 自動偵測 SAP ASE 工作負載 
+ 根據靜態閾值自動建立 SAP ASE 警示
+ 根據異常偵測自動建立 SAP ASE 警示 
+ 自動 SAP ASE 日誌模式辨識 
+ SAP ASE 的運作狀態儀表板
+ SAP ASE 的問題儀表板

## 先決條件
<a name="appinsights-tutorial-sap-ase-prerequisites"></a>

您必須完成以下先決條件，使用 CloudWatch Application Insights 設定 SAP ASE 資料庫：
+ **SAP ASE 組態參數** – 必須在 ASE 資料庫上啟用下列組態參數：`"enable monitoring"`、`"sql text pipe max messages"`、`"sql text pipe active"`。如此一來，CloudWatch Application Insights 就能為您的資料庫提供完整的監控功能。如果您的 ASE 資料庫上未啟用這些設定，Application Insights 會自動讓其收集必要的指標以允許監控。
+ **SAP ASE 資料庫使用者** – 在 Application Insights 佈設期間提供的資料庫使用者必須具有存取下列項目的許可：
  + 主資料庫和使用者 (租用戶) 資料庫中的系統資料表
  + 監控資料表
+ **SAPHostCtrl** – 在您的 Amazon EC2 執行個體上安裝並設定 SapHostCtrl。
+ **Amazon CloudWatch 代理程式** – 確保您沒有在 Amazon EC2 執行個體上執行預先存在的 CloudWatch 代理程式。若您安裝了 CloudWatch 代理程式，請確保從現有 CloudWatch 代理程式組態檔案中移除您要在 CloudWatch Application Insights 中使用的資源組態，以避免合併衝突。如需詳細資訊，請參閱[手動建立或編輯 CloudWatch 代理程式組態檔案](CloudWatch-Agent-Configuration-File-Details.md)。
+ **AWS Systems Manager 啟用** – 在執行個體上安裝 SSM Agent，並啟用為 SSM 啟用的執行個體。如需有關如何安裝 SSM Agent 的資訊，請參閱《*AWS Systems Manager 使用者指南*》中的[使用 SSM Agent](https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-agent.html)。
+ **Amazon EC2 執行個體角色** – 您必須連接下列 Amazon EC2 執行個體角色才能設定資料庫。
  + 您必須連接 `AmazonSSMManagedInstanceCore` 角色，以啟用 Systems Manager。如需詳細資訊，請參閱 [AWS Systems Manager 以身分為基礎的政策範例](https://docs.aws.amazon.com/systems-manager/latest/userguide/auth-and-access-control-iam-identity-based-access-control.html)。
  + 您必須連接 `CloudWatchAgentServerPolicy`，以便透過 CloudWatch 發出執行個體指標和日誌。如需詳細資訊，請參閱[建立 IAM 角色和使用者以使用 Amazon CloudWatch 代理程式](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-iam-roles-for-cloudwatch-agent.html)。
  + 您必須將下列 IAM 內嵌政策連接到 Amazon EC2 執行個體角色，才能讀取存放在 AWS Secrets Manager中的密碼。如需內嵌政策的詳細資訊，請參閱《*AWS Identity and Access Management 使用者指南*》中的[內嵌政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html)。

------
#### [ JSON ]

****  

    ```
    {
        "Version":"2012-10-17",		 	 	 
        "Statement": [
            {
                "Sid": "VisualEditor0",
                "Effect": "Allow",
                "Action": [
                    "secretsmanager:GetSecretValue"
                ],
                "Resource": "arn:aws:secretsmanager:*:*:secret:ApplicationInsights-*"
            }
        ]
    }
    ```

------
+ **AWS Resource Groups** – 您必須建立資源群組，其中包含應用程式堆疊用來將應用程式加入 CloudWatch Application Insights 的所有相關 AWS 資源。這包括執行 SAP ASE 資料庫的 Amazon EC2 執行個體和 Amazon EBS 磁碟區。如果每個帳戶有多個資料庫，建議您建立一個資源群組，其中包含每個 SAP ASE 資料庫系統 AWS 的資源。
+ **IAM 許可** - 對於非管理員使用者：
  +  您必須建立 AWS Identity and Access Management (IAM) 政策，允許 Application Insights 建立服務連結角色，並將其連接到您的使用者身分。如需連接政策的步驟，請參閱 [CloudWatch Application Insights 的 IAM 政策](appinsights-iam.md)。
  + 使用者必須具有在 中建立秘密的許可 AWS Secrets Manager ，才能存放資料庫使用者登入資料。如需詳細資訊，請參閱[範例：建立機密的許可](https://docs.aws.amazon.com/secretsmanager/latest/userguide/auth-and-access_examples.html#auth-and-access_examples_create)。

------
#### [ JSON ]

****  

    ```
    {
      "Version":"2012-10-17",		 	 	 
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "secretsmanager:CreateSecret"
          ],
          "Resource": "arn:aws:secretsmanager:*:*:secret:ApplicationInsights-*"
        }
      ]
    }
    ```

------
+ **服務連結角色** – Application Insights 使用 AWS Identity and Access Management (IAM) 服務連結角色。系統會在您於 Application Insights 主控台建立第一個 Application Insights 應用程式時，為您建立服務連結角色。如需詳細資訊，請參閱[針對 CloudWatch Application Insights 使用服務連結角色](CHAP_using-service-linked-roles-appinsights.md)。

## 在您的 SAP ASE 資料庫上設定監控
<a name="appinsights-tutorial-sap-ase-set-up"></a>

使用下列步驟設定 SAP ASE 資料庫的監控

1. 開啟 [CloudWatch 主控台](https://console.aws.amazon.com/cloudwatch)。

1. 從左側導覽窗格中，選擇 **Insights** 下的 **Application Insights**。

1. **Application Insights** 頁面會顯示 Application Insights 監控的應用程式清單，以及每個應用程式的監控狀態。在右上角，選擇 **Add an application** (新增應用程式)。

1. 在**指定應用程式詳細資訊**頁面上，從**資源群組**的下拉清單中選取 AWS 資源群組，其中包含您的 SAP ASE 資料庫資源。如果尚未建立應用程式的資源群組，您可以透過選擇 **Resource group** (資源群組) 下拉單中的 **Create new resource group** (建立新的資源群組) 建立一個。如需建立資源群組的詳細資訊，請參閱《[https://docs.aws.amazon.com/ARG/latest/userguide/resource-groups.html](https://docs.aws.amazon.com/ARG/latest/userguide/resource-groups.html)》。

1. 在**監控 CloudWatch Events** 下，選取核取方塊以整合 Application Insights 監控與 CloudWatch Events，從 Amazon EBS、Amazon EC2 AWS CodeDeploy、Amazon ECS、 AWS Health APIs和通知、Amazon RDS、Amazon S3 和 取得洞見 AWS Step Functions。

1. 在**與 AWS Systems Manager OpsCenter 整合**下，選取 **Generate AWS Systems Manager OpsCenter OpsItems ** 旁的核取方塊，以在偵測到所選應用程式的問題時檢視和取得通知。若要追蹤為了解決與 AWS 資源相關的操作工作項目而執行的操作，稱為 OpsItems，請提供 SNS 主題 ARN。

1. 您可以選擇輸入標籤協助您識別和整理資源。CloudWatch Application Insights 支援標籤型和 CloudFormation 堆疊型資源群組，但 Application Auto Scaling 群組除外。如需詳細資訊，請參閱 *AWS Resource Groups 和標籤使用者指南*中的[標籤編輯器](https://docs.aws.amazon.com/ARG/latest/userguide/tag-editor.html)。

1. 選擇 **Next** (下一個) 繼續設定監控。

1. 在**檢閱偵測到的元件**頁面上，系統會列出 CloudWatch Application Insights 自動偵測到的受監控元件及其工作負載。
**注意**  
包含偵測到的 SAP ASE 高可用性工作負載的元件，一個元件上僅支援一個工作負載。包含偵測到的 SAP ASE 單一節點工作負載的元件，支援多個工作負載，但您無法新增或移除工作負載。所有自動偵測到的工作負載將會受到監控。

1. 選擇**下一步**。

1. 在**指定元件詳細資訊**頁面上，輸入 SAP ASE 資料庫的使用者名稱和密碼。

1. 檢閱您的應用程式監控組態，然後選擇 **Submit** (提交)。

1. 應用程式詳細資訊頁面隨即開啟，您可以在其中檢視**應用程式摘要**、**受監控元件和工作負載**的清單，以及**未受監控元件和工作負載**。如果選取元件或工作負載旁邊的選項按鈕，則您也可以檢視**組態歷史記錄**、**日誌模式**，以及任何已建立的**標籤**。當您提交組態時，您的帳戶會為 SAP ASE 系統部署所有指標和警示，這可能需要最多 2 小時。

## 管理 SAP ASE 資料庫的監控
<a name="appinsights-tutorial-sap-ase-manage"></a>

您可以執行下列步驟來管理 SAP ASE 資料庫的使用者憑證、指標和日誌路徑：

1. 開啟 [CloudWatch 主控台](https://console.aws.amazon.com/cloudwatch)。

1. 從左側導覽窗格中，選擇 **Insights** 下的 **Application Insights**。

1. **Application Insights** 頁面會顯示 Application Insights 監控的應用程式清單，以及每個應用程式的監控狀態。

1. 在 **Monitored components** (受監控元件) 下，選取元件名稱旁的選項按鈕。然後，選擇 **Manage monitoring** (管理監控)。

1. 在 **EC2 instance group logs** (EC2 執行個體群組日誌) 下，您可以更新現有的日誌路徑、日誌模式集和記錄群組名稱。此外，您可以新增最多三個額外 **Application logs** (應用程式日誌)。

1. 在**指標**下，您可以根據需求選擇 SAP ASE 指標。SAP ASE 指標名稱的字首為 `asedb`。每個元件最多可新增 60 個指標。

1. 在 **ASE 組態**，輸入 SAP ASE 資料庫的使用者名稱和密碼。這是 Amazon CloudWatch 代理程式用來連線至 SAP ASE 資料庫的使用者名稱和密碼。

1. 在 **Custom alarms** (自訂警示) 下，您可以新增其他警示，以便由 CloudWatch Application Insights 監控。

1. 檢閱您的應用程式監控組態，然後選擇 **Submit** (提交)。當您提交組態時，您的帳戶會為 SAP HANA 系統更新所有指標和警示，這可能需要最多 2 小時。

## 設定警示閾值
<a name="appinsights-tutorial-sap-hana-configure-alarm-threshold"></a>

CloudWatch Application Insights 會自動建立 Amazon CloudWatch 指標和該指標的閾值，以觀察警示。當指標超過閾值達到指定的評估期間數，警示便會變更為 `ALARM ` 狀態。請注意，Application Insights 不會保留這些設定。

若要編輯單一指標的警示，請執行以下步驟：

1. 開啟 [CloudWatch 主控台](https://console.aws.amazon.com/cloudwatch)。

1. 在導覽窗格中，選擇 **Alarms** (警示) > **All alarms** (所有警示)。

1. 選取 CloudWatch Application Insights 自動建立警示旁的選項按鈕。然後選擇 **Actions** (動作)，然後從下拉選單中選取 **Edit** (編輯)。

1. 在 **Metric** (指標) 下編輯下列參數。

   1. 在 **Statistic** (統計數字) 下，選擇其中一個統計數字或預先定義的百分位數，或指定自訂的百分位數。例如 `p95.45`。

   1. 在 **Period** (期間) 下，選擇警示的評估期間。評估警示時，每個期間都會彙整為一個資料點。

1. 在 **Conditions** (條件) 下編輯下列參數。

   1. 選擇指標是否必須大於、小於，或等於閾值。

   1. 指定閾值。

1. 在 **Additional configuration** (其他組態) 下，編輯下列參數。

   1. 在 **Datapoints to alarm** (警示的資料點) 下，指定資料點數或評估期間 (必須處於 `ALARM` 狀態啟動警示)。當兩個值相符時，如果超過指定的連續週期數，系統會建立進入 `ALARM` 狀態的警示。若要建立 `n` 個的 `m` 個警示，請針對第一個資料點，指定低於第二個資料點的值。如需評估警示的詳細資訊，請參閱[評估警示](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Alarms.html#alarm-evaluation)。

   1. 在 **Missing data treatment** (遺失資料處理方式) 下，選擇警示在遺失某些資料點時的行為。如需遺失資料處理方式的詳細資訊，請參閱[設定 CloudWatch 警示如何處理遺失資料](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Alarms.html#alarms-and-missing-data)。

   1. 若警示使用百分位數作為監控統計資料，則會出現一個 **Percentiles with low samples (低樣本的百分位數)** 方塊。選擇是要評估還是忽略具有低抽樣率的案例。若您選擇 **ignore (maintain alarm state) (忽略 (維持警示狀態))**，則會在抽樣大小過低時一律維持目前的警示狀態。如需低範例百分位數的詳細資訊，請參閱 [以百分位數為基礎的警示和低資料範例](percentiles-with-low-samples.md)。

1. 選擇**下一步**。

1. 在 **Notification (通知)** 下，選取 SNS 主題來在警示處於 `ALARM` 狀態、`OK` 狀態或 `INSUFFICIENT_DATA` 狀態時進行通知。

1. 選擇 **Update alarm** (更新警示)。

## 檢視與針對 Application Insights 偵測到的 SAP ASE 問題進行疑難排解
<a name="appinsights-tutorial-sap-ase-troubleshooting-problems"></a>

本節可協助您解決在 Application Insights 上設定 SAP ASE 監控時所發生的常見故障診斷問題。

**SAP ASE 備份伺服器錯誤**  
您可透過查看動態建立的儀表板來識別錯誤訊息。儀表板會顯示 SAP ASE 備份伺服器中報告的錯誤訊息。如需有關 SAP ASE 備份伺服器日誌的詳細資訊，請參閱 [SAP 文件備份伺服器錯誤日誌記錄](https://help.sap.com/docs/SAP_ASE/aa939a27edb34f019f71cc47b9c0fd9a/a7aeb8b1bc2b10149ccf99b95687a64c.html)。

**SAP ASE 長時間執行的交易**  
識別長時間執行的交易，並確認其是否可停止或執行時間是否為有意設定。如需詳細資訊，請參閱 [2180410 - 如何顯示長時間執行交易的交易日誌記錄？ - SAP ASE](https://userapps.support.sap.com/sap/support/knowledge/en/2180410)。

**SAP ASE 使用者連線**  
檢閱 SAP ASE 資料庫是否已根據您想要在資料庫上執行的工作負載，相應地調整大小。如需詳細資訊，請參閱 SAP 文件中的[設定使用者連線](https://help.sap.com/docs/help/061ec8a5739842df9e505d8944fae8e2/9ea258fceaaa496eb80e17d3d5694ff6.html)。

**SAP ASE 磁碟空間**  
您可以查看動態建立的儀表板，識別造成問題的資料庫層。儀表板會顯示相關指標和日誌檔案程式碼片段。請務必了解磁碟增長的原因，並在適當的情況下增加實體磁碟大小、配置的磁碟空間或兩者。如需詳細資訊，請參閱 SAP 文件中的 [SAP 文件磁碟大小](https://help.sap.com/docs/SAP_ASE/e0d4539d39c34f52ae9ef822c2060077/ab22db00bc2b1014ad3ce047bbf117d7.html)。

## SAP ASE 的 Application Insights 疑難排解
<a name="appinsights-tutorial-sap-ase-troubleshooting-health-dashboard"></a>

本節提供的步驟可協助您解決 Application Insights 儀表板所傳回的常見錯誤。


| 錯誤 | 傳回的錯誤 | 根本原因 | Resolution | 
| --- | --- | --- | --- | 
|  無法新增超過 60 個監控指標。  |  `Component cannot have more than 60 monitored metric`  |  目前的指標限於每個元件 60 個監控指標。  |  移除不必要的指標以遵守限制。  | 
|  佈設程序之後，不會顯示 SAP 指標或警示  |  在 AWS Systems Manager中失敗的 `AWS-ConfigureAWSPackage` 上的 `run` 指令。輸出會顯示錯誤：`CT-LIBRARY error:``ct_connect(): protocol specific layer: external error: The attempt to connect to the server failed`  |  使用者名稱和密碼可能不正確。  |  確認使用者名稱和密碼有效，然後重新執行上架程序。  | 

# 教學課程：設定 SAP HANA 的監控
<a name="appinsights-tutorial-sap-hana"></a>

本教學課程示範如何設定 CloudWatch Application Insights，以設定 SAP HANA 資料庫的監控。您可以使用 CloudWatch Application Insights 自動儀表板，以視覺化方式呈現問題詳細資訊、加速疑難排解，並改進 SAP HANA 資料庫的平均解決時間 (MTTR)。

**Topics**
+ [支援的環境](#appinsights-tutorial-sap-hana-supported-environments)
+ [支援的作業系統](#appinsights-tutorial-sap-hana-supported-os)
+ [功能](#appinsights-tutorial-sap-hana-features)
+ [先決條件](#appinsights-tutorial-sap-hana-prerequisites)
+ [設定監控](#appinsights-tutorial-sap-hana-set-up)
+ [管理監控](#appinsights-tutorial-sap-hana-manage)
+ [為偵測到的問題進行疑難排解](#appinsights-tutorial-sap-hana-troubleshooting)
+ [異常偵測](#appinsights-tutorial-sap-hana-troubleshooting-anomaly-detection)
+ [Application Insights 疑難排解](#appinsights-tutorial-sap-hana-troubleshooting-health-dashboard)

## 支援的環境
<a name="appinsights-tutorial-sap-hana-supported-environments"></a>

CloudWatch Application Insights 支援下列系統和模式 AWS 的資源部署。您提供並安裝 SAP HANA 資料庫軟體和支援的 SAP 應用程式軟體。
+ **單一 Amazon EC2 執行個體上的 SAP HANA 資料庫** – SAP HANA 在單一節點、擴充規模的架構中，最多有 24 TB 的記憶體。
+ **多個 Amazon EC2 執行個體上的 SAP HANA 資料庫** – 多節點、水平擴展架構中的 SAP HANA。
+ **跨可用區域 SAP HANA 資料庫高可用性設定** – 使用 SUSE/RHEL 叢集跨兩個可用區域設定高可用性的 SAP HANA。

**注意**  
CloudWatch Application Insights 僅支援單一 SID HANA 環境。如果連接了多個 HANA SID，則僅為偵測到的第一個 SID 設定監控。

## 支援的作業系統
<a name="appinsights-tutorial-sap-hana-supported-os"></a>

適用於 SAP HANA 的 CloudWatch Application Insights 支援下列作業系統上的 x86-64 架構：
+ SuSE Linux 12 SP4 For SAP
+ SuSE Linux 12 SP5 For SAP
+ SuSE Linux 15
+ SuSE Linux 15 SP1
+ SuSE Linux 15 SP2
+ SuSE Linux 15 For SAP
+ SuSE Linux 15 SP1 For SAP
+ SuSE Linux 15 SP2 For SAP
+ SuSE Linux 15 SP3 For SAP
+ SuSE Linux 15 SP4 For SAP
+ SuSE Linux 15 SP5 For SAP
+ RedHat Linux 8.6 適用於具有高可用性和更新服務的 SAP
+ RedHat Linux 8.5 for SAP 搭配高可用性和更新服務
+ RedHat Linux 8.4 適用於具有高可用性和更新服務的 SAP
+ RedHat Linux 8.3 for SAP 搭配高可用性和更新服務
+ 具有高可用性和更新服務的 RedHat Linux 8.2 For SAP
+ 具有高可用性和更新服務的 RedHat Linux 8.1 For SAP
+ 具有高可用性和更新服務的 RedHat Linux 7.9 For SAP

## 功能
<a name="appinsights-tutorial-sap-hana-features"></a>

適用於 SAP HANA 的 CloudWatch Application Insights 提供下列功能：
+ 自動偵測 SAP HANA 工作負載 
+ 根據靜態閾值自動建立 SAP HANA 警示
+ 根據異常偵測自動建立 SAP HANA 警示
+ 自動 SAP HANA 日誌模式辨識 
+ SAP HANA 的運作狀態儀表板
+ SAP HANA 的問題儀表板

## 先決條件
<a name="appinsights-tutorial-sap-hana-prerequisites"></a>

您必須完成以下先決條件，使用 CloudWatch Application Insights 設定 SAP HANA 資料庫：
+ **SAP HANA**：在 Amazon EC2 執行個體上安裝執行中且可存取的 SAP HANA 資料庫 2.0 SPS05。
+ **SAP HANA 資料庫使用者**：必須在 SYSTEM 資料庫和所有租用戶中建立具有監控角色的資料庫使用者。

**範例**  
執行下列 SQL 命令可建立具有監控角色的使用者。

  ```
  su - <sid>adm
  hdbsql -u SYSTEM -p <SYSTEMDB password> -d SYSTEMDB
  CREATE USER CW_HANADB_EXPORTER_USER PASSWORD <Monitoring user password> NO FORCE_FIRST_PASSWORD_CHANGE;
  CREATE ROLE CW_HANADB_EXPORTER_ROLE;
  GRANT MONITORING TO CW_HANADB_EXPORTER_ROLE;
  GRANT CW_HANADB_EXPORTER_ROLE TO CW_HANADB_EXPORTER_USER;
  ```
+ **Python 3.8**：在作業系統中安裝 Python 3.8 或更高版本。使用最新版本的 Python。如果沒有在作業系統中偵測到 Python3，則會安裝 Python 3.6。

  如需更多資訊，請參閱[installation example](#install)。
**注意**  
SuSE Linux 15 SP4、RedHat Linux 8.6 及更新版本的作業系統需要手動安裝 Python 3.8 或更新版本。
+ **Pip3**：在作業系統上安裝安裝程式 pip3。如果沒有在您的作業系統上偵測到 pip3，則會安裝 pip3。
+ **hdbclient**：CloudWatch Application Insights 使用 python 驅動程式連線至 SAP HANA 資料庫。如果用戶端未安裝在 python3 下，請確定在 `/hana/shared/SID/hdbclient/` 下具有 hdbclient tar 檔案版本 `2.10 or later`。
+ **Amazon CloudWatch 代理程式** – 確保您沒有在 Amazon EC2 執行個體上執行預先存在的 CloudWatch 代理程式。若您安裝了 CloudWatch 代理程式，請確保從現有 CloudWatch 代理程式組態檔案中移除您要在 CloudWatch Application Insights 中使用的資源組態，以避免合併衝突。如需詳細資訊，請參閱[手動建立或編輯 CloudWatch 代理程式組態檔案](CloudWatch-Agent-Configuration-File-Details.md)。
+ **AWS Systems Manager 啟用** – 在執行個體上安裝 SSM Agent，且必須為 SSM 啟用執行個體。如需有關如何安裝 SSM Agent 的資訊，請參閱《*AWS Systems Manager 使用者指南*》中的[使用 SSM Agent](https://docs.aws.amazon.com/systems-manager/latest/userguide/ssm-agent.html)。
+ **Amazon EC2 執行個體角色** – 您必須連接下列 Amazon EC2 執行個體角色才能設定資料庫。
  + 您必須連接 `AmazonSSMManagedInstanceCore` 角色，以啟用 Systems Manager。如需詳細資訊，請參閱 [AWS Systems Manager 以身分為基礎的政策範例](https://docs.aws.amazon.com/systems-manager/latest/userguide/auth-and-access-control-iam-identity-based-access-control.html)。
  + 您必須連接 `CloudWatchAgentServerPolicy`，以便透過 CloudWatch 發出執行個體指標和日誌。如需詳細資訊，請參閱[《建立 IAM 角色和使用者以使用 CloudWatch 代理程式》](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-iam-roles-for-cloudwatch-agent.html)。
  + 您必須將下列 IAM 內嵌政策連接到 Amazon EC2 執行個體角色，才能讀取存放在 AWS Secrets Manager中的密碼。如需內嵌政策的詳細資訊，請參閱《*AWS Identity and Access Management 使用者指南*》中的[內嵌政策](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_managed-vs-inline.html)。

------
#### [ JSON ]

****  

    ```
    {
        "Version":"2012-10-17",		 	 	 
        "Statement": [
            {
                "Sid": "VisualEditor0",
                "Effect": "Allow",
                "Action": [
                    "secretsmanager:GetSecretValue"
                ],
                "Resource": "arn:aws:secretsmanager:*:*:secret:ApplicationInsights-*"
            }
        ]
    }
    ```

------
+ **AWS 資源群組** – 您必須建立資源群組，其中包含應用程式堆疊用來將應用程式加入 CloudWatch Application Insights 的所有相關 AWS 資源。這包括執行 SAP HANA 資料庫的 Amazon EC2 執行個體和 Amazon EBS 磁碟區。如果每個帳戶有多個資料庫，建議您建立一個資源群組，其中包含每個 SAP HANA 資料庫系統 AWS 的資源。
+ **IAM 許可** - 對於非管理員使用者：
  +  您必須建立 AWS Identity and Access Management (IAM) 政策，允許 Application Insights 建立服務連結角色，並將其連接到您的使用者身分。如需連接政策的步驟，請參閱 [CloudWatch Application Insights 的 IAM 政策](appinsights-iam.md)。
  + 使用者必須具有在 中建立秘密的許可 AWS Secrets Manager ，才能存放資料庫使用者登入資料。如需詳細資訊，請參閱[範例：建立機密的許可](https://docs.aws.amazon.com/secretsmanager/latest/userguide/auth-and-access_examples.html#auth-and-access_examples_create)。

------
#### [ JSON ]

****  

    ```
    {
      "Version":"2012-10-17",		 	 	 
      "Statement": [
        {
          "Effect": "Allow",
          "Action": [
            "secretsmanager:CreateSecret"
          ],
          "Resource": "arn:aws:secretsmanager:*:*:secret:ApplicationInsights-*"
        }
      ]
    }
    ```

------
+ **服務連結角色** – Application Insights 使用 AWS Identity and Access Management (IAM) 服務連結角色。系統會在您於 Application Insights 主控台建立第一個 Application Insights 應用程式時，為您建立服務連結角色。如需詳細資訊，請參閱[針對 CloudWatch Application Insights 使用服務連結角色](CHAP_using-service-linked-roles-appinsights.md)。

## 設定您的 SAP HANA 資料庫以進行監控
<a name="appinsights-tutorial-sap-hana-set-up"></a>

使用下列步驟設定 SAP HANA 資料庫的監控

1. 開啟 [CloudWatch 主控台](https://console.aws.amazon.com/cloudwatch)。

1. 從左側導覽窗格中，選擇 **Insights** 下的 **Application Insights**。

1. **Application Insights** 頁面會顯示 Application Insights 監控的應用程式清單，以及每個應用程式的監控狀態。在右上角，選擇 **Add an application** (新增應用程式)。

1. 在 **Specify application details** (指定應用程式詳細資訊) 頁面上，從 **Resource group** (資源群組) 的下拉清單中選取 AWS 資源群組，其中包含您的 SAP HANA 資料庫資源。如果尚未建立應用程式的資源群組，您可以透過選擇 **Resource group** (資源群組) 下拉單中的 **Create new resource group** (建立新的資源群組) 建立一個。如需建立資源群組的詳細資訊，請參閱《[https://docs.aws.amazon.com/ARG/latest/userguide/resource-groups.html](https://docs.aws.amazon.com/ARG/latest/userguide/resource-groups.html)》。

1. 在**監控 CloudWatch Events** 下，選取核取方塊以整合 Application Insights 監控與 CloudWatch Events，從 Amazon EBS、Amazon EC2 AWS CodeDeploy、Amazon ECS、 AWS Health APIs和通知、Amazon RDS、Amazon S3 和 取得洞見 AWS Step Functions。

1. 在**與 AWS Systems Manager OpsCenter 整合**下，選取 **Generate AWS Systems Manager OpsCenter OpsItems ** 旁的核取方塊，以在偵測到所選應用程式的問題時檢視和取得通知。若要追蹤為了解決與 AWS 資源相關的操作工作項目而執行的操作，稱為 OpsItems，請提供 SNS 主題 ARN。

1. 您可以選擇輸入標籤協助您識別和整理資源。CloudWatch Application Insights 支援標籤型和 CloudFormation 堆疊型資源群組，但 Application Auto Scaling 群組除外。如需詳細資訊，請參閱 *AWS Resource Groups 和標籤使用者指南*中的[標籤編輯器](https://docs.aws.amazon.com/ARG/latest/userguide/tag-editor.html)。

1. 選擇 **Next** (下一個) 繼續設定監控。

1. 在**檢閱偵測到的元件**頁面上，系統會列出 CloudWatch Application Insights 自動偵測到的受監控元件及其工作負載。

   1. 若要將工作負載新增至包含偵測到的 SAP HANA 單一節點工作負載的元件，請選取該元件，然後選擇**編輯元件**。
**注意**  
包含偵測到的 SAP HANA 多節點或 HANA 高可用性工作負載的元件，一個元件上僅支援一個工作負載。  
![\[CloudWatch Application Insights 主控台的「檢閱元件以供監控之用」頁面：選取要編輯的元件。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-multiapp-hana-review.png)

   1. 若要新增工作負載，請選擇**新增工作負載**。  
![\[CloudWatch Application Insights 主控台的「編輯元件」區段：選擇左下角的按鈕以新增工作負載。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-multiapp-hana-edit.png)

   1. 完成編輯工作負載後，請選擇**儲存變更**。

1. 選擇**下一步**。

1. 在**指定元件詳細資訊**頁面上，輸入使用者的使用者名稱和密碼。

1. 檢閱您的應用程式監控組態，然後選擇 **Submit** (提交)。

1. 應用程式詳細資訊頁面隨即開啟，您可以在其中檢視**應用程式摘要**、**受監控元件和工作負載**的清單，以及**未受監控元件和工作負載**。如果選取元件或工作負載旁邊的選項按鈕，則您也可以檢視**組態歷史記錄**、**日誌模式**，以及任何已建立的**標籤**。當您提交組態時，您的帳戶會為 SAP HANA 系統部署所有指標和警示，這可能需要最多 2 小時。

## 管理 SAP HANA 資料庫的監控
<a name="appinsights-tutorial-sap-hana-manage"></a>

您可以執行下列步驟來管理 SAP HANA 資料庫的使用者憑證、指標和日誌路徑：

1. 開啟 [CloudWatch 主控台](https://console.aws.amazon.com/cloudwatch)。

1. 從左側導覽窗格中，選擇 **Insights** 下的 **Application Insights**。

1. **Application Insights** 頁面會顯示 Application Insights 監控的應用程式清單，以及每個應用程式的監控狀態。

1. 在 **Monitored components** (受監控元件) 下，選取元件名稱旁的選項按鈕。然後，選擇 **Manage monitoring** (管理監控)。

1. 在 **EC2 instance group logs** (EC2 執行個體群組日誌) 下，您可以更新現有的日誌路徑、日誌模式集和記錄群組名稱。此外，您可以新增最多三個額外 **Application logs** (應用程式日誌)。

1. 在 **Metrics** (指標) 下，您可以根據需求選擇 SAP HANA 指標。SAP HANA 指標名稱的字首為 `hanadb`。每個元件最多可新增 40 個指標。

1. 在 **HANA configuration** (HANA 組態) 下，輸入 SAP HANA 資料庫的密碼和使用者名稱。這是 Amazon CloudWatch 代理程式用來連線至 SAP HANA 資料庫的使用者名稱和密碼。

1. 在 **Custom alarms** (自訂警示) 下，您可以新增其他警示，以便由 CloudWatch Application Insights 監控。

1. 檢閱您的應用程式監控組態，然後選擇 **Submit** (提交)。當您提交組態時，您的帳戶會為 SAP HANA 系統更新所有指標和警示，這可能需要最多 2 小時。

## 檢視與針對 CloudWatch Application Insights 偵測到的 SAP HANA 問題進行疑難排解
<a name="appinsights-tutorial-sap-hana-troubleshooting"></a>

下列各節提供的步驟可協助您解決在 Application Insights 上設定 SAP HANA 監控時所發生的常見疑難排解案例。

**Topics**
+ [SAP HANA 資料庫達到記憶體配置上限](#appinsights-tutorial-sap-hana-troubleshooting-memory)
+ [磁碟已滿事件](#appinsights-tutorial-sap-hana-troubleshooting-disk-full)
+ [SAP HANA 備份已停止執行](#appinsights-tutorial-sap-hana-troubleshooting-backup-stopped)

### SAP HANA 資料庫達到記憶體配置上限
<a name="appinsights-tutorial-sap-hana-troubleshooting-memory"></a>

**Description**  
由 SAP HANA 資料庫提供技術的 SAP 應用程式因高記憶體壓力而發生故障，導致應用程式效能降低。

**Resolution**  
您可以檢查顯示相關指標和日誌檔案程式碼片段的動態建立儀表板，找出造成問題的應用程式層。在下列範例中，問題可能是因為 SAP HANA 系統中的大型資料負載而產生。

![\[記憶體配置超出。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-memory-allocation-1.png)


使用的記憶體配置超過總記憶體配置上限閾值的 80%。

![\[顯示記憶體容量不足的日誌群組。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-memory-allocation-2.png)


日誌群組會顯示記憶體容量不足的結構描述 `BNR-DATA` 和資料表 `IMDBMASTER_30003`。此外，日誌群組會顯示問題的確切時間、目前的全域位置限制、共用記憶體、程式碼大小和 OOM 保留區配置大小。

![\[日誌群組文字。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-memory-allocation-3.png)


### 磁碟已滿事件
<a name="appinsights-tutorial-sap-hana-troubleshooting-disk-full"></a>

**Description**  
SAP HANA 資料庫提供技術的 SAP 應用程式停止回應，這會導致無法存取資料庫。

**Resolution**  
您可以檢查顯示相關指標和日誌檔案程式碼片段的動態建立儀表板，找出造成問題的資料庫層。在下列範例中，問題可能是系統管理員無法啟用自動日誌備份，造成 sap/hana/log 目錄填滿。

![\[顯示記憶體容量不足的日誌群組。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-disk-full-1.png)


問題儀表板中的日誌群組小工具會顯示 `DISKFULL` 事件。

![\[顯示記憶體容量不足的日誌群組。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-disk-full-2.png)


### SAP HANA 備份已停止執行
<a name="appinsights-tutorial-sap-hana-troubleshooting-backup-stopped"></a>

**Description**  
SAP HANA 資料庫提供技術的 SAP 應用程式已停止運作。

**Resolution**  
您可以檢查顯示相關指標和日誌檔案程式碼片段的動態建立儀表板，找出造成問題的資料庫層。

問題儀表板中的日誌群組小工具會顯示 `ACCESS DENIED` 事件。這包括其他資訊，例如 S3 儲存貯體、S3 儲存貯體資料夾和 S3 儲存貯體區域。

![\[顯示記憶體容量不足的日誌群組。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-backup-stopped-2.png)


## SAP HANA 的異常偵測
<a name="appinsights-tutorial-sap-hana-troubleshooting-anomaly-detection"></a>

對於特定的 SAP HANA 指標 (例如執行緒計數)，CloudWatch 會套用統計和機器學習演算法來定義閾值。這些演算法會在使用者介入程度最低的情況下，持續分析 SAP HANA 資料庫的指標、判斷正常基準以及表面異常情況。演算法會產生異常偵測模型，模型會產生預期值範圍，代表正常指標行為。

異常偵測演算法會考慮指標的季節性和趨勢變化。季節性變化可能是每小時、每日或每週，如下列 SAP HANA CPU 使用率範例所示。

![\[顯示記憶體容量不足的日誌群組。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-anomaly-detection.png)


建立模型後，CloudWatch 異常偵測會持續評估模型並對模型進行調整，從而確保模型盡可能精確。這包括重新訓練模型，以調整指標值是否隨著時間而演變，或是遇到突然變化。它還包括預測，以改善季節性，尖峰或稀疏指標的模型。

## SAP HANA 的 Application Insights 疑難排解
<a name="appinsights-tutorial-sap-hana-troubleshooting-health-dashboard"></a>

本節提供的步驟可協助您解決 Application Insights 儀表板所傳回的常見錯誤。

### 無法新增超過 60 個監控指標
<a name="cant-add-greater-sixty-metrics"></a>

輸出會顯示下列錯誤。

```
Component cannot have more than 60 monitored metrics
```

**根本原因**：目前的指標限於每個元件 60 個監控指標。

**解決方案**：若要保持在限制範圍內，請移除不需要的指標。

### 佈設程序之後，不會顯示 SAP 指標
<a name="no-sap-metrics-appear"></a>

使用下列資訊來明確 SAP 指標在加入程序之後為何不會顯示在儀表板上。第一步是疑難排解為什麼 SAP 指標不會使用來自 Amazon EC2 執行個體的 AWS 管理主控台 或 Exporter 日誌顯示。然後，檢閱錯誤輸出以尋找解決方案。

#### 疑難排解為何 SAP 指標在佈建後未顯示
<a name="w2aac26c20c27c27b7b5"></a>

您可以從 Amazon EC2 執行個體使用 AWS 管理主控台 或匯出器日誌進行故障診斷。

------
#### [ AWS 管理主控台 ]

**使用主控台針對佈建後未出現 SAP 指標的問題進行疑難排解**

1. 在 https：//[https://console.aws.amazon.com/systems-manager/](https://console.aws.amazon.com/systems-manager/) 開啟 AWS Systems Manager 主控台。

1. 在左側導覽窗格中，選擇 **State Manager**。

1. 在**關聯**下，檢查文件 `AWSEC2-ApplicationInsightsCloudwatchAgentInstallAndConfigure` 的狀態。如果狀態為 `Failed`，請在**執行 ID** 下選取失敗的 ID 並檢視輸出。

1. 在**關聯**下，檢查文件 `AWS-ConfigureAWSPackage` 的狀態。如果狀態為 `Failed`，請在**執行 ID** 下選取失敗的 ID 並檢視輸出。

------
#### [ Exporter logs from Amazon EC2 instance ]

**使用匯出工具日誌針對佈建後未出現 SAP 指標的問題進行疑難排解**

1. 連線至執行 SAP HANA 資料庫的 Amazon EC2 執行個體。

1. <a name="step-find-short-name"></a>使用下列命令來尋找 `WORKLOAD_SHORT_NAME` 的正確命名慣例。將會在下列兩個步驟中使用此簡短名稱。

   ```
   sudo systemctl | grep exporter
   ```
**注意**  
Application Insights 會根據執行中的工作負載，將尾碼 `WORKLOAD_SHORT_NAME` 新增至服務名稱。SAP HANA 單一節點、多個節點和高可用性部署的簡短名稱為 `HANA_SN`、`HANA_MN` 和 `HANA_HA`。

1. 若要檢查匯出工具管理器服務日誌中的錯誤，請執行下列命令，將 `WORKLOAD_SHORT_NAME` 取代為您在 [Step 2](#step-find-short-name) 中找到的簡短名稱。

   ```
   sudo journalctl -e --unit=prometheus-hanadb_exporter_manager_WORKLOAD_SHORT_NAME.service
   ```

1. 如果匯出工具管理器服務日誌未顯示錯誤，請執行下列命令，檢查匯出工具服務日誌中的錯誤。

   ```
   sudo journalctl -e --unit=prometheus-hanadb_exporter_WORKLOAD_SHORT_NAME.service
   ```

------

#### 解決 SAP 指標在佈建後未出現的常見根本原因
<a name="resolve-root-causes-sap-metrics"></a>

下列範例說明如何解決 SAP 指標在佈建後未出現的常見根本原因。
+ 輸出會顯示下列錯誤。

  ```
  Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/default ...
  Reading json config file path: /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/ssm_AmazonCloudWatch-ApplicationInsights-SSMParameterForTESTCWEC2INSTANCEi0d88867f1f3e36285.tmp ...
  2023/11/30 22:25:17 Failed to merge multiple json config files.
  2023/11/30 22:25:17 Failed to merge multiple json config files.
  2023/11/30 22:25:17 Under path : /metrics/append_dimensions | Error : Different values are specified for append_dimensions
  2023/11/30 22:25:17 Under path : /metrics/metrics_collected/disk | Error : Different values are specified for disk
  2023/11/30 22:25:17 Under path : /metrics/metrics_collected/mem | Error : Different values are specified for mem
  2023/11/30 22:25:17 Configuration validation first phase failed. Agent version: 1.0. Verify the JSON input is only using features supported by this version.
  ```

  **解決方案**：Application Insights 正在嘗試設定與現有 CloudWatch 代理程式組態檔案中預先設定的指標相同的指標。從 `/opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.d/` 下移除現有檔案，或者從現有的 CloudWatch 代理程式組態檔案中移除導致衝突的指標。
+ 輸出會顯示下列錯誤。

  ```
  Unable to find a host with system database, for more info rerun using -v
  ```

  **解決方案**：使用者名稱、密碼或資料庫連接埠可能不正確。確認使用者名稱、密碼和連接埠有效，然後重新執行佈建程序。
+ 輸出會顯示下列錯誤。

  ```
  This hdbcli installer is not compatible with your Python interpreter
  ```

  **解決方案**：升級 pip3 和 wheel，如下列 Python 3.6 範例所示。

  ```
  python3.6 -m pip install --upgrade pip setuptools wheel
  ```
+ 輸出會顯示下列錯誤。

  ```
  Unable to install hdbcli using pip3. Please try to install it
  ```

  **解決方案**：確認已遵循 `hdbclient` 先決條件或在 pip3 下手動安裝 `hdbclient`。
+ 輸出會顯示下列錯誤。

  ```
  Package 'boto3' requires a different Python: 3.6.15 not in '>= 3.7'
  ```

  **解決方案**：此作業系統版本需要 Python 3.8 或更高版本。檢查 Python 3.8 先決條件並進行安裝。
+ 輸出會顯示下列其中一個安裝錯誤。

  ```
  Can not execute `setup.py` since setuptools is not available in the build environment
  ```

  或

  ```
  [SSL: CERTIFICATE_VERIFY_FAILED]
  ```

  **解決方案**：使用 SUSE Linux 命令來安裝 Python，如下列範例所示。下列範例會安裝最新版本的 [Python 3.8](https://www.python.org/downloads/)。

  ```
  wget https://www.python.org/ftp/python/3.8.<LATEST_RELEASE>/Python-3.8.<LATEST_RELEASE>.tgz
  tar xf Python-3.*
  cd Python-3.*/
  sudo zypper install make gcc-c++ gcc automake autoconf libtool
  sudo zypper install zlib-devel
  sudo zypper install libopenssl-devel libffi-devel
  ./configure --with-ensurepip=install 
  sudo make
  sudo make install
  sudo su 
  python3.8 -m pip install --upgrade pip setuptools wheel
  ```

# 教學課程：設定 SAP NetWeaver 的監控
<a name="appinsights-tutorial-sap-netweaver"></a>

本教學課程示範如何設定 Amazon CloudWatch Application Insights，以設定 SAP NetWeaver 的監控。您可以使用 CloudWatch Application Insights 自動儀表板，以視覺化方式呈現問題詳細資訊、加速疑難排解，並減少 SAP NetWeaver 應用程式伺服器的平均解決時間 (MTTR)。

**Topics**
+ [支援的環境](#appinsights-tutorial-sap-netweaver-supported-environments)
+ [支援的作業系統](#appinsights-tutorial-sap-netweaver-supported-os)
+ [功能](#appinsights-tutorial-sap-netweaver-features)
+ [先決條件](#appinsights-tutorial-sap-netweaver-prerequisites)
+ [設定監控](#appinsights-tutorial-sap-netweaver-set-up)
+ [管理監控](#appinsights-tutorial-sap-netweaver-manage)
+ [對問題進行疑難排解](#appinsights-tutorial-sap-netweaver-troubleshooting)
+ [Application Insights 疑難排解](#appinsights-tutorial-sap-netweaver-troubleshooting-health-dashboard)

## 支援的環境
<a name="appinsights-tutorial-sap-netweaver-supported-environments"></a>

CloudWatch Application Insights 支援下列系統和模式 AWS 的資源部署。
+ **SAP NetWeaver 標準系統部署。**
+ **在多個 Amazon EC2 執行個執行個體上的 SAP NetWeaver 分散式部署。**
+ **跨可用區域 SAP NetWeaver 高可用性設定**：使用 SUSE/RHEL 叢集跨兩個可用區域設定高可用性的 SAP NetWeaver。

## 支援的作業系統
<a name="appinsights-tutorial-sap-netweaver-supported-os"></a>

適用於 SAP NetWeaver 的 CloudWatch Application Insights 支援下列作業系統：
+ Oracle Linux 8
+ Red Hat Enterprise Linux 7.6
+ Red Hat Enterprise Linux 7.7
+ Red Hat Enterprise Linux 7.9
+ Red Hat Enterprise Linux 8.1
+ Red Hat Enterprise Linux 8.2
+ Red Hat Enterprise Linux 8.4
+ Red Hat Enterprise Linux 8.6
+ SUSE Linux Enterprise Server 15 for SAP
+ SUSE Linux Enterprise Server 15 SP1 for SAP
+ SUSE Linux Enterprise Server 15 SP2 for SAP
+ SUSE Linux Enterprise Server 15 SP3 for SAP
+ SUSE Linux Enterprise Server 15 SP4 for SAP
+ SUSE Linux Enterprise Server 12 SP4 for SAP
+ SUSE Linux Enterprise Server 12 SP5 for SAP
+ SUSE Linux Enterprise Server 15，高可用性模式除外
+ SUSE Linux Enterprise Server 15 SP1，高可用性模式除外
+ SUSE Linux Enterprise Server 15 SP2，高可用性模式除外
+ SUSE Linux Enterprise Server 15 SP3，高可用性模式除外
+ SUSE Linux Enterprise Server 15 SP4，高可用性模式除外
+ SUSE Linux Enterprise Server 12 SP4，高可用性模式除外
+ SUSE Linux Enterprise Server 12 SP5，高可用性模式除外

## 功能
<a name="appinsights-tutorial-sap-netweaver-features"></a>

適用於 SAP NetWeaver 7.0x–7.5x 的 CloudWatch Application Insights (包含 ABAP 平台) 提供下列功能：
+ 自動 SAP NetWeaver 工作負載偵測 
+ 根據靜態閾值自動建立 SAP NetWeaver 警示
+ 自動 SAP NetWeaver 日誌模式辨識 
+ SAP NetWeaver 的運作狀態儀表板
+ SAP NetWeaver 的問題儀表板

## 先決條件
<a name="appinsights-tutorial-sap-netweaver-prerequisites"></a>

您必須滿足以下先決條件，才能使用 CloudWatch Application Insights 設定 SAP NetWeaver：
+ **AWS Systems Manager 啟用** – 在 Amazon EC2 執行個體上安裝 SSM Agent，並啟用 SSM 執行個體。如需有關如何安裝 SSM Agent 的資訊，請參閱*《AWS Systems Manager 使用者指南》*中的[設定 AWS Systems Manager](https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-setting-up.html)。
+ **Amazon EC2 執行個體角色**：您必須連接下列 Amazon EC2 執行個體角色才能設定 SAP NetWeaver 監控。
  + 您必須連接 `AmazonSSMManagedInstanceCore` 角色，以啟用 Systems Manager。如需詳細資訊，請參閱 [AWS Systems Manager 以身分為基礎的政策範例](https://docs.aws.amazon.com/systems-manager/latest/userguide/auth-and-access-control-iam-identity-based-access-control.html)。
  + 您必須連接 `CloudWatchAgentServerPolicy` 政策，以便透過 CloudWatch 發出執行個體指標和日誌。如需詳細資訊，請參閱[《建立 IAM 角色和使用者以使用 CloudWatch 代理程式》](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-iam-roles-for-cloudwatch-agent.html)。
+ **AWS 資源群組** – 您必須建立資源群組，其中包含應用程式堆疊用於將應用程式加入 CloudWatch Application Insights 的所有相關 AWS 資源。這包括在 SAP NetWeaver 應用程式伺服器上執行的 Amazon EC2 執行個體、Amazon EFS 和 Amazon EBS 磁碟區。如果每個帳戶有多個 SAP NetWeaver 系統，我們建議您建立一個資源群組，其中包含每個 SAP NetWeaver 系統 AWS 的資源。如需有關建立資源群組的詳細資訊，請參閱[《AWS 資源群組和標籤使用者指南**》](https://docs.aws.amazon.com/ARG/latest/userguide/resource-groups.html)。
+ **IAM 許可** – 對於沒有管理存取權的使用者，您必須建立允許 Application Insights 建立服務連結角色並將其連接到使用者身分的 AWS Identity and Access Management (IAM) 政策。如需有關如何建立政策的更多資訊，請參閱 [IAM 政策](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/appinsights-iam.html)。
+ **服務連結角色** – Application Insights 使用 AWS Identity and Access Management (IAM) 服務連結角色。系統會在您於 Application Insights 主控台建立第一個 Application Insights 應用程式時，為您建立服務連結角色。如需詳細資訊，請參閱[針對 CloudWatch Application Insights 使用服務連結角色](CHAP_using-service-linked-roles-appinsights.md)。
+ **Amazon CloudWatch 代理程式** — Application Insights 會安裝並設定 CloudWatch 代理程式。若您已安裝 CloudWatch 代理程式，Application Insights 會保留您的組態。若要避免合併衝突，請從現有的 CloudWatch 代理程式組態檔案中移除您要在 Application Insights 中使用的資源組態。如需詳細資訊，請參閱[手動建立或編輯 CloudWatch 代理程式組態檔案](CloudWatch-Agent-Configuration-File-Details.md)。

## 設定 SAP NetWeaver 應用程式伺服器以進行監控
<a name="appinsights-tutorial-sap-netweaver-set-up"></a>

使用下列步驟為 SAP NetWeaver 應用程式伺服器設定監控。

**設定監控**

1. 開啟 [CloudWatch 主控台](https://console.aws.amazon.com/cloudwatch)。

1. 在左側導覽窗格中，選取 **Insights** 下的 **Application Insights**。

1. **Application Insights** 頁面會顯示 Application Insights 監控的應用程式清單，以及每個應用程式的監控狀態。在右上角，選取 **Add an application** (新增應用程式)。

1. 在 **Specify application details** (指定應用程式詳細資訊) 頁面上，從 **Resource group** (資源群組) 的下拉式清單中選取您建立的 AWS 資源群組，其中包含您的 SAP NetWeaver 資源。如果尚未建立應用程式的資源群組，您可以透過選擇 **Resource group** (資源群組) 下拉式清單中的 **Create new resource group** (建立新的資源群組) 建立一個。

1. 在 **Automatic monitoring of new resources** (自動監控新資源) 下，選取核取方塊，以允許 Application Insights 在加入後自動監控新增至應用程式資源群組的資源。

1. 在**監控 EventBridge 事件**下，選取核取方塊，將 Application Insights 監控與 CloudWatch Events 整合，以取得來自 Amazon EBS、Amazon EC2、 AWS CodeDeploy、Amazon ECS、 AWS Health APIs和通知、Amazon RDS、Amazon S3 和 的洞見 AWS Step Functions。

1. 在**與 AWS Systems Manager OpsCenter 整合**下，選取 **Generate AWS Systems Manager OpsCenter OpsItems ** 旁的核取方塊，以便在偵測到所選應用程式的問題時，檢視和取得通知。若要追蹤為了解決與 AWS 資源相關的操作工作項目而執行的操作，稱為 [OpsItems](https://docs.aws.amazon.com/systems-manager/latest/userguide/OpsCenter-getting-started-sns.html)，請提供 SNS 主題 ARN。

1. 您可以選擇輸入標籤協助您識別和整理資源。CloudWatch Application Insights 支援標籤型和 CloudFormation 堆疊型資源群組，但 Application Auto Scaling 群組除外。如需詳細資訊，請參閱 *AWS Resource Groups 和標籤使用者指南*中的[標籤編輯器](https://docs.aws.amazon.com/ARG/latest/userguide/tag-editor.html)。

1. 若要檢閱偵測到的元件，請選擇**下一步**。

1. 在**檢閱偵測到的元件**頁面上，系統會列出 CloudWatch Application Insights 自動偵測到的受監控元件及其工作負載。

   1. 若要編輯工作負載類型和名稱，請選擇**編輯元件**。
**注意**  
包含偵測到的 NetWeaver 分散式或 NetWeaver 高可用性工作負載的元件，一個元件上僅支援一個工作負載。  
![\[CloudWatch Application Insights 主控台的「檢閱偵測到的元件」區段：可編輯元件的清單。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-multiapp-netweaver.png)

1. 選擇 **Next (下一步)**。

1. 在 **Specify component details** (指定元件詳細資訊) 頁面上，選擇 **Next** (下一步)。

1. 檢閱您的應用程式監控組態，然後選擇**提交**。

1. 應用程式詳細資訊頁面隨即開啟，您可以在其中檢視**應用程式摘要**、**儀表板**、**元件**和**工作負載**。您也可以檢視 **Configuration history** (組態歷史記錄)、**Log patterns** (日誌模式)，以及任何已建立的 **Tags** (標籤)。您提交應用程式之後，CloudWatch Application Insights 會為 SAP NetWeaver 系統部署所有指標和警示，這最多可能需要一小時。

## 管理 SAP NetWeaver 應用程式伺服器的監控
<a name="appinsights-tutorial-sap-netweaver-manage"></a>

使用下列步驟管理 SAP NetWeaver 應用程式伺服器的監控。

**管理監控**

1. 開啟 [CloudWatch 主控台](https://console.aws.amazon.com/cloudwatch)。

1. 在左側導覽窗格中，選取 **Insights** 下的 **Application Insights**。

1. 選擇 **List view** (清單檢視) 索引標籤。

1. **Application Insights** 頁面會顯示 Application Insights 監控的應用程式清單，以及每個應用程式的監控狀態。

1. 選取您的應用程式。

1. 選擇 **Components** (元件) 索引標籤。

1. 在 **Monitored components** (受監控元件) 下，選取元件名稱旁的選項按鈕。然後，選取 **Manage monitoring** (管理監控)。

1. 在 **Instance logs** (執行個體日誌) 下，您可以更新現有的日誌路徑、日誌模式集和日誌群組名稱。此外，您可以新增最多三個額外 **Application logs** (應用程式日誌)。

1. 在 **Metrics** (指標) 下，您可以根據需求選取 SAP NetWeaver 指標。SAP NetWeaver 指標名稱的字首為 `sap`。每個元件最多可新增 40 個指標。

1. 在 **Custom alarms** (自訂警示) 下，您可以新增其他警示，以便由 CloudWatch Application Insights 監控。

1. 檢閱您的應用程式監控組態，然後選擇 **Save** (儲存)。您提交組態後，您的帳戶會為 SAP NetWeaver 系統更新所有指標和警示。

## 檢視 CloudWatch Application Insights 偵測到的 SAP NetWeaver 問題並進行疑難排解
<a name="appinsights-tutorial-sap-netweaver-troubleshooting"></a>

下列各節提供的步驟可協助您解決在 Application Insights 上設定 SAP NetWeaver 監控時所發生的常見疑難排解案例。

**Topics**
+ [SAP NetWeaver 資料庫連線問題](#appinsights-tutorial-sap-netweaver-troubleshooting-database)
+ [SAP NetWeaver 應用程式可用性問題](#appinsights-tutorial-sap-netweaver-troubleshooting-availability)

### SAP NetWeaver 資料庫連線問題
<a name="appinsights-tutorial-sap-netweaver-troubleshooting-database"></a>

**描述**  
您的 SAP NetWeaver 應用程式遇到資料庫連線問題。

**原因**  
您可以前往 CloudWatch Application Insights 主控台，並檢查 SAP NetWeaver Application Insights 問題儀表板，以識別連線問題。選取 **Problem summary** (問題摘要) 下方的連結，即可查看特定問題。

![\[CloudWatch Application Insights 的偵測問題儀表板，在 Problem summary (問題摘要) 資料欄中 Detected problems (偵測到的問題) 區段下方包含詳細資訊。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-database-connectivity-1.png)


在下列範例中，在 **Problem summary** (問題摘要) 下，SAP：可用性是問題所在。

![\[Problem summary (問題摘要) 區段下方的 CloudWatch Application Insights Problem summary (問題摘要) 頁面。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-database-connectivity-2.png)


緊接在 **Problem summary** (問題摘要) 之後，**Insight** 區段會提供有關錯誤以及您可以從何處取得有關問題原因的詳細資訊。

![\[CloudWatch Application Insights 的 Problem insight (問題洞見) 中包含有關錯誤原因的其他資訊。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-database-connectivity-3.png)


在此相同的問題儀表板上，您可以檢視問題偵測功能已進行分組的相關日誌和指標，以協助您隔離錯誤的原因。`sap_alerts_Availability` 指標會追蹤 SAP NetWeaver 系統在一段時間內的可用性。您可以使用歷史追蹤來關聯指標何時啟動錯誤狀態或超出警示閾值。在下列範例中，SAP NetWeaver 系統出現可用性問題。此範例會顯示兩個警示，因為有兩個 SAP 應用程式伺服器執行個體，已針對每個執行個體建立一個警示。

![\[CloudWatch Application Insights 的 SAP 可用性指標，其中包含有關錯誤發生時間歷史記錄的其他資訊。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-database-connectivity-4.png)


如需有關每個警示的詳細資訊，請將滑鼠游標暫留在 `sap_alerts_Availability` 指標名稱上。

![\[CloudWatch Application Insights 的 SAP 可用性指標，其中包含有關錯誤的其他詳細資訊。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-database-connectivity-5.png)


在下列範例中，`sap_alerts_Database` 指標顯示資料庫層發生問題或故障。此警示表示 SAP NetWeaver 在連線至其資料庫或與其資料庫進行通訊時發生問題。

![\[CloudWatch Application Insights 的 SAP 資料庫指標，其中包含錯誤發生時間的其他歷史記錄。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-database-connectivity-6.png)


由於資料庫是 SAP NetWeaver 的重要資源，因此當資料庫發生問題或故障時，您可能會收到許多相關警示。在下列範例中，因為無法使用資料庫，所以會啟動 `sap_alerts_FrontendResponseTime` 和 `sap_alerts_LongRunners` 指標。

![\[因為資料庫故障而建立的 CloudWatch Application Insights 其他 SAP 資料庫指標。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-database-connectivity-7.png)


**解決方案**  
Application Insights 會每小時監控偵測到的問題。如果 SAP NetWeaver 日誌檔案中沒有新的相關日誌項目，較舊的日誌項目會被視為已解決。您必須修正與 CloudWatch 警示相關的任何錯誤情況。修復錯誤條件後，當警示和日誌復原時，警示就會解決。所有 CloudWatch 日誌錯誤和警示都解決後，Application Insights 會停止偵測錯誤，並在一小時內自動解決問題。我們建議您解決所有日誌錯誤狀況和警示，以便在問題儀表板上找到最新的問題。

在下列範例中，SAP 可用性問題已解決。

![\[CloudWatch Application Insights 問題儀表板，其中包含解決的 SAP 可用性問題。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-database-connectivity-resolved.png)


### SAP NetWeaver 應用程式可用性問題
<a name="appinsights-tutorial-sap-netweaver-troubleshooting-availability"></a>

**描述**  
SAP NetWeaver 高可用性排入佇列複寫已停止運作。

**原因**  
您可以前往 CloudWatch Application Insights 主控台，並檢查 SAP NetWeaver Application Insights 問題儀表板，以識別連線問題。選取 **Problem summary** (問題摘要) 下方的連結，即可查看特定問題。

![\[CloudWatch Application Insights 中的問題儀表板，其中包含 Problem summary (問題摘要) 下的詳細資訊。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-app-availability-problem-dashboard.png)


在下列範例中，在 **Problem summary** (問題摘要) 下，高可用性排入佇列複寫就是問題所在。

![\[CloudWatch Application Insights 中的 Problem summary (問題摘要)，其中包含 SAP 可用性：列出的排入佇列複寫錯誤。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-app-availability-1.png)


緊接在 **Problem summary** (問題摘要) 之後，**Insight** 區段會提供有關錯誤以及您可以從何處取得有關問題原因的詳細資訊。

![\[CloudWatch Application Insights 的 Problem insight (問題洞見) 中包含有關錯誤原因的其他資訊。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-app-availability-2.png)


下列範例顯示問題儀表板，您可以在其中檢視日誌和指標，這些日誌和指標會分組以協助您隔離錯誤的原因。`sap_enqueue_server_replication_state` 指標會追蹤一段時間內的值。您可以使用歷史追蹤來關聯指標何時啟動錯誤狀態或超出警示閾值。

![\[問題儀表板上的排入佇列伺服器複寫狀態指標，其中包含發生錯誤時的其他相關資訊。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-app-availability-3.png)


在下列範例中，`ha_cluster_pacemaker_fail_count` 指標會顯示高可用性 Pacemaker 叢集發生資源故障。失敗計數大於或等於 1 的特定 Pacemaker 資源會在元件儀表板中識別出來。

![\[失敗計數大於或等於 1 的 Pacemaker 資源 CloudWatch Application Insights 應用程式可用性指標。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-app-availability-4.png)


下列範例顯示 `sap_alerts_Shortdumps` 指標，表示偵測到問題時，SAP 應用程式效能已降低。

![\[CloudWatch Application Insights 的應用程式可用性提醒 Shortdumps 指標。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-app-availability-5.png)


#### 日誌
<a name="ai-sap-netweaver-logs"></a>

日誌項目有助於更好地了解偵測到問題時發生在 SAP NetWeaver 層的問題。問題儀表板中的日誌群組小工具會顯示問題的具體時間。

![\[CloudWatch Application Insights 的日誌項目顯示問題發生的確切時間。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-app-availability-7.png)


若要查看有關日誌的詳細資訊，請選取右上角的三個垂直點，然後在 **View in CloudWatch Logs Insights** (在 CloudWatch Logs Insights 中檢視)。

![\[CloudWatch Logs Application Insights 詳細資訊，其中有 CloudWatch Logs Insights 中的檢視。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-app-availability-8.png)


使用下列步驟來取得有關問題儀表板中顯示之指標和警示的詳細資訊。

**取得指標和警示的詳細資訊**

1. 開啟 [CloudWatch 主控台](https://console.aws.amazon.com/cloudwatch)。

1. 在左側導覽窗格中，選取 **Insights** 下的 **Application Insights**。然後，選擇 **List view** (清單檢視) 索引標籤，然後選擇您的應用程式。

1. 選取 **Components** (元件) 索引標籤。然後，選取您要取得其詳細資訊的 SAP NetWeaver 元件。

   下列範例會顯示 **HA Metrics** (HA 指標) 區段，其中包含顯示在問題儀表板中的 `ha_cluster_pacemaker_fail_count` 指標。  
![\[CloudWatch Application Insights 的 HA 指標，顯示 Pacemaker 資源失敗計數。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-app-availability-9.png)

**解決方案**  
Application Insights 會每小時監控偵測到的問題。如果 SAP NetWeaver 日誌檔案中沒有新的相關日誌項目，較舊的日誌項目會被視為已解決。您必須修正與此問題相關的任何錯誤情況。

針對 `sap_alerts_Shortdumps` 警示，您必須使用交易程式碼 `RZ20 → R3Abap → Shortdumps` 導覽至 CCMS 提醒來解決 SAP NetWeaver 系統中的提醒。如需有關 CCMS 提醒的詳細資訊，請參閱 [SAP 網站](https://help.sap.com/docs/SAP_NETWEAVER_701/6f45651d6c4b1014a50f9ef0fc8df39d/408dc4a7c415437a9b91d2ef6caa9d7d.html)。解決 Shortdumps 樹中的所有 CCMS 提醒。SAP NetWeaver 系統中所有提醒都解決之後，CloudWatch 不會再回報處於警示狀態的指標。

所有 CloudWatch 日誌錯誤和警示都解決後，Application Insights 會停止偵測錯誤，並在一小時內自動解決問題。我們建議您解決所有日誌錯誤狀況和警示，以便在問題儀表板上找到最新的問題。在下列範例中，SAP Netweaver 高可用性排入佇列複寫問題已解決。

![\[CloudWatch Application Insights 的問題儀表板顯示 SAP 可用性：狀態為已解決的排入佇列複寫問題。\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/images/appinsights-nw-app-availability-problem-resolved.png)


## 適用於 SAP NetWeaver 的 Application Insights 的疑難排解
<a name="appinsights-tutorial-sap-netweaver-troubleshooting-health-dashboard"></a>

本節提供的步驟可協助您解決 Application Insights 儀表板所傳回的常見錯誤。

### 無法新增超過 60 個監控指標
<a name="ai-unable-add-monitor-metrics"></a>

**傳回錯誤**：`Component cannot have more than 60 monitored metrics.`

**根本原因**：`The current metric limit is 60 monitor metrics per component.`

**解決方案**：移除不需要遵守限制的指標。

### SAP 指標在加入程序之後不會顯示在儀表板上
<a name="sap-metrics-not-on-dashboard"></a>

**根本原因**：元件儀表板使用五分鐘的指標期間來彙總資料點。

**解決方案**：五分鐘後，所有指標都應顯示在儀表板上。

### SAP 指標和警示不會顯示在儀表板上
<a name="sap-metrics-and-alarms-not-on-dashboard"></a>

使用下列步驟來確定為什麼 SAP 指標和警示在加入程序之後不會顯示在儀表板上。

**識別有指標與警示的問題**

1. 開啟 [CloudWatch 主控台](https://console.aws.amazon.com/cloudwatch)。

1. 在左側導覽窗格中，選取 **Insights** 下的 **Application Insights**。然後，選擇 **List view** (清單檢視) 索引標籤，然後選擇您的應用程式。

1. 選擇 **Configuration history** (組態歷史紀錄) 索引標籤。

1. 如果您看到遺失的指標資料點，請檢查與 `prometheus-sap_host_exporter` 相關的錯誤。

1. 如果在上一個步驟中找不到錯誤，[Connect to your Linux instance](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstances.html) (連線到您的 Linux 執行個體)。對於高可用性部署，請連線到主叢集 Amazon EC2 執行個體。

1. 在您的執行個體中，請使用下列命令確認匯出程式是否正在執行。預設連接埠為 `9680`。如果您使用其他連接埠，請使用您正在使用的連接埠取代 `9680`。

   ```
   curl localhost:9680/metrics
   ```

   如果沒有傳回任何資料，則匯出程式無法啟動。

1. 若要尋找接下來兩個步驟`WORKLOAD_SHORT_NAME`中用於 的正確命名慣例，請執行下列命令。
**注意**  
Application Insights 會根據執行中的工作負載，`WORKLOAD_SHORT_NAME`將尾碼 新增至服務名稱。NetWeaver 分散式、標準和高可用性部署的簡短名稱為 `SAP_NWD`、 `SAP_NWS`和 `SAP_NWH`。

   ```
   sudo systemctl | grep exporter
   ```

1. 若要檢查匯出器服務日誌中的錯誤，請執行下列命令：

   ```
   sudo journalctl -e --unit=prometheus-sap_host_exporter_WORKLOAD_SHORT_NAME.service
   ```

1. 若要檢查匯出工具管理員服務日誌中的錯誤，請執行下列命令：

   ```
   sudo journalctl -e --unit=prometheus-sap_host_exporter_manager_WORKLOAD_SHORT_NAME.service
   ```
**注意**  
此服務應該始終啟動並運行。

   如果此命令沒有傳回錯誤，則繼續下一個步驟。

1. 若要手動啟動匯出器，請執行下列命令。然後，檢查匯出程式輸出。

   ```
   sudo /opt/aws/sap_host_exporter/sap_host_exporter
   ```

   您可以在檢查錯誤後結束匯出程式程序。

**根本原因**：此問題有數個可能的原因。常見的原因是匯出程式無法連線到其中一個應用程式伺服器執行個體。

**解決方案**

請使用下列步驟將匯出程式連線至應用程式伺服器執行個體。您需要驗證 SAP 應用程式執行個體是否正在執行，並使用 SAPControl 連線至執行個體。

**將匯出程式連線至應用程式伺服器執行個體**

1. 在您的 Amazon EC2 執行個體中，執行下列命令以驗證 SAP 應用程式是否正在執行。

   ```
   sapcontrol -nr <App_InstNo> -function GetProcessList
   ```

1. 您必須建立有效的 SAPControl 連線。如果 SAPControl 連線無法運作，請在相關 SAP 應用程式執行個體上找出問題的根本原因。

1. 若要在修正 SAPControl 連線問題後手動啟動匯出程式，請執行下列命令：

   ```
   sudo systemctl start prometheus-sap_host_exporter.service
   ```

1. 如果您無法解決 SAPControl 連線問題，請使用下列程序作為暫時修正。

   1. 開啟 [AWS Systems Manager 主控台](https://console.aws.amazon.com/systems-manager)。

   1. 在左側導覽窗格中，選擇 **State Manager**。

   1. 在 **Associations** (關聯) 下，搜尋 SAP NetWeaver 系統的關聯。

      ```
      Association Name: Equal: AWS-ApplicationInsights-SSMSAPHostExporterAssociationForCUSTOMSAPNW<SID>-1
      ```

   1. 選取 **Association ID** (關聯 ID)。

   1. 選擇 **Parameters** (參數) 索引標籤，然後從 **additionalArguments** 中移除應用程式伺服器編號。

   1. 選擇 **Apply association now** (立即套用關聯)。
**注意**  
這是暫時的修正程式。如果對元件的監視組態進行了更新，則會重新新增執行個體。

# 檢視與針對 Amazon CloudWatch Application Insights 偵測到的問題進行故障診斷
<a name="appinsights-troubleshooting"></a>

本節中的主題提供 Application Insights 所顯示之已偵測問題和洞察的詳細資訊。它也會針對您的帳戶或組態中所偵測到的問題，提供建議的解決方案。

**Topics**
+ [CloudWatch 主控台概觀](#appinsights-troubleshooting-overview)
+ [Application Insights 問題摘要頁面](#appinsights-troubleshooting-problem-summary)
+ [CloudWatch 代理程式合併衝突失敗](#cwagent-merge-conflicts)
+ [CloudWatch 代理程式日誌處理中的高 CPU 用量](#cwagent-high-cpu-usage)
+ [未建立警報](#alarms-not-created)
+ [意見回饋](#appinsights-troubleshooting-feedback)
+ [組態錯誤](#appinsights-configuration-errors)

## CloudWatch 主控台概觀
<a name="appinsights-troubleshooting-overview"></a>

影響受監控應用程式的問題概觀，列在 [CloudWatch 主控台](https://console.aws.amazon.com/cloudwatch)概觀頁面的 CloudWatch Application Insights 窗格下。

CloudWatch Application Insights 概觀窗格會顯示下列項目：
+ 偵測到的問題嚴重性：高/中/低
+ 問題的簡短摘要
+ 問題來源
+ 問題開始的時間
+ 問題的解決狀態
+ 受影響的資源群組

若要檢視特定問題的詳細資訊，請在 **Problem Summary** (問題摘要) 下，選取問題描述。詳細資訊儀表板會顯示問題和相關指標異常的洞見以及日誌錯誤的程式碼片段。您可以選取它是否有用，提供對洞察相關的意見回饋。

如果偵測到未設定的新資源，問題摘要描述會將您移至 **Edit configuration** (編輯組態) 精靈，以設定新的資源。您可以選擇詳細資訊儀表板右上角的 **View/edit configuration** (檢視/編輯組態)，檢視或編輯您的資源群組組態。

若要返回概觀，請選擇位在 CloudWatch Application Insights 詳細資訊儀表板標頭旁的 **Back to overview** (返回概觀)。

## Application Insights 問題摘要頁面
<a name="appinsights-troubleshooting-problem-summary"></a>

**Application Insights 問題摘要頁面**  
CloudWatch Application Insights 會在問題摘要頁面上提供以下有關偵測到的問題資訊：
+ 問題的簡短摘要
+ 問題的開始時間和日期
+ 問題嚴重性：高/中/低
+ 偵測到的問題狀態：正在進行/已解決
+ 洞見：對所偵測問題及可能根本原因自動產生的洞見
+ 對洞察的意見回饋：您針對 CloudWatch Application Insights 所產生洞察實用性提供的意見回饋
+ 相關觀察：詳細檢視與跨各種應用程式元件問題有關的相關日誌指標異常和錯誤程式碼片段

## CloudWatch 代理程式合併衝突失敗
<a name="cwagent-merge-conflicts"></a>

CloudWatch Application Insights 會在客戶執行個體上安裝並設定 CloudWatch 代理程式。這包含建立 CloudWatch 代理程式組態檔案，其中包含指標或日誌的組態。如果客戶的執行個體已具有 CloudWatch 代理程式組態檔案，且該檔案具有針對相同指標或日誌定義的不同組態，則可能會發生合併衝突。若要解決合併衝突，請使用下列步驟：

1. 找出您系統上的 CloudWatch 代理程式組態檔。如需檔案位置的詳細資訊，請參閱 [CloudWatch 代理程式檔案和位置](troubleshooting-CloudWatch-Agent.md#CloudWatch-Agent-files-and-locations)。

1. 請從現有的 CloudWatch 代理程式組態檔案中移除您要在 Application Insights 中使用的資源組態。如果您只想要使用 Application Insights 組態，請刪除現有的 CloudWatch 代理程式組態檔案。

## CloudWatch 代理程式日誌處理中的高 CPU 用量
<a name="cwagent-high-cpu-usage"></a>

CloudWatch Application Insights 會在客戶執行個體上安裝並設定 CloudWatch 代理程式。如果 Amazon EC2 執行個體設定了具有大量日誌資料的日誌路徑，則該執行個體可能會在 CloudWatch 代理程式處理日誌時遇到 CPU 用量增加的情況。若要減少 CPU 用量，請移除 [Amazon EC2 執行個體元件組態](component-configuration-examples-ec2.md)中的日誌路徑。

## 未建立警報
<a name="alarms-not-created"></a>

對於某些指標，Application Insights 會根據指標的先前資料點預測警示閾值。若要啟用此預測，必須符合下列條件。
+ **最近的資料點** – 過去 24 小時內至少必須有 100 個資料點。資料點不需要連續，而且可以分散在 24 小時的時間範圍內。
+ **歷史資料** – 從目前日期前 15 天到目前日期前 1 天，必須至少有 100 個資料點跨越時間範圍。資料點不需要連續，而且可以分散在 15 天的時間範圍內。

**注意**  
對於某些指標，Application Insights 會延遲警示的建立，直到符合前述條件為止。在此情況下，您會收到組態歷史記錄事件，說明指標缺少足夠的資料點來建立警示閾值。

## 意見回饋
<a name="appinsights-troubleshooting-feedback"></a>

**意見回饋**

您可以指出針對所偵測問題自動產生的洞見是否有用，提供意見回饋。您對洞見的意見回饋以及您的應用程式診斷 (指標異常和日誌例外狀況)，都會用來提升未來對類似問題的偵測。

## 組態錯誤
<a name="appinsights-configuration-errors"></a>

CloudWatch Application Insights 會使用您的組態來建立元件監控遙測。當 Application Insights 偵測到您的帳戶或您的組態發生問題時，應用程式摘要的 **Remarks** (備註) 欄位中會提供如何解決應用程式組態問題的資訊。

下表顯示特定備註的建議解決方案。


| 備註 | 建議的解決方案 | 其他備註  | 
| --- | --- | --- | 
|  已達到 CloudFormation 的限額。  |  Application Insights 會針對每個應用程式建立一個 CloudFormation 堆疊，以管理所有應用程式元件的 CloudWatch 代理安裝和組態。根據預設，每個 AWS 帳戶可以有 2000 個堆疊。請參閱 [CloudFormation 限制](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cloudformation-limits.html)。若要解決這個問題，請提高 CloudFormation 堆疊限制。  | N/A | 
|  下列執行個體上沒有 SSM 執行個體角色。  |  若希望 Application Insights 能夠在應用程式執行個體上安裝與設定 CloudWatch 代理，AmazonSSMManagedInstanceCore 和 CloudWatchAgentServerPolicy 政策必須連接到執行個體角色。  |  Application Insights 會呼叫 SSM [DescribeInstanceInformation API](https://docs.aws.amazon.com/systems-manager/latest/APIReference/API_DescribeInstanceInformation.html)，以 SSM 許可取得執行個體清單。角色連接到執行個體後，SSM 需要一點時間將執行個體納入 DescribeInstanceInformation 結果。在 SSM 將執行個體納入結果前，應用程式會一直顯示 NO\$1SSM\$1INSTANCE\$1ROLE 錯誤。  | 
|  您可能需要設定新的元件。  |  Application Insights 偵測到應用程式資源群組有新元件。若要解決這個問題，請相應設定新的元件。  | N/A | 

# Amazon CloudWatch Application Insights 支援的日誌和指標
<a name="appinsights-logs-and-metrics"></a>

以下清單顯示 Amazon CloudWatch Application Insights 支援的日誌和指標。

**CloudWatch Application Insights 支援以下日誌：**
+ Microsoft Internet Information Services (IIS) 日誌
+ EC2 的 SQL Server 錯誤日誌
+ 自訂的 .NET 應用程式日誌，例如 Log4Net
+ Windows 事件日誌，包括 Windows 日誌 (系統、應用程式和安全性) 及應用程式和服務日誌
+ 的 Amazon CloudWatch Logs AWS Lambda
+ EC2 上 RDS MySQL、Aurora MySQL 和 MySQL 的錯誤日誌和慢速日誌
+ EC2 上的 PostgreSQL RDS 和 PostgreSQL 的 Postgresql 日誌
+ 的 Amazon CloudWatch Logs AWS Step Functions
+ API Gateway REST API 階段的執行日誌和存取日誌 (JSON、CSV 和 XML，而非 CLF)
+ Prometheus JMX Exporter 日誌 (EMF)
+ Amazon RDS 上的 Oracle 和 Amazon EC2 上的 Oracle 的提醒日誌與接聽程式
+ 使用 [`awslogs` 日誌驅動程式](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_awslogs.html)可將容器日誌從 Amazon ECS 容器路由至 CloudWatch。
+ 使用 [FireLens 容器日誌路由器](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_firelens.html)可將容器日誌從 Amazon ECS 容器路由至 CloudWatch。
+ 搭配使用 [Fluent Bit 或 Fluentd 日誌處理器](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/Container-Insights-EKS-logs.html)與 Container Insights，將容器日誌從 Amazon EC2 上執行的 Amazon EKS 或 Kubernetes 路由至 CloudWatch。
+ SAP HANA 追蹤和錯誤日誌
+ HA Pacemaker 日誌
+ SAP ASE 伺服器日誌
+ SAP ASE 備份伺服器日誌
+ SAP ASE 複寫伺服器日誌
+ SAP ASE RMA 代理程式日誌
+ SAP ASE 錯誤管理員日誌
+ SAP NetWeaver 開發追蹤日誌
+ 使用 [CloudWatch 代理程式的 proctstat 外掛程式](CloudWatch-Agent-procstat-process-metrics.md)的 Windows 程式的程式指標
+ 託管區域的公用 DNS 查詢日誌
+ Amazon Route 53 Resolver DNS 查詢日誌

**CloudWatch Application Insights 支援以下日誌類別：**
+ **標準** –Amazon CloudWatch Application Insights 要求使用 [CloudWatch Logs 標準日誌類別](https://docs.aws.amazon.com/AmazonCloudWatch/latest/logs/CloudWatch_Logs_Log_Classes.html)設定日誌群組，才能啟用監控功能。

**Contents**
+ [Amazon Elastic Compute Cloud (EC2)](appinsights-metrics-ec2.md)
  + [CloudWatch 內建指標](appinsights-metrics-ec2.md#appinsights-metrics-ec2-built-in)
  + [CloudWatch 代理指標 (Windows 伺服器)](appinsights-metrics-ec2.md#appinsights-metrics-ec2-windows)
  + [CloudWatch 代理程式指標 (Windows Server)](appinsights-metrics-ec2.md#appinsights-metrics-procstat-ec2-windows)
  + [CloudWatch 代理程式指標 (Linux 伺服器)](appinsights-metrics-ec2.md#appinsights-metrics-ec2-linux)
+ [Elastic Block Store (EBS)](appinsights-metrics-ebs.md)
+ [Amazon Elastic File System (Amazon EFS)](appinsights-metrics-efs.md)
+ [Elastic Load Balancer (ELB)](appinsights-metrics-elb.md)
+ [應用程式 ELB](appinsights-metrics-app-elb.md)
+ [Amazon EC2 Auto Scaling 群組](appinsights-metrics-as.md)
+ [Amazon Simple Queue Server (SQS)](appinsights-metrics-sqs.md)
+ [Amazon Relational Database Service (RDS)](appinsights-metrics-rds.md)
  + [RDS 資料庫執行個體](appinsights-metrics-rds.md#appinsights-metrics-rds-instances)
  + [RDS 資料庫叢集](appinsights-metrics-rds.md#appinsights-metrics-rds-clusters)
+ [AWS Lambda 函數](appinsights-metrics-lambda.md)
+ [Amazon DynamoDB 資料表](appinsights-metrics-dyanamodb.md)
+ [Amazon S3 儲存貯體](appinsights-metrics-s3.md)
+ [AWS Step Functions](appinsights-metrics-step-functions.md)
  + [Execution-level](appinsights-metrics-step-functions.md#appinsights-metrics-step-functions-execution)
  + [活動](appinsights-metrics-step-functions.md#appinsights-metrics-step-functions-activity)
  + [Lambda 函式](appinsights-metrics-step-functions.md#appinsights-metrics-step-functions-lambda)
  + [服務整合](appinsights-metrics-step-functions.md#appinsights-metrics-step-functions-service-integration)
  + [Step Functions API](appinsights-metrics-step-functions.md#appinsights-metrics-step-functions-api)
+ [API Gateway REST API 階段](appinsights-metrics-api-gateway.md)
+ [SAP HANA](appinsights-metrics-sap-hana.md)
+ [SAP ASE](appinsights-metrics-sap-ase.md)
+ [在 Amazon EC2 上的 SAP ASE 高可用性](appinsights-metrics-sap-ase-ha.md)
+ [SAP NetWeaver](appinsights-metrics-sap-netweaver.md)
+ [HA 叢集](appinsights-metrics-ha-cluster.md)
+ [Java](appinsights-metrics-java.md)
+ [Amazon Elastic Container Service (Amazon ECS)](appinsights-metrics-ecs.md)
  + [CloudWatch 內建指標](appinsights-metrics-ecs.md#appinsights-metrics-ecs-built-in-metrics)
  + [Container Insights 指標](appinsights-metrics-ecs.md#appinsights-metrics-ecs-container-insights-metrics)
  + [Container Insights Prometheus 指標](appinsights-metrics-ecs.md#appinsights-metrics-ecs-container-insights-prometheus)
+ [上的 Kubernetes AWS](appinsights-metrics-kubernetes.md)
  + [Container Insights 指標](appinsights-metrics-kubernetes.md#appinsights-metrics-kubernetes-container-insights-metrics)
  + [Container Insights Prometheus 指標](appinsights-metrics-kubernetes.md#appinsights-metrics-kubernetes-container-insights-prometheus)
+ [Amazon FSx](appinsights-metrics-fsx.md)
+ [Amazon VPC](appinsights-metrics-vpc.md)
+ [Amazon VPC NAT 閘道](appinsights-metrics-nat-gateways.md)
+ [Amazon Route 53 運作狀態檢查](appinsights-metrics-health-check.md)
+ [Amazon Route 53 託管區域](appinsights-metrics-hosted-zone.md)
+ [Amazon Route 53 Resolver endpoint](appinsights-metrics-resolver-endpoint.md)
+ [AWS Network Firewall 規則群組](appinsights-metrics-firewall-rule-group.md)
+ [AWS Network Firewall 規則群組關聯](appinsights-metrics-firewall-rule-group-assoc.md)
+ [具有指標資料點要求的指標](appinsights-metrics-datapoint-requirements.md)
  + [AWS/ApplicationELB](appinsights-metrics-datapoint-requirements.md#appinsights-metrics-datapoint-requirements-app-elb)
  + [AWS/AutoScaling](appinsights-metrics-datapoint-requirements.md#appinsights-metrics-datapoint-requirements-autoscaling)
  + [AWS/EC2](appinsights-metrics-datapoint-requirements.md#appinsights-metrics-datapoint-requirements-ec2)
  + [Elastic Block Store (EBS)](appinsights-metrics-datapoint-requirements.md#appinsights-metrics-datapoint-requirements-ebs)
  + [AWS/ELB](appinsights-metrics-datapoint-requirements.md#appinsights-metrics-datapoint-requirements-elb)
  + [AWS/RDS](appinsights-metrics-datapoint-requirements.md#appinsights-metrics-datapoint-requirements-rds)
  + [AWS/Lambda](appinsights-metrics-datapoint-requirements.md#appinsights-metrics-datapoint-requirements-lambda)
  + [AWS/SQS](appinsights-metrics-datapoint-requirements.md#appinsights-metrics-datapoint-requirements-sqs)
  + [AWS/CWAgent](appinsights-metrics-datapoint-requirements.md#appinsights-metrics-datapoint-requirements-cwagent)
  + [AWS/DynamoDB](appinsights-metrics-datapoint-requirements.md#appinsights-metrics-datapoint-requirements-dynamo)
  + [AWS/S3](appinsights-metrics-datapoint-requirements.md#appinsights-metrics-datapoint-requirements-s3)
  + [AWS/狀態](appinsights-metrics-datapoint-requirements.md#appinsights-metrics-datapoint-requirements-states)
  + [AWS/ApiGateway](appinsights-metrics-datapoint-requirements.md#appinsights-metrics-datapoint-requirements-api-gateway)
  + [AWS/SNS](appinsights-metrics-datapoint-requirements.md#appinsights-metrics-datapoint-requirements-sns)
+ [建議的指標](application-insights-recommended-metrics.md)
+ [效能計數器指標](application-insights-performance-counter.md)

# Amazon Elastic Compute Cloud (EC2)
<a name="appinsights-metrics-ec2"></a>

CloudWatch Application Insights 支援以下指標：

**Topics**
+ [CloudWatch 內建指標](#appinsights-metrics-ec2-built-in)
+ [CloudWatch 代理指標 (Windows 伺服器)](#appinsights-metrics-ec2-windows)
+ [CloudWatch 代理程式指標 (Windows Server)](#appinsights-metrics-procstat-ec2-windows)
+ [CloudWatch 代理程式指標 (Linux 伺服器)](#appinsights-metrics-ec2-linux)

## CloudWatch 內建指標
<a name="appinsights-metrics-ec2-built-in"></a>

CPUCreditBalance

CPUCreditUsage

CPUSurplusCreditBalance

CPUSurplusCreditsCharged

CPUUtilization

DiskReadBytes

DiskReadOps

DiskWriteBytes

DiskWriteOps

EBSByteBalance%

EBSIOBalance%

EBSReadBytes

EBSReadOps

EBSWriteBytes

EBSWriteOps

NetworkIn

NetworkOut

NetworkPacketsIn

NetworkPacketsOut

StatusCheckFailed

StatusCheckFailed\$1Instance (StatusCheckFailed\$1Instance)

StatusCheckFailed\$1System (StatusCheckFailed\$1System)

## CloudWatch 代理指標 (Windows 伺服器)
<a name="appinsights-metrics-ec2-windows"></a>

擲出的 .NET CLR 異常數

每秒擲出的 .NET CLR 異常數

每秒篩選的 .NET CLR 異常數

每秒最終的 .NET CLR 異常數

每秒擲出以捕捉深度的 .NET CLR 異常

CCW 的 .NET CLR Interop 數

Stub 的 .NET CLR Interop 數

每秒 TLB 匯出的 .NET CLR Interop 數

每秒 TLB 匯入的 .NET CLR Interop 數

封送處理的 .NET CLR Interop 數

Jit 的 .NET CLR Jit 時間百分比

.NET CLR Jit 標準 Jit 失敗

.NET CLR 正在載入 - 正在載入時間百分比

.NET CLR 載入失敗的載入速率

.NET CLR LocksAndThreads 爭用速率/秒

.NET CLR LocksAndThreads 佇列長度/秒

.NET CLR 記憶體數總遞交的位元組

.NET CLR 記憶體在 GC 中時間佔比

.NET CLR Networking 4.0.0.0 HttpWebRequest 平均佇列時間

.NET CLR Networking 4.0.0.0 HttpWebRequests 中止/秒

.NET CLR Networking 4.0.0.0 HttpWebRequests 失敗/秒

.NET CLR Networking 4.0.0.0 HttpWebRequests 佇列/秒

APP\$1POL\$1WAS 總工作者處理序 Ping 失敗

ASP.NET 應用程式重新啟動

ASP.NET 應用程式 % 受管處理器時間 (估計)

ASP.NET 應用程式錯誤總計/秒

ASP.NET 應用程式執行期間未處理錯誤/秒

應用程式佇列中的 ASP.NET 應用程式請求

ASP.NET 應用程式請求/秒

ASP.NET 請求等待時間

ASP.NET 請求已排入佇列

HTTP 服務要求佇列 CurrentQueueSize

LogicalDisk % 可用空間

記憶體 % 使用中的認可位元組

記憶體可用的 MB 數

記憶體分頁/秒

網路介面位元組總數/秒

分頁檔用量 %

PhysicalDisk % 磁碟時間

PhysicalDisk Avg. 磁碟佇列長度

PhysicalDisk Avg. Disk sec/Read

PhysicalDisk Avg. Disk sec/Write

PhysicalDisk 磁碟讀取位元組/秒

PhysicalDisk Disk Reads/sec

PhysicalDisk 磁碟寫入位元組/秒

PhysicalDisk Disk Writes/sec

處理器 % 閒置時間

處理器 % 中斷時間

處理器 % 處理器時間

處理器 % 使用者時間

SQLServer:Access Methods Forwarded Records/sec

SQLServer:Access Methods Full Scans/sec

SQLServer:Access Methods Page Splits/sec

SQLServer:Buffer Manager 緩衝快取命中率

SQLServer:Buffer Manager 頁面的預期壽命

SQLServer:General Statistics Processes blocked

SQLServer：一般統計資料使用者連線

SQLServer：閂鎖平均閂鎖等待時間 (毫秒)

SQLServer：鎖定平均等待時間 (毫秒)

SQLServer：鎖定鎖定逾時/秒

SQLServer：鎖定鎖定等待/秒

SQLServer：鎖定死鎖數目/秒

SQLServer：記憶體管理員記憶體授權待定

SQLServer:SQL Statistics 每秒批次要求數

SQLServer:SQL Statistics SQL Compilations/sec

SQLServer:SQL Statistics SQL Re-Compilations/sec

系統處理器佇列長度

已建立 TCPv4 連線

已建立 TCPv6 連線

W3SVC\$1W3WP 檔案饋取排清

W3SVC\$1W3WP 檔案快取遺漏

W3SVC\$1W3WP 請求/秒

W3SVC\$1W3WP URI 快取排清

W3SVC\$1W3WP URI 快取遺漏

接收的 Web 服務位元組/秒

傳送的 Web 服務位元組/秒

Web 服務連線嘗試/秒

Web 服務目前連線數目

Web 服務收到請求/秒

Web 服務 POST 請求/秒

接收的位元組/秒

正常訊息佇列長度/秒

紧急訊息佇列長度/秒

重新連線計數

未確認的訊息佇列長度/秒

未處理的訊息

傳送的訊息/秒

資料庫更新訊息/秒

更新訊息/秒

排清數/秒

儲存的加密檢查點/秒

還原的加密檢查點/秒

還原的登錄檢查點/秒

儲存的登錄檢查點/秒

叢集 API 呼叫/秒

資源 API 呼叫/秒

叢集處理/秒

資源處理/秒

## CloudWatch 代理程式指標 (Windows Server)
<a name="appinsights-metrics-procstat-ec2-windows"></a>

系統會使用 [CloudWatch 代理程式的 procstat 外掛程式](CloudWatch-Agent-procstat-process-metrics.md)收集程式指標。只有執行 Windows 工作負載的 Amazon EC2 執行個體才支援程式指標。

procstat cpu\$1time\$1system

procstat cpu\$1time\$1user

procstat cpu\$1usage

procstat memory\$1rss

procstat memory\$1vms

procstat read\$1bytes

procstat write\$1bytes

.procstat read\$1count

procstat write\$1count

## CloudWatch 代理程式指標 (Linux 伺服器)
<a name="appinsights-metrics-ec2-linux"></a>

cpu\$1time\$1active

cpu\$1time\$1guest

cpu\$1time\$1guest\$1nice

cpu\$1time\$1idle

cpu\$1time\$1iowait

cpu\$1time\$1irq

cpu\$1time\$1nice

cpu\$1time\$1softirq

cpu\$1time\$1steal

cpu\$1time\$1system

cpu\$1time\$1user

cpu\$1usage\$1active

cpu\$1usage\$1guest

cpu\$1usage\$1guest\$1nice

cpu\$1usage\$1idle

cpu\$1usage\$1iowait

cpu\$1usage\$1irq

cpu\$1usage\$1nice

cpu\$1usage\$1softirq

cpu\$1usage\$1steal

cpu\$1usage\$1system

cpu\$1usage\$1user

disk\$1free

disk\$1inodes\$1free

disk\$1inodes\$1used

disk\$1used

disk\$1used\$1percent

diskio\$1io\$1time

diskio\$1iops\$1in\$1progress

diskio\$1read\$1bytes

diskio\$1read\$1time

diskio\$1reads

diskio\$1write\$1bytes

diskio\$1write\$1time

diskio\$1writes

mem\$1active

mem\$1available

mem\$1available\$1percent

mem\$1buffered

mem\$1cached

mem\$1free

mem\$1inactive

mem\$1used

mem\$1used\$1percent

net\$1bytes\$1recv

net\$1bytes\$1sent

net\$1drop\$1in

net\$1drop\$1out

net\$1err\$1in

net\$1err\$1out

net\$1packets\$1recv

net\$1packets\$1sent

netstat\$1tcp\$1close

netstat\$1tcp\$1close\$1wait

netstat\$1tcp\$1closing

netstat\$1tcp\$1established

netstat\$1tcp\$1fin\$1wait1

netstat\$1tcp\$1fin\$1wait2

netstat\$1tcp\$1last\$1ack

netstat\$1tcp\$1listen

netstat\$1tcp\$1none

netstat\$1tcp\$1syn\$1recv

netstat\$1tcp\$1syn\$1sent

netstat\$1tcp\$1time\$1wait

netstat\$1udp\$1socket

processes\$1blocked

processes\$1dead

processes\$1idle

processes\$1paging

processes\$1running

processes\$1sleeping

processes\$1stopped

processes\$1total

processes\$1total\$1threads

processes\$1wait

processes\$1zombies

swap\$1free

swap\$1used

swap\$1used\$1percent

# Elastic Block Store (EBS)
<a name="appinsights-metrics-ebs"></a>

CloudWatch Application Insights 支援以下指標：

VolumeReadBytes

VolumeWriteBytes

VolumeReadOps

VolumeWriteOps

VolumeTotalReadTime 

VolumeTotalWriteTime 

VolumeIdleTime

VolumeQueueLength

VolumeThroughputPercentage

VolumeConsumedReadWriteOps

BurstBalance

# Amazon Elastic File System (Amazon EFS)
<a name="appinsights-metrics-efs"></a>

CloudWatch Application Insights 支援以下指標：

urstCreditBalance

PercentIOLimit

PermittedThroughput

MeteredIOBytes

TotalIOBytes

DataWriteIOBytes

DataReadIOBytes

MetadataIOBytes

ClientConnections

TimeSinceLastSync

StorageBytes

輸送量

PercentageOfPermittedThroughputUtilization

ThroughputIOPS

 PercentThroughputDataReadIOByte

PercentThroughputDataWriteIOBytes

PercentageOfIOPSDataReadIOBytes

PercentageOfIOPSDataWriteIOBytes

AverageDataReadIOBytesSize

AverageDataWriteIOBytesSize

# Elastic Load Balancer (ELB)
<a name="appinsights-metrics-elb"></a>

CloudWatch Application Insights 支援以下指標：

EstimatedALBActiveConnectionCount

EstimatedALBConsumedLCUs

EstimatedALBNewConnectionCount

EstimatedProcessedBytes

HTTPCode\$1Backend\$14XX

HTTPCode\$1Backend\$15XX

HealthyHostCount

RequestCount

UnHealthyHostCount

# 應用程式 ELB
<a name="appinsights-metrics-app-elb"></a>

CloudWatch Application Insights 支援以下指標：

EstimatedALBActiveConnectionCount

EstimatedALBConsumedLCUs

EstimatedALBNewConnectionCount

EstimatedProcessedBytes

HTTPCode\$1Backend\$14XX

HTTPCode\$1Backend\$15XX

HealthyHostCount

延遲

RequestCount

SurgeQueueLength

UnHealthyHostCount

# Amazon EC2 Auto Scaling 群組
<a name="appinsights-metrics-as"></a>

CloudWatch Application Insights 支援以下指標：

CPUCreditBalance

CPUCreditUsage

CPUSurplusCreditBalance

CPUSurplusCreditsCharged

CPUUtilization

DiskReadBytes

DiskReadOps

DiskWriteBytes

DiskWriteOps

EBSByteBalance%

EBSIOBalance%

EBSReadBytes

EBSReadOps

EBSWriteBytes

EBSWriteOps

NetworkIn

NetworkOut

NetworkPacketsIn

NetworkPacketsOut

StatusCheckFailed

StatusCheckFailed\$1Instance (StatusCheckFailed\$1Instance)

StatusCheckFailed\$1System (StatusCheckFailed\$1System)

# Amazon Simple Queue Server (SQS)
<a name="appinsights-metrics-sqs"></a>

CloudWatch Application Insights 支援以下指標：

ApproximateAgeOfOldestMessage

ApproximateNumberOfMessagesDelayed

ApproximateNumberOfMessagesNotVisible

ApproximateNumberOfMessagesVisible

NumberOfEmptyReceives

NumberOfMessagesDeleted

NumberOfMessagesReceived

NumberOfMessagesSent

# Amazon Relational Database Service (RDS)
<a name="appinsights-metrics-rds"></a>

CloudWatch Application Insights 支援以下指標：

**Topics**
+ [RDS 資料庫執行個體](#appinsights-metrics-rds-instances)
+ [RDS 資料庫叢集](#appinsights-metrics-rds-clusters)

## RDS 資料庫執行個體
<a name="appinsights-metrics-rds-instances"></a>

BurstBalance

CPUCreditBalance

CPUUtilization

DatabaseConnections

DiskQueueDepth

FailedSQLServerAgentJobsCount

FreeStorageSpace

FreeableMemory

NetworkReceiveThroughput

NetworkTransmitThroughput

ReadIOPS

ReadLatency

ReadThroughput

WriteIOPS

WriteLatency

WriteThroughput

## RDS 資料庫叢集
<a name="appinsights-metrics-rds-clusters"></a>

ActiveTransactions

AuroraBinlogReplicaLag

AuroraReplicaLag

BackupRetentionPeriodStorageUsed

BinLogDiskUsage

BlockedTransactions

BufferCacheHitRatio

CPUUtilization

CommitLatency

CommitThroughput

DDLLatency

DDLThroughput

DMLLatency

DMLThroughput

DatabaseConnections

鎖死

DeleteLatency

DeleteThroughput

EngineUptime

FreeLocalStorage

FreeableMemory

InsertLatency

InsertThroughput

LoginFailures

NetworkReceiveThroughput

NetworkThroughput

NetworkTransmitThroughput

查詢

ResultSetCacheHitRatio

SelectLatency

SelectThroughput

SnapshotStorageUsed

TotalBackupStorageBilled

UpdateLatency

UpdateThroughput

VolumeBytesUsed

VolumeReadIOPs

VolumeWriteIOPs

# AWS Lambda 函數
<a name="appinsights-metrics-lambda"></a>

CloudWatch Application Insights 支援以下指標：

錯誤

DeadLetterErrors

持續時間

限流

IteratorAge

ProvisionedConcurrencySpilloverInvocations

# Amazon DynamoDB 資料表
<a name="appinsights-metrics-dyanamodb"></a>

CloudWatch Application Insights 支援以下指標：

SystemErrors

UserErrors

ConsumedReadCapacityUnits

ConsumedWriteCapacityUnits

ReadThrottleEvents

WriteThrottleEvents

TimeToLiveDeletedItemCount

ConditionalCheckFailedRequests

TransactionConflict

ReturnedRecordsCount

PendingReplicationCount

ReplicationLatency

# Amazon S3 儲存貯體
<a name="appinsights-metrics-s3"></a>

CloudWatch Application Insights 支援以下指標：

ReplicationLatency

BytesPendingReplication

OperationsPendingReplication

4xxErrors

5xxErrors

AllRequests

GetRequests

PutRequests

DeleteRequests

HeadRequests

PostRequests

SelectRequests

ListRequests

SelectScannedBytes

SelectReturnedBytes

FirstByteLatency

TotalRequestLatency

BytesDownloaded

BytesUploaded

# AWS Step Functions
<a name="appinsights-metrics-step-functions"></a>

CloudWatch Application Insights 支援以下指標：

**Topics**
+ [Execution-level](#appinsights-metrics-step-functions-execution)
+ [活動](#appinsights-metrics-step-functions-activity)
+ [Lambda 函式](#appinsights-metrics-step-functions-lambda)
+ [服務整合](#appinsights-metrics-step-functions-service-integration)
+ [Step Functions API](#appinsights-metrics-step-functions-api)

## Execution-level
<a name="appinsights-metrics-step-functions-execution"></a>

ExecutionTime

ExecutionThrottled

ExecutionsFailed

ExecutionsTimedOut

ExecutionsAborted

ExecutionsSucceeded

ExecutionsStarted

## 活動
<a name="appinsights-metrics-step-functions-activity"></a>

ActivityRunTime

ActivityScheduleTime

ActivityTime

ActivitiesFailed

ActivitiesHeartbeatTimedOut

ActivitiesTimedOut

ActivitiesScheduled

ActivitiesSucceeded

ActivitiesStarted

## Lambda 函式
<a name="appinsights-metrics-step-functions-lambda"></a>

LambdaFunctionRunTime

LambdaFunctionScheduleTime

LambdaFunctionTime

LambdaFunctionsFailed

LambdaFunctionsTimedOut

LambdaFunctionsScheduled

LambdaFunctionsSucceeded

LambdaFunctionsStarted

## 服務整合
<a name="appinsights-metrics-step-functions-service-integration"></a>

ServiceIntegrationRunTime

ServiceIntegrationScheduleTime

ServiceIntegrationTime

ServiceIntegrationsFailed

ServiceIntegrationsTimedOut

ServiceIntegrationsScheduled

ServiceIntegrationsSucceeded

ServiceIntegrationsStarted

## Step Functions API
<a name="appinsights-metrics-step-functions-api"></a>

ThrottledEvents

ProvisionedBucketSize

ProvisionedRefillRate

ConsumedCapacity

# API Gateway REST API 階段
<a name="appinsights-metrics-api-gateway"></a>

CloudWatch Application Insights 支援以下指標：

4XXError

5XXError

IntegrationLatency

延遲

CacheHitCount

CacheMissCount

# SAP HANA
<a name="appinsights-metrics-sap-hana"></a>

**注意**  
CloudWatch Application Insights 僅支援單一 SID HANA 環境。如果連接了多個 HANA SID，則僅為偵測到的第一個 SID 設定監控。

CloudWatch Application Insights 支援以下指標：

hanadb\$1every\$1service\$1started\$1status

hanadb\$1daemon\$1service\$1started\$1status

hanadb\$1preprocessor\$1service\$1started\$1status

hanadb\$1webdispatcher\$1service\$1started\$1status

hanadb\$1compileserver\$1service\$1started\$1status

hanadb\$1nameserver\$1service\$1started\$1status

hanadb\$1server\$1startup\$1time\$1variations\$1seconds

hanadb\$1level\$15\$1alerts\$1count

hanadb\$1level\$14\$1alerts\$1count

hanadb\$1out\$1of\$1memory\$1events\$1count

hanadb\$1max\$1trigger\$1read\$1ratio\$1percent

hanadb\$1max\$1trigger\$1write\$1ratio\$1percent

hanadb\$1log\$1switch\$1wait\$1ratio\$1percent

hanadb\$1log\$1switch\$1race\$1ratio\$1percent

hanadb\$1time\$1since\$1last\$1savepoint\$1seconds

hanadb\$1disk\$1usage\$1highlevel\$1percent

hanadb\$1max\$1converter\$1page\$1number\$1count

hanadb\$1long\$1running\$1savepoints\$1count

hanadb\$1failed\$1io\$1reads\$1count

hanadb\$1failed\$1io\$1writes\$1count

hanadb\$1disk\$1data\$1unused\$1percent

hanadb\$1current\$1allocation\$1limit\$1used\$1percent

hanadb\$1table\$1allocation\$1limit\$1used\$1percent

hanadb\$1host\$1total\$1physical\$1memory\$1mb

hanadb\$1host\$1physical\$1memory\$1used\$1mb

hanadb\$1host\$1physical\$1memory\$1free\$1mb

hanadb\$1swap\$1memory\$1free\$1mb

hanadb\$1swap\$1memory\$1used\$1mb

hanadb\$1host\$1allocation\$1limit\$1mb

hanadb\$1host\$1total\$1memory\$1used\$1mb

 hanadb\$1host\$1total\$1peak\$1memory\$1used\$1mb

hanadb\$1host\$1total\$1allocation\$1limit\$1mb

hanadb\$1host\$1code\$1size\$1mb

hanadb\$1host\$1shared\$1memory\$1allocation\$1mb

hanadb\$1cpu\$1usage\$1percent

hanadb\$1cpu\$1user\$1percent

hanadb\$1cpu\$1system\$1percent

hanadb\$1cpu\$1waitio\$1percent

hanadb\$1cpu\$1busy\$1percent

hanadb\$1cpu\$1idle\$1percent

hanadb\$1long\$1delta\$1merge\$1count

hanadb\$1unsuccessful\$1delta\$1merge\$1count

hanadb\$1successful\$1delta\$1merge\$1count

hanadb\$1row\$1store\$1allocated\$1size\$1mb

hanadb\$1row\$1store\$1free\$1size\$1mb

hanadb\$1row\$1store\$1used\$1size\$1mb

hanadb\$1temporary\$1tables\$1count

hanadb\$1large\$1non\$1compressed\$1tables\$1count

hanadb\$1total\$1non\$1compressed\$1tables\$1count

hanadb\$1longest\$1running\$1job\$1seconds

hanadb\$1average\$1commit\$1time\$1milliseconds

hanadb\$1suspended\$1sql\$1statements\$1count

hanadb\$1plan\$1cache\$1hit\$1ratio\$1percent

hanadb\$1plan\$1cache\$1lookup\$1count

hanadb\$1plan\$1cache\$1hit\$1count

hanadb\$1plan\$1cache\$1total\$1execution\$1microseconds

hanadb\$1plan\$1cache\$1cursor\$1duration\$1microseconds

hanadb\$1plan\$1cache\$1preparation\$1microseconds

hanadb\$1plan\$1cache\$1evicted\$1count

hanadb\$1plan\$1cache\$1evicted\$1microseconds

hanadb\$1plan\$1cache\$1evicted\$1preparation\$1count

hanadb\$1plan\$1cache\$1evicted\$1execution\$1count

hanadb\$1plan\$1cache\$1evicted\$1preparation\$1microseconds

hanadb\$1plan\$1cache\$1evicted\$1cursor\$1duration\$1microseconds

hanadb\$1plan\$1cache\$1evicted\$1total\$1execution\$1microseconds

hanadb\$1plan\$1cache\$1evicted\$1plan\$1size\$1mb

hanadb\$1plan\$1cache\$1count

hanadb\$1plan\$1cache\$1preparation\$1count

hanadb\$1plan\$1cache\$1execution\$1count

hanadb\$1network\$1collision\$1rate

hanadb\$1network\$1receive\$1rate

hanadb\$1network\$1transmit\$1rate

hanadb\$1network\$1packet\$1receive\$1rate

hanadb\$1network\$1packet\$1transmit\$1rate

hanadb\$1network\$1transmit\$1error\$1rate

hanadb\$1network\$1receive\$1error\$1rate

hanadb\$1time\$1until\$1license\$1expires\$1days

hanadb\$1is\$1license\$1valid\$1status

hanadb\$1local\$1running\$1connections\$1count

hanadb\$1local\$1idle\$1connections\$1count

hanadb\$1remote\$1running\$1connections\$1count

hanadb\$1remote\$1idle\$1connections\$1count

hanadb\$1last\$1full\$1data\$1backup\$1age\$1days

hanadb\$1last\$1data\$1backup\$1age\$1days

hanadb\$1last\$1log\$1backup\$1age\$1hours

hanadb\$1failed\$1data\$1backup\$1past\$17\$1days\$1count

hanadb\$1failed\$1log\$1backup\$1past\$17\$1days\$1count

hanadb\$1oldest\$1backup\$1in\$1catalog\$1age\$1days

hanadb\$1backup\$1catalog\$1size\$1mb

hanadb\$1hsr\$1replication\$1status

hanadb\$1hsr\$1log\$1shipping\$1delay\$1seconds

hanadb\$1hsr\$1secondary\$1failover\$1count

hanadb\$1hsr\$1secondary\$1reconnect\$1count

hanadb\$1hsr\$1async\$1buffer\$1used\$1mb

hanadb\$1hsr\$1secondary\$1active\$1status

hanadb\$1handle\$1count

hanadb\$1ping\$1time\$1milliseconds

hanadb\$1connection\$1count

hanadb\$1internal\$1connection\$1count

hanadb\$1external\$1connection\$1count

hanadb\$1idle\$1connection\$1count

hanadb\$1transaction\$1count

hanadb\$1internal\$1transaction\$1count

hanadb\$1external\$1transaction\$1count

hanadb\$1user\$1transaction\$1count

hanadb\$1blocked\$1transaction\$1count

hanadb\$1statement\$1count

hanadb\$1active\$1commit\$1id\$1range\$1count

hanadb\$1mvcc\$1version\$1count

hanadb\$1pending\$1session\$1count

hanadb\$1record\$1lock\$1count

hanadb\$1read\$1count

hanadb\$1write\$1count

hanadb\$1merge\$1count

hanadb\$1unload\$1count

hanadb\$1active\$1thread\$1count

hanadb\$1waiting\$1thread\$1count

hanadb\$1total\$1thread\$1count

hanadb\$1active\$1sql\$1executor\$1count

hanadb\$1waiting\$1sql\$1executor\$1count

hanadb\$1total\$1sql\$1executor\$1count

hanadb\$1data\$1write\$1size\$1mb

hanadb\$1data\$1write\$1time\$1milliseconds

hanadb\$1log\$1write\$1size\$1mb

hanadb\$1log\$1write\$1time\$1milliseconds

hanadb\$1data\$1read\$1size\$1mb

hanadb\$1data\$1read\$1time\$1milliseconds

hanadb\$1log\$1read\$1size\$1mb

hanadb\$1log\$1read\$1time\$1milliseconds

hanadb\$1data\$1backup\$1write\$1size\$1mb

hanadb\$1data\$1backup\$1write\$1time\$1milliseconds

hanadb\$1log\$1backup\$1write\$1size\$1mb

hanadb\$1log\$1backup\$1write\$1time\$1milliseconds

hanadb\$1mutex\$1collision\$1count

hanadb\$1read\$1write\$1lock\$1collision\$1count

hanadb\$1admission\$1control\$1admit\$1count

hanadb\$1admission\$1control\$1reject\$1count

hanadb\$1admission\$1control\$1queue\$1size\$1mb

hanadb\$1admission\$1control\$1wait\$1time\$1milliseconds

# SAP ASE
<a name="appinsights-metrics-sap-ase"></a>

CloudWatch Application Insights 支援以下指標：

asedb\$1database\$1availability

asedb\$1trunc\$1log\$1on\$1chkpt\$1enabled

asedb\$1last\$1db\$1backup\$1age\$1in\$1days

asedb\$1last\$1transaction\$1log\$1backup\$1age\$1in\$1hours

asedb\$1suspected\$1database

asedb\$1db\$1space\$1usage\$1percent

asedb\$1db\$1log\$1space\$1usage\$1percent

asedb\$1locked\$1login

asedb\$1has\$1mixed\$1log\$1and\$1data

asedb\$1runtime\$1for\$1open\$1transactions

asedb\$1data\$1cache\$1hit\$1ratio

asedb\$1data\$1cache\$1usage

asedb\$1sql\$1cache\$1hit\$1ratio

asedb\$1cache\$1usage

asedb\$1run\$1queue\$1length

asedb\$1number\$1of\$1rollbacks

asedb\$1number\$1of\$1commits

asedb\$1number\$1of\$1transactions

asedb\$1outstanding\$1disk\$1io

asedb\$1percent\$1io\$1busy

asedb\$1percent\$1system\$1busy

asedb\$1percent\$1locks\$1active

asedb\$1scheduled\$1jobs\$1failed\$1percent

asedb\$1user\$1connections\$1percent

asedb\$1query\$1logical\$1reads

asedb\$1query\$1physical\$1reads

asedb\$1query\$1cpu\$1time

asedb\$1query\$1memory\$1usage

# 在 Amazon EC2 上的 SAP ASE 高可用性
<a name="appinsights-metrics-sap-ase-ha"></a>

CloudWatch Application Insights 支援以下指標：

asedb\$1ha\$1replication\$1state

asedb\$1ha\$1replication\$1mode

asedb\$1ha\$1replication\$1latency\$1in\$1minutes

# SAP NetWeaver
<a name="appinsights-metrics-sap-netweaver"></a>

CloudWatch Application Insights 支援以下指標：


| 指標 | Description | 
| --- | --- | 
| sap\$1alerts\$1ResponseTime |  來自 CCMS (RZ20)>R3Services>Dialog>ResponseTime 的 SAP 回應時間提醒。  | 
|  sap\$1alerts\$1ResponseTimeDialog  | 來自 CCMS (RZ20)>R3Services>Dialog> ResponseTimeDialog 的 SAP 回應時間對話方塊提醒。 | 
| sap\$1alerts\$1ResponseTimeDialogRFC | 來自 CCMS (RZ20)>R3Services> Dialog>ResponseTimeDialogRFC 的 SAP 回應時間提醒。 | 
| sap\$1alerts\$1DBRequestTime | 來自 CCMS (RZ20)>R3Services>Dialog>DBRequestTime 的 SAP 回應時間提醒。 | 
| sap\$1alerts\$1FrontendResponseTime | 來自 CCMS (RZ20)>R3Services > Dialog>FrontEndResponseTime 的 SAP 回應時間提醒。 | 
| sap\$1alerts\$1Database  | SAP 系統已記錄與資料庫相關的錯誤。來自 SM21 或 CCMS (RZ20)>R3Syslog>Database 的提醒。 | 
| sap\$1alerts\$1QueueTime  | 來自 CCMS (RZ20)>R3Services>Dialog>QueueTime 的 SAP 佇列時間提醒。 | 
| sap\$1alerts\$1AbortedJobs | SAP 系統中失敗的背景作業。來自 (RZ20)>R3Services > Background>AbortedJobs 的提醒。 | 
| sap\$1alerts\$1BasisSystem | SAP 系統記錄了系統層級錯誤。來自 SM21 或 CCMS (RZ20)>R3Syslog>BasisSystem 的提醒。 | 
| sap\$1alerts\$1Security  | SAP 系統記錄了與安全相關的訊息。來自 SM21 或 CCMS (RZ20)>R3Syslog>Security 的提醒。 | 
| sap\$1alerts\$1System  | SAP 系統記錄了與安全或稽核相關訊息。來自 SM21 或 CCMS (RZ20)>Security>System 的提醒。 | 
| sap\$1alerts\$1LongRunners  | 您的 SAP 系統中有長時間執行的程序。來自 CCMS (RZ20)>R3Services > Dialog>LongRunners 的提醒。 | 
| sap\$1alerts\$1SqlError  | 有 SAP 資料庫用戶端層錯誤日誌。來自 CCMS(RZ20)>DatabaseClient>AbapSql>SqlError 的提醒。 | 
| sap\$1alerts\$1State  | 來自 CCMS (RZ20)>OS Collector>State 的提醒。 | 
| sap\$1alerts\$1Shortdumps  | 來自 ST22 和 CCMS (RZ20)>R3Abap>Shortdumps 的 Shortdumps 提醒。 | 
| sap\$1alerts\$1Availability  | 來自 SM21、SM50、SM51、SM66 和 CCMS (RZ20)>InstanceAsTask>Availability 的 SAP 應用程式伺服器執行個體的可用性提醒。 | 
| sap\$1dispatcher\$1queue\$1high | SAPControl Web 服務函數 GetQueueStatistic 會提供發送器佇列高計數。 | 
| sap\$1dispatcher\$1queue\$1max | SAPControl Web 服務函數 GetQueueStatistic 會提供發送器佇列計數上限。 | 
| sap\$1dispatcher\$1queue\$1now | SAPControl Web 服務函數 GetQueueStatistic 會提供發送器佇列當前計數。 | 
| sap\$1dispatcher\$1queue\$1reads | SAPControl Web 服務函數 GetQueueStatistic 會提供發送器佇列讀取計數。 | 
| sap\$1dispatcher\$1queue\$1writes | SAPControl Web 服務函數 GetQueueStatistic 會提供發送器佇列寫入計數。 | 
| sap\$1enqueue\$1server\$1arguments\$1high  | SAPControl Web 服務函數 EnqGetStatistic 會提供高排入佇列引數數量。 | 
| sap\$1enqueue\$1server\$1arguments\$1max  | SAPControl Web 服務函數 EnqGetStatistic 會提供排入佇列引數數量上限。 | 
| sap\$1enqueue\$1server\$1arguments\$1now | SAPControl Web 服務函數 EnqGetStatistic 會提供當前排入佇列引數數量。 | 
| sap\$1enqueue\$1server\$1arguments\$1state | SAPControl Web 服務函數 EnqGetStatistic 會提供排入佇列引數狀態。 | 
| sap\$1enqueue\$1server\$1backup\$1requests | SAPControl Web 服務函數 EnqGetStatistic 會提供排入佇列備份請求數量。 | 
| sap\$1enqueue\$1server\$1cleanup\$1requests | SAPControl Web 服務函數 EnqGetStatistic 會提供排入佇列清除請求數量。 | 
| sap\$1enqueue\$1server\$1dequeue\$1all\$1requests | SAPControl Web 服務函數 EnqGetStatistic 會提供所有移出佇列請求數量。 | 
| sap\$1enqueue\$1server\$1dequeue\$1errors | SAPControl Web 服務函數 EnqGetStatistic 會提供移出佇列錯誤數量。 | 
| sap\$1enqueue\$1server\$1dequeue\$1requests  | SAPControl Web 服務函數 EnqGetStatistic 會提供移出佇列請求數量。 | 
| sap\$1enqueue\$1server\$1enqueue\$1errors | SAPControl Web 服務函數 EnqGetStatistic 會提供排入佇列錯誤數量。 | 
| sap\$1enqueue\$1server\$1enqueue\$1rejects  | SAPControl Web 服務函數 EnqGetStatistic 會提供排入佇列拒絕數量。 | 
| sap\$1enqueue\$1server\$1enqueue\$1requests | SAPControl Web 服務函數 EnqGetStatistic 會提供排入佇列請求數量。 | 
| sap\$1enqueue\$1server\$1lock\$1time | SAPControl Web 服務函數 EnqGetStatistic 會提供排入佇列鎖定時間。 | 
| sap\$1enqueue\$1server\$1lock\$1wait\$1time | SAPControl Web 服務函數 EnqGetStatistic 會提供排入佇列鎖定等待時間。 | 
| sap\$1enqueue\$1server\$1locks\$1high | SAPControl Web 服務函數 EnqGetStatistic 會提供高排入佇列鎖定數量。 | 
| sap\$1enqueue\$1server\$1locks\$1max | SAPControl Web 服務函數 EnqGetStatistic 會提供排入佇列鎖定數量上限。 | 
| sap\$1enqueue\$1server\$1locks\$1now | SAPControl Web 服務函數 EnqGetStatistic 會提供當前排入佇列鎖定數量。 | 
| sap\$1enqueue\$1server\$1locks\$1state | SAPControl Web 服務函數 EnqGetStatistic 會提供排入佇列鎖定狀態。 | 
| sap\$1enqueue\$1server\$1owner\$1high | SAPControl Web 服務函數 EnqGetStatistic 會提供高排入佇列擁有者。 | 
| sap\$1enqueue\$1server\$1owner\$1max | SAPControl Web 服務函數 EnqGetStatistic 會提供最大排入佇列擁有者。 | 
| sap\$1enqueue\$1server\$1owner\$1now | SAPControl Web 服務函數 EnqGetStatistic 會提供當前排入佇列擁有者。 | 
| sap\$1enqueue\$1server\$1owner\$1state | SAPControl Web 服務函數 EnqGetStatistic 會提供排入佇列擁有者狀態。 | 
| sap\$1enqueue\$1server\$1replication\$1state  | SAPControl Web 服務函數 EnqGetStatistic 會提供排入佇列複寫狀態。 | 
| sap\$1enqueue\$1server\$1reporting\$1requests | SAPControl Web 服務函數 EnqGetStatistic 會提供報告請求狀態。 | 
| sap\$1enqueue\$1server\$1server\$1time | SAPControl Web 服務函數 EnqGetStatistic 會提供排入佇列伺服器時間。 | 
| sap\$1HA\$1check\$1failover\$1config\$1state | SAPControl Web 服務功能 HACheckFailoverConfig 會提供 SAP 高可用性狀態。 | 
| sap\$1HA\$1get\$1failover\$1config\$1HAActive | SAPControl Web 服務函數 HAGetFailoverConfig 會提供 SAP 高可用性叢集組態和狀態。 | 
| sap\$1start\$1service\$1processes  | SAPControl Web 服務函數 GetProcessList 會提供顯示 disp\$1work、IGS、gwrd、icman、訊息伺服器和排入佇列伺服器程序的狀態。 | 

# HA 叢集
<a name="appinsights-metrics-ha-cluster"></a>

CloudWatch Application Insights 支援以下指標：

ha\$1cluster\$1pacemaker\$1stonith\$1enabled 

ha\$1cluster\$1corosync\$1quorate

hanadb\$1webdispatcher\$1service\$1started\$1status

ha\$1cluster\$1pacemaker\$1nodes 

ha\$1cluster\$1corosync\$1ring\$1errors

ha\$1cluster\$1pacemaker\$1fail\$1count 

# Java
<a name="appinsights-metrics-java"></a>

CloudWatch Application Insights 支援以下指標：

java\$1lang\$1memory\$1heapmemoryusage\$1used

java\$1lang\$1memory\$1heapmemoryusage\$1committed

java\$1lang\$1operatingsystem\$1openfiledescriptorcount

java\$1lang\$1operatingsystem\$1maxfiledescriptorcount

java\$1lang\$1operatingsystem\$1freephysicalmemorysize

java\$1lang\$1operatingsystem\$1freeswapspacesize

java\$1lang\$1threading\$1threadcount

java\$1lang\$1threading\$1daemonthreadcount

java\$1lang\$1classloading\$1loadedclasscount

java\$1lang\$1garbagecollector\$1collectiontime\$1copy

java\$1lang\$1garbagecollector\$1collectiontime\$1ps\$1scavenge

java\$1lang\$1garbagecollector\$1collectiontime\$1parnew

java\$1lang\$1garbagecollector\$1collectiontime\$1marksweepcompact

java\$1lang\$1garbagecollector\$1collectiontime\$1ps\$1marksweep

java\$1lang\$1garbagecollector\$1collectiontime\$1concurrentmarksweep

java\$1lang\$1garbagecollector\$1collectiontime\$1g1\$1young\$1generation

java\$1lang\$1garbagecollector\$1collectiontime\$1g1\$1old\$1generation

java\$1lang\$1garbagecollector\$1collectiontime\$1g1\$1mixed\$1generation

java\$1lang\$1operatingsystem\$1committedvirtualmemorysize

# Amazon Elastic Container Service (Amazon ECS)
<a name="appinsights-metrics-ecs"></a>

CloudWatch Application Insights 支援以下指標：

**Topics**
+ [CloudWatch 內建指標](#appinsights-metrics-ecs-built-in-metrics)
+ [Container Insights 指標](#appinsights-metrics-ecs-container-insights-metrics)
+ [Container Insights Prometheus 指標](#appinsights-metrics-ecs-container-insights-prometheus)

## CloudWatch 內建指標
<a name="appinsights-metrics-ecs-built-in-metrics"></a>

CPUReservation

CPUUtilization

MemoryReservation

MemoryUtilization

GPUReservation

## Container Insights 指標
<a name="appinsights-metrics-ecs-container-insights-metrics"></a>

ContainerInstanceCount

CpuUtilized

CpuReserved

DeploymentCount

DesiredTaskCount

MemoryUtilized

MemoryReserved

NetworkRxBytes

NetworkTxBytes

PendingTaskCount

RunningTaskCount

ServiceCount

StorageReadBytes

StorageWriteBytes

TaskCount

TaskSetCount

instance\$1cpu\$1limit

instance\$1cpu\$1reserved\$1capacity

instance\$1cpu\$1usage\$1total

instance\$1cpu\$1utilization

instance\$1filesystem\$1utilization

instance\$1memory\$1limit

instance\$1memory\$1reserved\$1capacity

instance\$1memory\$1utilization

instance\$1memory\$1working\$1set

執行個體網路總數 (\$1O) 位元組

instance\$1number\$1of\$1running\$1tasks

## Container Insights Prometheus 指標
<a name="appinsights-metrics-ecs-container-insights-prometheus"></a>

**Javer JMX 指標**

java\$1lang\$1memory\$1heapmemoryusage\$1used

java\$1lang\$1memory\$1heapmemoryusage\$1committed

java\$1lang\$1operatingsystem\$1openfiledescriptorcount

java\$1lang\$1operatingsystem\$1maxfiledescriptorcount

java\$1lang\$1operatingsystem\$1freephysicalmemorysize

java\$1lang\$1operatingsystem\$1freeswapspacesize

java\$1lang\$1threading\$1threadcount

java\$1lang\$1classloading\$1loadedclasscount

java\$1lang\$1threading\$1daemonthreadcount

java\$1lang\$1garbagecollector\$1collectiontime\$1copy

java\$1lang\$1garbagecollector\$1collectiontime\$1ps\$1scavenge

java\$1lang\$1garbagecollector\$1collectiontime\$1parnew

java\$1lang\$1garbagecollector\$1collectiontime\$1marksweepcompact

java\$1lang\$1garbagecollector\$1collectiontime\$1ps\$1marksweep

java\$1lang\$1garbagecollector\$1collectiontime\$1concurrentmarksweep

java\$1lang\$1garbagecollector\$1collectiontime\$1g1\$1young\$1generation

java\$1lang\$1garbagecollector\$1collectiontime\$1g1\$1old\$1generation

java\$1lang\$1garbagecollector\$1collectiontime\$1g1\$1mixed\$1generation

java\$1lang\$1operatingsystem\$1committedvirtualmemorysize

# 上的 Kubernetes AWS
<a name="appinsights-metrics-kubernetes"></a>

CloudWatch Application Insights 支援以下指標：

**Topics**
+ [Container Insights 指標](#appinsights-metrics-kubernetes-container-insights-metrics)
+ [Container Insights Prometheus 指標](#appinsights-metrics-kubernetes-container-insights-prometheus)

## Container Insights 指標
<a name="appinsights-metrics-kubernetes-container-insights-metrics"></a>

cluster\$1failed\$1node\$1count

cluster\$1node\$1count

namespace\$1number\$1of\$1running\$1pods

node\$1cpu\$1limit

node\$1cpu\$1reserved\$1capacity

node\$1cpu\$1usage\$1total

node\$1cpu\$1utilization

node\$1filesystem\$1utilization

node\$1memory\$1limit

node\$1memory\$1reserved\$1capacity

node\$1memory\$1utilization

node\$1memory\$1working\$1set

node\$1network\$1total\$1bytes

node\$1number\$1of\$1running\$1containers

node\$1number\$1of\$1running\$1pods

pod\$1cpu\$1reserved\$1capacity

pod\$1cpu\$1utilization

pod\$1cpu\$1utilization\$1over\$1pod\$1limit

pod\$1memory\$1reserved\$1capacity

pod\$1memory\$1utilization

pod\$1memory\$1utilization\$1over\$1pod\$1limit

pod\$1network\$1rx\$1bytes

pod\$1network\$1tx\$1bytes

service\$1number\$1of\$1running\$1pods

## Container Insights Prometheus 指標
<a name="appinsights-metrics-kubernetes-container-insights-prometheus"></a>

**Javer JMX 指標**

java\$1lang\$1memory\$1heapmemoryusage\$1used

java\$1lang\$1memory\$1heapmemoryusage\$1committed

java\$1lang\$1operatingsystem\$1openfiledescriptorcount

java\$1lang\$1operatingsystem\$1maxfiledescriptorcount

java\$1lang\$1operatingsystem\$1freephysicalmemorysize

java\$1lang\$1operatingsystem\$1freeswapspacesize

java\$1lang\$1threading\$1threadcount

java\$1lang\$1classloading\$1loadedclasscount

java\$1lang\$1threading\$1daemonthreadcount

java\$1lang\$1garbagecollector\$1collectiontime\$1copy

java\$1lang\$1garbagecollector\$1collectiontime\$1ps\$1scavenge

java\$1lang\$1garbagecollector\$1collectiontime\$1parnew

java\$1lang\$1garbagecollector\$1collectiontime\$1marksweepcompact

java\$1lang\$1garbagecollector\$1collectiontime\$1ps\$1marksweep

java\$1lang\$1garbagecollector\$1collectiontime\$1concurrentmarksweep

java\$1lang\$1garbagecollector\$1collectiontime\$1g1\$1young\$1generation

java\$1lang\$1garbagecollector\$1collectiontime\$1g1\$1old\$1generation

java\$1lang\$1garbagecollector\$1collectiontime\$1g1\$1mixed\$1generation

java\$1lang\$1operatingsystem\$1committedvirtualmemorysize

# Amazon FSx
<a name="appinsights-metrics-fsx"></a>

CloudWatch Application Insights 支援以下指標：

DataReadBytes

DataWriteBytes

DataReadOperations

DataWriteOperations

MetadataOperations

FreeStorageCapacity

FreeDataStorageCapacity

LogicalDiskUsage

PhysicalDiskUsage

# Amazon VPC
<a name="appinsights-metrics-vpc"></a>

CloudWatch Application Insights 支援以下指標：

NetworkAddressUsage

NetworkAddressUsagePeered

VPCFirewallQueryVolume

# Amazon VPC NAT 閘道
<a name="appinsights-metrics-nat-gateways"></a>

CloudWatch Application Insights 支援以下指標：

ErrorPortAllocation

IdleTimeoutCount

# Amazon Route 53 運作狀態檢查
<a name="appinsights-metrics-health-check"></a>

CloudWatch Application Insights 支援以下指標：

ChildHealthCheckHealthyCount

ConnectionTime

HealthCheckPercentageHealthy

HealthCheckStatus

SSLHandshakeTime 

TimeToFirstByte

# Amazon Route 53 託管區域
<a name="appinsights-metrics-hosted-zone"></a>

CloudWatch Application Insights 支援以下指標：

DNSQueries

DNSSECInternalFailure

DNSSECKeySigningKeysNeedingAction

DNSSECKeySigningKeyMaxNeedingActionAge

DNSSECKeySigningKeyAge

# Amazon Route 53 Resolver endpoint
<a name="appinsights-metrics-resolver-endpoint"></a>

CloudWatch Application Insights 支援以下指標：

EndpointHealthyENICount

EndpointUnHealthyENICount

InboundQueryVolume

OutboundQueryVolume

OutboundQueryAggregateVolume

# AWS Network Firewall 規則群組
<a name="appinsights-metrics-firewall-rule-group"></a>

CloudWatch Application Insights 支援以下指標：

FirewallRuleGroupQueryVolume

# AWS Network Firewall 規則群組關聯
<a name="appinsights-metrics-firewall-rule-group-assoc"></a>

CloudWatch Application Insights 支援以下指標：

FirewallRuleGroupVpcQueryVolume

# 具有指標資料點要求的指標
<a name="appinsights-metrics-datapoint-requirements"></a>

針對沒有明顯預設警示閾值的指標，Application Insights 會等到指標有足夠的資料點可預測合理的警示閾值。CloudWatch Application Insights 建立警示前會先檢查的指標資料點要求如下：
+ 指標至少有過去 15 天到過去 2 天的 100 個資料點。
+ 指標至少有最後一天的 100 個資料點。

以下指標會遵循以下資料點要求。請注意，CloudWatch 代理指標最多需要 1 小時來建立警示。

**Topics**
+ [AWS/ApplicationELB](#appinsights-metrics-datapoint-requirements-app-elb)
+ [AWS/AutoScaling](#appinsights-metrics-datapoint-requirements-autoscaling)
+ [AWS/EC2](#appinsights-metrics-datapoint-requirements-ec2)
+ [Elastic Block Store (EBS)](#appinsights-metrics-datapoint-requirements-ebs)
+ [AWS/ELB](#appinsights-metrics-datapoint-requirements-elb)
+ [AWS/RDS](#appinsights-metrics-datapoint-requirements-rds)
+ [AWS/Lambda](#appinsights-metrics-datapoint-requirements-lambda)
+ [AWS/SQS](#appinsights-metrics-datapoint-requirements-sqs)
+ [AWS/CWAgent](#appinsights-metrics-datapoint-requirements-cwagent)
+ [AWS/DynamoDB](#appinsights-metrics-datapoint-requirements-dynamo)
+ [AWS/S3](#appinsights-metrics-datapoint-requirements-s3)
+ [AWS/狀態](#appinsights-metrics-datapoint-requirements-states)
+ [AWS/ApiGateway](#appinsights-metrics-datapoint-requirements-api-gateway)
+ [AWS/SNS](#appinsights-metrics-datapoint-requirements-sns)

## AWS/ApplicationELB
<a name="appinsights-metrics-datapoint-requirements-app-elb"></a>

ActiveConnectionCount

ConsumedLCUs

HTTPCode\$1ELB\$14XX\$1Count

HTTPCode\$1Target\$12XX\$1Count

HTTPCode\$1Target\$13XX\$1Count

HTTPCode\$1Target\$14XX\$1Count

HTTPCode\$1Target\$15XX\$1Count

NewConnectionCount

ProcessedBytes

TargetResponseTime

UnHealthyHostCount

## AWS/AutoScaling
<a name="appinsights-metrics-datapoint-requirements-autoscaling"></a>

GroupDesiredCapacity

GroupInServiceInstances

GroupMaxSize

GroupMinSize

GroupPendingInstances

GroupStandbyInstances

GroupTerminatingInstances

GroupTotalInstances

## AWS/EC2
<a name="appinsights-metrics-datapoint-requirements-ec2"></a>

CPUCreditBalance

CPUCreditUsage

CPUSurplusCreditBalance

CPUSurplusCreditsCharged

CPUUtilization

DiskReadBytes

DiskReadOps

DiskWriteBytes

DiskWriteOps

EBSByteBalance%

EBSIOBalance%

EBSReadBytes

EBSReadOps

EBSWriteBytes

EBSWriteOps

NetworkIn

NetworkOut

NetworkPacketsIn

NetworkPacketsOut

## Elastic Block Store (EBS)
<a name="appinsights-metrics-datapoint-requirements-ebs"></a>

VolumeReadBytes 

VolumeWriteBytes 

VolumeReadOps

VolumeWriteOps

VolumeTotalReadTime 

VolumeTotalWriteTime 

VolumeIdleTime

VolumeQueueLength

VolumeThroughputPercentage

VolumeConsumedReadWriteOps

BurstBalance

## AWS/ELB
<a name="appinsights-metrics-datapoint-requirements-elb"></a>

EstimatedALBActiveConnectionCount

EstimatedALBConsumedLCUs

EstimatedALBNewConnectionCount

EstimatedProcessedBytes

HTTPCode\$1Backend\$14XX

HTTPCode\$1Backend\$15XX

HealthyHostCount

延遲

RequestCount

SurgeQueueLength

UnHealthyHostCount

## AWS/RDS
<a name="appinsights-metrics-datapoint-requirements-rds"></a>

ActiveTransactions

AuroraBinlogReplicaLag

AuroraReplicaLag

BackupRetentionPeriodStorageUsed

BinLogDiskUsage

BlockedTransactions

CPUCreditBalance

CommitLatency

CommitThroughput

DDLLatency

DDLThroughput

DMLLatency

DMLThroughput

DatabaseConnections

鎖死

DeleteLatency

DeleteThroughput

DiskQueueDepth

EngineUptime

FreeLocalStorage

FreeStorageSpace

FreeableMemory

InsertLatency

InsertThroughput

LoginFailures

NetworkReceiveThroughput

NetworkThroughput

NetworkTransmitThroughput

查詢

ReadIOPS

ReadThroughput

SelectLatency

SelectThroughput

SnapshotStorageUsed

TotalBackupStorageBilled

UpdateLatency

UpdateThroughput

VolumeBytesUsed

VolumeReadIOPs

VolumeWriteIOPs

WriteIOPS

WriteThroughput

## AWS/Lambda
<a name="appinsights-metrics-datapoint-requirements-lambda"></a>

錯誤

DeadLetterErrors

持續時間

限流

IteratorAge

ProvisionedConcurrencySpilloverInvocations

## AWS/SQS
<a name="appinsights-metrics-datapoint-requirements-sqs"></a>

ApproximateAgeOfOldestMessage

ApproximateNumberOfMessagesDelayed

ApproximateNumberOfMessagesNotVisible

ApproximateNumberOfMessagesVisible

NumberOfEmptyReceives

NumberOfMessagesDeleted

NumberOfMessagesReceived

NumberOfMessagesSent

## AWS/CWAgent
<a name="appinsights-metrics-datapoint-requirements-cwagent"></a>

LogicalDisk % 可用空間

記憶體 % 使用中的認可位元組

記憶體可用的 MB 數

網路介面位元組總數/秒

分頁檔用量 %

PhysicalDisk % 磁碟時間

PhysicalDisk Avg. Disk sec/Read

PhysicalDisk Avg. Disk sec/Write

PhysicalDisk 磁碟讀取位元組/秒

PhysicalDisk Disk Reads/sec

PhysicalDisk 磁碟寫入位元組/秒

PhysicalDisk Disk Writes/sec

處理器 % 閒置時間

處理器 % 中斷時間

處理器 % 處理器時間

處理器 % 使用者時間

SQLServer:Access Methods Forwarded Records/sec

SQLServer:Access Methods Page Splits/sec

SQLServer:Buffer Manager 緩衝快取命中率

SQLServer:Buffer Manager 頁面的預期壽命

SQLServer:已接收的資料庫複本檔案位元組/秒

SQLServer:已接收的資料庫複本日誌位元組/秒

SQL Server:剩餘可復原的資料庫複本日誌

SQL Server:資料庫複本日誌傳送佇列

SQLServer:資料庫複本鏡像寫入交易/秒

SQL Server:資料庫複本復原佇列

SQL Server:剩餘的資料庫複本重做位元組

SQL Server:資料庫複本已重做位元組/秒

SQL Server:需要復原的資料庫複本日誌合計

SQL Server:資料庫複本交易延遲

SQLServer:General Statistics Processes blocked

SQLServer:SQL Statistics 每秒批次要求數

SQLServer:SQL Statistics SQL Compilations/sec

SQLServer:SQL Statistics SQL Re-Compilations/sec

系統處理器佇列長度

已建立 TCPv4 連線

已建立 TCPv6 連線

## AWS/DynamoDB
<a name="appinsights-metrics-datapoint-requirements-dynamo"></a>

ConsumedReadCapacityUnits

ConsumedWriteCapacityUnits

ReadThrottleEvents

WriteThrottleEvents

TimeToLiveDeletedItemCount

ConditionalCheckFailedRequests

TransactionConflict

ReturnedRecordsCount

PendingReplicationCount

ReplicationLatency

## AWS/S3
<a name="appinsights-metrics-datapoint-requirements-s3"></a>

ReplicationLatency

BytesPendingReplication

OperationsPendingReplication

4xxErrors

5xxErrors

AllRequests

GetRequests

PutRequests

DeleteRequests

HeadRequests

PostRequests

SelectRequests

ListRequests

SelectScannedBytes

SelectReturnedBytes

FirstByteLatency

TotalRequestLatency

BytesDownloaded

BytesUploaded

## AWS/狀態
<a name="appinsights-metrics-datapoint-requirements-states"></a>

ActivitiesScheduled

ActivitiesStarted

ActivitiesSucceeded

ActivityScheduleTime

ActivityRuntime

ActivityTime

LambdaFunctionsScheduled

LambdaFunctionsStarted

LambdaFunctionsSucceeded

LambdaFunctionScheduleTime

LambdaFunctionRuntime

LambdaFunctionTime

ServiceIntegrationsScheduled

ServiceIntegrationsStarted

ServiceIntegrationsSucceeded

ServiceIntegrationScheduleTime

ServiceIntegrationRuntime

ServiceIntegrationTime

ProvisionedRefillRate

ProvisionedBucketSize

ConsumedCapacity

ThrottledEvents

## AWS/ApiGateway
<a name="appinsights-metrics-datapoint-requirements-api-gateway"></a>

4XXError 

IntegrationLatency

延遲

DataProcessed

CacheHitCount

CacheMissCount

## AWS/SNS
<a name="appinsights-metrics-datapoint-requirements-sns"></a>

NumberOfNotificationsDelivered

NumberOfMessagesPublished

NumberOfNotificationsFailed

NumberOfNotificationsFilteredOut

NumberOfNotificationsFilteredOut-InvalidAttributes

NumberOfNotificationsFilteredOut-NoMessageAttributes

NumberOfNotificationsRedrivenToDlq

NumberOfNotificationsFailedToRedriveToDlq

SMSSuccessRate

# 建議的指標
<a name="application-insights-recommended-metrics"></a>

下表列出每個元件類型的建議指標。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/application-insights-recommended-metrics.html)

下表列出每個元件類型的建議程式和程式指標。對於未在執行個體上執行的程式，CloudWatch Application Insights 不建議進行程式監控。

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/zh_tw/AmazonCloudWatch/latest/monitoring/application-insights-recommended-metrics.html)

# 效能計數器指標
<a name="application-insights-performance-counter"></a>

只有在 Windows 執行個體上安裝對應的效能計數器集時，才建議執行個體使用效能計數器指標。


| 效能計數器指標名稱 | 效能計數器集名稱 | 
| --- | --- | 
| 擲出的 .NET CLR 異常數 | .NET CLR 異常情形 | 
| 每秒擲出的 .NET CLR 異常數  | .NET CLR 異常情形 | 
| 每秒篩選的 .NET CLR 異常數  | .NET CLR 異常情形 | 
| 每秒最終的 .NET CLR 異常數  | .NET CLR 異常情形 | 
| 每秒擲出以捕捉深度的 .NET CLR 異常  | .NET CLR 異常情形 | 
| CCW 的 .NET CLR Interop 數  | .NET CLR Interop  | 
| Stub 的 .NET CLR Interop 數  | .NET CLR Interop  | 
| 每秒 TLB 匯出的 .NET CLR Interop 數  | .NET CLR Interop  | 
| 每秒 TLB 匯入的 .NET CLR Interop 數  | .NET CLR Interop  | 
| 封送處理的 .NET CLR Interop 數  | .NET CLR Interop  | 
| Jit 的 .NET CLR Jit 時間百分比  | .NET CLR Jit  | 
| .NET CLR Jit 標準 Jit 失敗  | .NET CLR Jit  | 
| .NET CLR 正在載入 - 正在載入時間百分比  | .NET CLR 正在載入  | 
| .NET CLR 載入失敗的載入速率  | .NET CLR 正在載入  | 
| .NET CLR LocksAndThreads 爭用速率/秒  | .NET CLR LocksAndThreads  | 
| .NET CLR LocksAndThreads 佇列長度/秒  | .NET CLR LocksAndThreads  | 
| .NET CLR 記憶體數總遞交的位元組  | .NET CLR 記憶體 | 
| .NET CLR 記憶體在 GC 中時間佔比 | .NET CLR 記憶體 | 
| .NET CLR Networking 4.0.0.0 HttpWebRequest 平均佇列時間  | .NET CLR Networking 4.0.0.0  | 
| .NET CLR Networking 4.0.0.0 HttpWebRequests 中止/秒  | .NET CLR Networking 4.0.0.0  | 
| .NET CLR Networking 4.0.0.0 HttpWebRequests 失敗/秒  | .NET CLR Networking 4.0.0.0  | 
| .NET CLR Networking 4.0.0.0 HttpWebRequests 佇列/秒  | .NET CLR Networking 4.0.0.0  | 
| APP\$1POL\$1WAS 總工作者處理序 Ping 失敗 | APP\$1POOL\$1WAS | 
| ASP.NET 應用程式重新啟動  | ASP.NET  | 
| ASP.NET 請求已遭拒絕 | ASP.NET | 
| ASP.NET 工作程序重新啟動 | ASP.NET | 
| ASP.NET 應用程式快取 API 裁剪 | ASP.NET 應用程式 | 
| ASP.NET 應用程式 % 受管處理器時間 (估計) | ASP.NET 應用程式 | 
| ASP.NET 應用程式錯誤總計/秒 | ASP.NET 應用程式 | 
|  ASP.NET 應用程式執行期間未處理錯誤/秒  |  ASP.NET 應用程式  | 
|  應用程式佇列中的 ASP.NET 應用程式請求  |  ASP.NET 應用程式  | 
|  ASP.NET 應用程式請求/秒  |  ASP.NET 應用程式  | 
| ASP.NET 請求等待時間  | ASP.NET  | 
| ASP.NET 請求已排入佇列  | ASP.NET  | 
| 資料庫 ==> 執行個體資料庫快取 % 命中率 | 資料庫 ==> 執行個體 | 
| 資料庫 ==> 執行個體輸入/輸出資料庫讀取平均延遲 | 資料庫 ==> 執行個體 | 
| 資料庫 ==> 執行個體輸入/輸出資料庫讀取/秒 | 資料庫 ==> 執行個體 | 
| 資料庫 ==> 執行個體輸入/輸出日誌寫入平均延遲 | 資料庫 ==> 執行個體 | 
| DirectoryServices DRA 待決複寫作業 | DirectoryServices | 
| DirectoryServices DRA 待決複寫同步 | DirectoryServices | 
| DirectoryServices LDAP 綁定時間 | DirectoryServices | 
| DNS 遞迴查詢/秒 | DNS | 
| DNS 遞迴查詢失敗/秒 | DNS | 
| 收到的 DNS TCP 查詢/秒 | DNS | 
| 收到的 DNS 查詢總數/秒 | DNS | 
| 傳送的 DNS 回應總數/秒 | DNS | 
| 收到的 DNS UDP 查詢/秒 | DNS | 
| HTTP 服務要求佇列 CurrentQueueSize  | HTTP 服務要求佇列  | 
|  LogicalDisk % 可用空間  |  LogicalDisk  | 
| LogicalDisk Avg. Disk sec/Write | LogicalDisk | 
| LogicalDisk Avg. Disk sec/Read | LogicalDisk | 
| LogicalDisk Avg. 磁碟佇列長度 | LogicalDisk | 
|  記憶體 % 使用中的認可位元組  | 記憶體 | 
|  記憶體可用的 MB 數  |  記憶體  | 
| 記憶體分頁/秒  |  記憶體  | 
| 記憶體長期平均備用快取生命週期 (s) | 記憶體 | 
|  網路介面位元組總數/秒  | 網路介面 | 
| 收到的網路介面位元組/秒 | 網路介面 | 
| 傳送的網路介面位元組/秒 | 網路介面 | 
| 網路介面電流頻寬 | 網路介面 | 
|  分頁檔用量 %  |  分頁檔  | 
| PhysicalDisk % 磁碟時間 | PhysicalDisk | 
| PhysicalDisk Avg. 磁碟佇列長度 | PhysicalDisk | 
| PhysicalDisk Avg. Disk Sec/Read | PhysicalDisk | 
| PhysicalDisk Avg. Disk Sec/Write | PhysicalDisk | 
| PhysicalDisk 磁碟讀取位元組/秒 | PhysicalDisk | 
| PhysicalDisk Disk Reads/Sec | PhysicalDisk | 
| PhysicalDisk 磁碟寫入位元組/秒 | PhysicalDisk | 
| PhysicalDisk Disk Writes/Sec | PhysicalDisk | 
|  處理器 % 閒置時間  | 處理器 | 
| 處理器 % 中斷時間 |  處理器  | 
| 處理器 % 處理器時間 |  處理器  | 
| 處理器 % 使用者時間 |  處理器  | 
| SharePoint 磁碟型快取 Blob 快取填充率  | SharePoint 磁碟型快取  | 
| SharePoint 磁碟型快取 Blob 快取清空/秒  | SharePoint 磁碟型快取  | 
| SharePoint 磁碟型快取 Blob 快取命中率  | SharePoint 磁碟型快取  | 
| SharePoint 磁碟型快取快取壓縮總數 | SharePoint 磁碟型快取  | 
| SharePoint Foundation 執行時間/頁面請求 | SharePoint Foundation | 
| SharePoint 發布快取發布快取清空/秒 | SharePoint 發布快取 | 
| 安全全系統範圍統計數字 Kerberos 身分驗證 | 安全全系統範圍統計數字 | 
| 安全全系統範圍統計數字 NTLM 身分驗證 | 安全全系統範圍統計數字 | 
| SQLServer:Access Methods Forwarded Records/Sec |  SQLServer:Access Methods  | 
| SQLServer:Access Methods Full Scans/Sec |  SQLServer:Access Methods  | 
| SQLServer:Access Methods Page Splits/Sec |  SQLServer:Access Methods  | 
| SQLServer:Buffer Manager 緩衝快取命中率 |  SQLServer:Buffer Manager  | 
| SQLServer:Buffer Manager 頁面的預期壽命 |  SQLServer:Buffer Manager  | 
| SQLServer:已接收的資料庫複本檔案位元組/秒 | SQLServer:Database Replica | 
| SQLServer:已接收的資料庫複本日誌位元組/秒 | SQLServer:Database Replica | 
| SQL Server:剩餘可復原的資料庫複本日誌 | SQLServer:Database Replica | 
| SQL Server:資料庫複本日誌傳送佇列 | SQLServer:Database Replica | 
| SQLServer:資料庫複本鏡像寫入交易/秒 | SQLServer:Database Replica | 
| SQL Server:資料庫複本復原佇列 | SQLServer:Database Replica | 
| SQL Server:剩餘的資料庫複本重做位元組 | SQLServer:Database Replica | 
| SQL Server:資料庫複本已重做位元組/秒 | SQLServer:Database Replica | 
| SQL Server:需要復原的資料庫複本日誌合計 | SQLServer:Database Replica | 
| SQL Server:資料庫複本交易延遲 | SQLServer:Database Replica | 
| SQLServer:General Statistics Processes Blocked |  SQLServer:General Statistics  | 
| SQLServer：一般統計資料使用者連線 | SQLServer:General Statistics | 
| SQLServer：閂鎖平均閂鎖等待時間 (毫秒)  | SQLServer：閂鎖  | 
| SQLServer：鎖定平均等待時間 (毫秒)  | SQLServer：鎖定  | 
| SQLServer：鎖定鎖定逾時/秒  | SQLServer：鎖定  | 
| SQLServer：鎖定鎖定等待/秒  | SQLServer：鎖定  | 
| SQLServer：鎖定死鎖數目/秒  | SQLServer：鎖定  | 
| SQLServer：記憶體管理員記憶體授權待定  | SQLServer：記憶體管理員  | 
| SQLServer:SQL Statistics Batch Requests/Sec | SQLServer:SQL Statistics | 
| SQLServer:SQL Statistics SQL Compilations/Sec | SQLServer:SQL Statistics | 
| SQLServer:SQL Statistics SQL Re-Compilations/Sec |  SQLServer:SQL Statistics  | 
| 系統處理器佇列長度 |  系統  | 
| 已建立 TCPv4 連線 | TCPv4 | 
| 已建立 TCPv6 連線 | TCPv6 | 
| W3SVC\$1W3WP 檔案饋取排清  | W3SVC\$1W3WP  | 
| W3SVC\$1W3WP 檔案快取遺漏  | W3SVC\$1W3WP  | 
| W3SVC\$1W3WP 請求/秒  | W3SVC\$1W3WP  | 
| W3SVC\$1W3WP URI 快取排清  | W3SVC\$1W3WP  | 
| W3SVC\$1W3WP URI 快取遺漏  | W3SVC\$1W3WP  | 
| 接收的 Web 服務位元組/秒 |  Web 服務  | 
| 傳送的 Web 服務位元組/秒 |  Web 服務  | 
|  Web 服務連線嘗試/秒   |  Web 服務  | 
| Web 服務目前連線數目  |  Web 服務  | 
| Web 服務收到請求/秒  |  Web 服務  | 
| Web 服務 POST 請求/秒  |  Web 服務  | 

# 在 CloudWatch 主控台中使用資源運作狀態檢視
<a name="servicelens_resource_health"></a>

您可以使用資源運作狀態檢視，在單一檢視中跨應用程式自動探索、管理及視覺化主機的運作狀態和效能。您可以透過效能維度 (例如 CPU 或記憶體) 視覺化其主機的運作狀態，並使用篩選條件在單一檢視中並排顯示數百台主機。您可以依標籤或使用案例 (例如相同 Auto Scaling 群組中的主機或使用相同負載平衡器的主機) 進行篩選。

## 先決條件
<a name="servicelens_resource_health-prerequisites"></a>

若要確認您獲得資源運作狀態檢視的完整效益，請檢查您是否具備下列先決條件。
+ 若要查看主機的記憶體使用率並將其用作篩選條件，您必須在主機上安裝 CloudWatch 代理程式，並將其設定為在預設 `CWAgent` 命名空間中將記憶體指標傳送至 CloudWatch。在 Linux 和 macOS 執行個體上，CloudWatch 代理程式必須傳送 `mem_used_percent` 指標。在 Windows 執行個體上，代理程式必須傳送 `Memory % Committed Bytes In Use` 指標。如果您使用精靈建立 CloudWatch 代理程式組態檔案，並選取任何預先定義的指標集，就會包含這些指標。CloudWatch 代理程式收集的指標以自訂指標計費。如需詳細資訊，請參閱[安裝 CloudWatch 代理程式](install-CloudWatch-Agent-on-EC2-Instance.md)。

  當您使用 CloudWatch 代理程式收集這些記憶體指標以搭配資源運作狀態檢視使用時，您必須在 CloudWatch 代理程式組態檔案中包含下列區段。此區段包含預設維度設定，依預設會建立，因此請勿將此區段的任何部分變更為與下列範例所示不同的任何部分。

  ```
  "append_dimensions": {
    "ImageId": "${aws:ImageId}",
    "InstanceId": "${aws:InstanceId}",
    "InstanceType": "${aws:InstanceType}",
    "AutoScalingGroupName": "${aws:AutoScalingGroupName}"
  },
  ```
+  若要檢視資源運作狀態檢視中可用的所有資訊，您必須登入擁有下列許可的帳戶。如果您使用較少的許可登入，您仍然可以使用資源運作狀態檢視，但是某些效能資料將無法看見。

------
#### [ JSON ]

****  

  ```
  {
      "Version":"2012-10-17",		 	 	 
      "Statement": [
          {
              "Action": [
                  "autoscaling:Describe*",
                  "cloudwatch:Describe*",
                  "cloudwatch:Describe*",
                  "cloudwatch:Get*",
                  "cloudwatch:List*",
                  "logs:Get*",
                  "logs:Describe*",
                  "sns:Get*",
                  "sns:List*",
                  "ec2:DescribeInstances",
                  "ec2:DescribeInstanceStatus",
                  "ec2:DescribeRegions"
              ],
              "Effect": "Allow",
              "Resource": "*"
          }
      ]
  }
  ```

------

**若要檢視您帳戶中的資源運作狀態**

1. 透過 [https://console.aws.amazon.com/cloudwatch/](https://console.aws.amazon.com/cloudwatch/) 開啟 CloudWatch 主控台。

1. 在導覽窗格中，選擇 **Insights**、**EC2 資源運作狀態**。

   隨即出現資源運作狀態頁面，並為您的帳戶中的每個主機顯示一個方形。每個方形都會根據該主機的目前狀態和 **Color by** (顏色依據) 的設定著色。具有警示符號的主機方形有一個或多個警示目前處於 ALARM 狀態。

   您可以在單一檢視中看到多達 500 台主機。如果您的帳戶中有更多主機，請使用此程序的步驟 6 中的篩選條件設定。

1. 若要變更用來顯示每個主機運作狀態的條件，請選擇 **Color by** (顏色依據) 的設定。您可以選擇 **CPU Utilization** (CPU 使用率)、**Memory Utilization** (記憶體使用率) 或 **Status check** (狀態檢查)。記憶體使用率指標僅適用於執行 CloudWatch 代理程式並將其設定為收集記憶體指標，以及將其傳送至預設 `CWAgent` 命名空間的主機。如需詳細資訊，請參閱[使用 CloudWatch 代理程式收集指標、日誌和追蹤](Install-CloudWatch-Agent.md)。

1. 若要變更網格中運作狀態指示器所使用的閾值和顏色，請選擇網格上方的齒輪圖示。

1. 若要切換是否要在主機網格中顯示警示，請選擇或清除 **Show alarms across all metrics** (顯示所有指標的警示)。

1. 若要將映射中的主機分割為群組，選擇 **Group by** (分組依據) 的分組條件。

1. 若要將檢視縮小至較少的主機，請選擇 **Filter by** (篩選依據) 的篩選條件。您可以依標籤和資源群組 (例如 Auto Scaling 群組、執行個體類型、安全群組等) 進行篩選。

1. 若要排序主機，請選擇 **Sort by** (排序依據) 的排序條件。您可以依狀態檢查結果、執行個體狀態、CPU 或記憶體使用率，以及處於 ALARM 狀態的警示數目來排序。

1. 若要查看有關主機的詳細資訊，請選擇代表該主機的方形。隨即會顯示快顯窗格。若要深入了解該主機的相關資訊，請選擇 **View dashboard** (檢視儀表板) 或 **View on list** (檢視清單)。