

# 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)
+ [CloudWatch Application Insights 使用的 AWS Systems Manager (SSM) 软件包](appinsights-ssm-packages.md)
+ [CloudWatch Application Insights 使用的 AWS Systems Manager（SSM）文档](appinsights-ssm-documents.md)

## Application Insights 监控应用程序的方式
<a name="appinsights-how-works-sub"></a>

以下信息描述了 Application Insights 如何监控应用程序。

**应用程序发现和配置**  
首次将应用程序添加到 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 数据库层。

## 数据留存
<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)。许多服务包含无法更改的配额。有关特定服务的配额的更多信息，请参阅针对该服务的文档。

# CloudWatch Application Insights 使用的 AWS 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) 中检索工作负载特定的 Java 指标，以供 Application Insights 配置和监控告警。在 Application Insights 控制台的 **Manage monitoring（管理监控）**页面上，在 **Application tier（应用程序层）**下拉菜单选择 **JAVA application（JAVA 应用程序）**。然后在 **JAVA Prometheus exporter configuration（JAVA Prometheus Exporter 配置）**下，选择您的 **Collection method（收集方法）**和 **JMX port number（JMX 端口号）**。

要使用 [AWS Systems Manager Distributor](https://docs.aws.amazon.com/systems-manager/latest/userguide/distributor.html) 来打包、安装和配置 AWS 提供的 Prometheus JMX Exporter（独立于 Application Insights），请完成以下步骤。

**使用 Prometheus JMX Exporter SSM 软件包的先决条件**
+ 2.3.1550.0 版或更高版本的 SSM Agent 已安装
+ JAVA\$1HOME 环境变量已设置

**安装和配置 `AWSObservabilityExporter-JMXExporterInstallAndConfigure` 软件包**  
`AWSObservabilityExporter-JMXExporterInstallAndConfigure` 软件包是一个 SSM Distributor 软件包，您可以使用它来安装和配置 [Prometheus JMX Exporter](https://github.com/prometheus/jmx_exporter)。当 Prometheus JMX Exporter 发送 Java 指标时，可以配置 CloudWatch 代理来检索 CloudWatch 服务的指标。

1. 根据您的首选项，准备位于 Prometheus GitHub 存储库中的 [Prometheus JMX Exporter YAML 配置文件](https://github.com/prometheus/jmx_exporter#configuration)。使用示例配置和选项说明为您提供指导。

1. 将编码为 Base64 的 Prometheus JMX Exporter YAML 配置文件复制到 [SSM Parameter Store](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. 通过将“Additional Arguments（其他实际参数）”替换为以下内容来更新您在第一步中创建的 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. 验证 CloudWatch 代理是否已安装在您的 Amazon EC2 实例上，以及版本是否为 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 配置文件路径。
   + 指定要向其发布 EMF 指标日志的目标日志组。
   + 为每个指标名称指定两组维度。
   + 发送 8 个（每个指标名称 2 组维度，每组 4 个指标名称）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 Database Exporter](https://prometheus.io/docs/instrumenting/exporters/#third-party-exporters) 中检索工作负载特定的 SAP HANA 指标，以供 Application Insights 配置和监控告警。有关更多信息，请参阅本指南中的[设置 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) 来打包、安装和配置 AWS 提供的 Prometheus HANA Database Exporter 软件包（独立于 Application Insights），请完成以下步骤。

**使用 Prometheus HANA Database Exporter SSM 软件包的先决条件**
+ 2.3.1550.0 版或更高版本的 SSM Agent 已安装
+ 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 Database Exporter](https://github.com/prometheus/jmx_exporter)。当 Prometheus HANA Database Exporter 发送 HANA 数据库指标时，就可以配置 CloudWatch 代理来检索 CloudWatch 服务的指标。

1. 在 [SSM Parameter Store](https://console.aws.amazon.com/systems-manager/parameters) 中创建 SSM 参数以存储该 Exporter 的配置。以下为示例参数值。

   ```
   {\"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 实例上保持空闲状态，以免指标重复。该 Exporter 可以检索 `SYSTEM` 数据库中的所有数据库租户信息。

1. 在 [SSM Parameter Store](https://console.aws.amazon.com/systems-manager/parameters) 中创建 SSM 参数以存储该 Exporter 的指标查询。软件包可以接受多个指标参数。每个参数必须具有有效的 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. 通过将“Additional Arguments（其他实际参数）”替换为以下内容来更新您在第一步中创建的 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 Cluster Exporter](https://prometheus.io/docs/instrumenting/exporters/#third-party-exporters) 中检索工作负载特定的高可用性 (HA) 集群指标，以供 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) 来打包、安装和配置 AWS 提供的 Prometheus HA Cluster Exporter 软件包（独立于 Application Insights），请完成以下步骤。

**使用 Prometheus HA Cluster Exporter SSM 软件包的先决条件**
+ 2.3.1550.0 版或更高版本的 SSM Agent 已安装
+ 适用于 Pacemaker、Corosync、SBD 和 DRBD 的 HA 集群
+ Linux 操作系统（SUSE Linux、RedHat Linux）

**安装和配置 `AWSObservabilityExporter-HAClusterExporterInstallAndConfigure` 软件包**  
`AWSObservabilityExporter-HAClusterExporterInstallAndConfigure` 软件包是一个 SSM Distributor 软件包，您可以使用它来安装和配置 Prometheus HA Cluster Exporter。当 Prometheus HANA Database Exporter 发送集群指标时，就可以配置 CloudWatch 代理来检索 CloudWatch 服务的指标。

1. 在 [SSM Parameter Store](https://console.aws.amazon.com/systems-manager/parameters) 中创建 SSM 参数，以 JSON 格式存储该 Exporter 的配置。以下为示例参数值。

   ```
   {\"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}
   ```

   有关该 Exporter 配置的更多信息，请参阅 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. 通过将“Additional Arguments（其他实际参数）”替换为以下内容来更新您在第一步中创建的 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)中检索特定于工作负载的 SAP NetWeaver 指标，以便 Application Insights 为 SAP NetWeaver 分布式和高可用性部署配置和监控告警。

要使用 [AWS Systems Manager Distributor](https://docs.aws.amazon.com/systems-manager/latest/userguide/distributor.html) 来打包、安装和配置 SAP 主机导出器软件包（独立于 Application Insights），请完成以下步骤。

**使用 Prometheus SAP 主机导出器 SSM 软件包的先决条件**
+ 2.3.1550.0 版或更高版本的 SSM Agent 已安装
+ 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 Parameter Store](https://console.aws.amazon.com/systems-manager/parameters) 中创建 SSM 参数，以 JSON 格式存储该 Exporter 的配置。以下为示例参数值。

   ```
   {\"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. 通过将“Additional Arguments（其他实际参数）”替换为以下内容来更新您在第一步中创建的 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)中检索工作负载特定的 SQL Server 指标，以供 Application Insights 监控关键指标。

要使用 [AWS Systems Manager Distributor](https://docs.aws.amazon.com/systems-manager/latest/userguide/distributor.html) 来打包、安装和配置 SQL 导出器软件包（独立于 Application Insights），请完成以下步骤。

**使用 Prometheus SQL 导出器 SSM 软件包的先决条件**
+ 2.3.1550.0 版或更高版本的 SSM Agent 已安装
+ 在启用了 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 导出器发送 Java 指标时，可以配置 CloudWatch 代理来检索 CloudWatch 服务的指标。

1. 根据您的偏好，准备 SQL 导出器 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 导出器 YAML 配置文件复制到 [SSM Parameter Store](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 实例，然后选择运行。

# CloudWatch Application Insights 使用的 AWS 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 文档。


| 文档名称 | 说明 | 运行时间表 | 
| --- | --- | --- | 
|  `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 实例收集内部系统级指标和日志。