

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

# 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 執行個體中收集內部系統層級指標和日誌。