

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

# 從 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** (刪除應用程式)。這會刪除監控並刪除所有已儲存的應用程式元件監控。不會刪除應用程式資源。