

# 教程：为 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 系统（SID）ASE HA 环境。如果附加了多个 ASE HA SID，则只会为检测到的第一个 SID 设置监控。

## 支持的操作系统
<a name="appinsights-tutorial-sap-ase-supported-os"></a>

CloudWatch Application Insights for SAP ASE 在以下操作系统中支持 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>

CloudWatch Application Insights for SAP ASE 具有以下功能：
+ 自动检测 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 实例角色。
  + 要启用 Systems Manager，您必须附加 `AmazonSSMManagedInstanceCore` 角色。有关更多信息，请参阅 [AWS Systems Manager 基于身份的策略示例](https://docs.aws.amazon.com/systems-manager/latest/userguide/auth-and-access-control-iam-identity-based-access-control.html)。
  + 要启用通过 CloudWatch 发出实例指标和日志，您必须附加 `CloudWatchAgentServerPolicy`。有关更多信息，请参阅[创建 IAM 角色和用户以用于 Amazon CloudWatch 代理](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/create-iam-roles-for-cloudwatch-agent.html)。
  + 要读取存储在 AWS Secrets Manager 中的密码，您必须将以下 IAM 内联策略附加到 Amazon EC2 实例角色。有关内联策略的更多信息，请参阅 *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 权限** – 对于非管理员用户：
  +  您必须创建允许 Application Insights 创建服务相关角色的 AWS Identity and Access Management（IAM）policy，并将其附加到您的用户身份。有关附加策略的步骤，请参阅 [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 HANA 数据库的监控

1. 打开 [CloudWatch 控制台](https://console.aws.amazon.com/cloudwatch)。

1. 从左侧导航窗格中，选择 **Insights** 下的 **Application Insights**。

1. **Application Insights** 页面会显示使用 Application Insights 监控的应用程序列表以及每个应用程序的监控状态。在右上角，选择 **Add an application**（添加应用程序）。

1. 在**指定应用程序详细信息**页面上，从**资源组**下的下拉列表中选择包含 SAP ASE 数据库资源的 AWS 资源组。如果尚未为应用程序创建资源组，则可以在 **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. 在 **Monitor CloudWatch Events**（监控 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. 在 **Integrate with AWS Systems Manager OpsCenter**（与 OpsCenter 集成）下，选中 **Generate AWS Systems Manager OpsCenter OpsItems for remedial actions**（生成 OpsCenter OpsItems 以采取修复措施）旁边的复选框，以在检测到所选应用程序的问题时查看问题及接收通知。要跟踪为解析与 AWS 资源相关的操作工作项 (OpsItem) 而执行的操作，请提供 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 HANA 数据库的监控
<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`（告警）状态。要创建“`m`（最大为 `n`）”告警，则为第一个数据点指定的值应小于为第二个数据点指定的值。有关评估告警的更多信息，请参阅[评估告警](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.md)。

1. 选择**下一步**。

1. 在**通知**下面，选择一个在警报处于 `ALARM`、`OK` 或 `INSUFFICIENT_DATA` 状态时通知的 SNS 主题。

1. 选择 **Update alarm**（更新告警）。

## 查看和排查 Application Insights 检测到的 SAP ASE 问题
<a name="appinsights-tutorial-sap-ase-troubleshooting-problems"></a>

本节可帮助您解决在 Application Insights 上针对 SAP ASE 配置监控时出现的常见问题。

**SAP ASE Backup 服务器错误**  
您可以通过检查动态创建的控制面板来识别错误消息。控制面板会显示 SAP ASE Backup 服务器中报告的错误消息。有关 SAP ASE Backup Server 日志的更多详细信息，请参阅 [SAP 文档“Backup Server 错误记录”](https://help.sap.com/docs/SAP_ASE/aa939a27edb34f019f71cc47b9c0fd9a/a7aeb8b1bc2b10149ccf99b95687a64c.html)。

**SAP ASE 长时间运行的事务**  
确定长时间运行的事务，并确认是否可以将其停止或运行时间是否有意设置的。有关更多详细信息，请参阅 [2180410 – How to display transaction log records for long running transactions? – SAP ASE](https://userapps.support.sap.com/sap/support/knowledge/en/2180410)。

**SAP ASE 用户连接**  
检查您的 SAP ASE 数据库的大小是否与您打算在数据库上运行的工作负载相匹配。有关更多详细信息，请参阅 SAP 文档中的 [Configuring User Connections](https://help.sap.com/docs/help/061ec8a5739842df9e505d8944fae8e2/9ea258fceaaa496eb80e17d3d5694ff6.html)。

**SAP ASE 磁盘空间**  
您可以检查动态创建的控制面板，找出导致问题的数据库层。控制面板会显示相关指标和日志文件片段。请务必了解磁盘扩容的原因，并在适用情况下增加物理磁盘大小、分配的磁盘空间或同时增加两者。有关更多详细信息，请参阅 SAP 文档中的 [disk resize](https://help.sap.com/docs/SAP_ASE/e0d4539d39c34f52ae9ef822c2060077/ab22db00bc2b1014ad3ce047bbf117d7.html)。

## 利用 Application Insights 排查 SAP ASE 的问题
<a name="appinsights-tutorial-sap-ase-troubleshooting-health-dashboard"></a>

本节提供了帮助您解决 Application Insights 控制面板返回的常见错误的步骤。


| 错误 | 返回的错误 | 根本原因 | 解决方案 | 
| --- | --- | --- | --- | 
|  无法添加超过 60 个监控指标。  |  `Component cannot have more than 60 monitored metric`  |  当前的指标限制为每个组件 60 个受监控指标。  |  删除不必要的指标以符合限制。  | 
|  添加过程之后未显示 SAP 指标或警告  |  `run` 上的 `AWS-ConfigureAWSPackage` 命令在 AWS Systems Manager 中失败了。输出显示错误：`CT-LIBRARY error:``ct_connect(): protocol specific layer: external error: The attempt to connect to the server failed`  |  用户名和密码可能不正确。  |  验证用户名和密码是否有效，然后重新运行添加过程。  | 