使用 CloudWatch Application Insights 模板创建和配置CloudFormation监控 - Amazon CloudWatch
AWS 文档中描述的 AWS 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅中国的 AWS 服务入门

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

使用 CloudWatch Application Insights 模板创建和配置CloudFormation监控

您可以直接从 Application Insights 模板将AWS CloudFormation监控(包括关键指标和遥测数据)添加到您的应用程序、数据库和 Web 服务器。

本节提供 JSON 和 YAML 格式的示例AWS CloudFormation模板,以帮助您创建和配置Application Insights监控。

要查看 Application Insights 用户指南 AWS CloudFormation中的资源和属性参考,请参阅 ApplicationInsights 资源类型参考

为整个Application Insights堆栈创建AWS CloudFormation应用程序

要应用以下模板,您必须创建 AWS 资源以及一个或多个资源组,以便从这些资源中创建Application Insights应用程序来监控这些资源。有关更多信息,请参阅 AWS 资源组https://docs.amazonaws.cn/ARG/latest/userguide/gettingstarted.html入门。

以下模板的前两个部分指定资源和资源组。模板的最后一部分为资源组创建Application Insights应用程序,但不配置应用程序或应用监控。有关更多信息,请参阅 CreateApplication API 参考中的Amazon CloudWatch Application Insights命令详细信息。

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应用程序。有关更多信息,请参阅 CreateApplication API 参考中的Amazon CloudWatch Application Insights命令详细信息。

AutoConfigurationEnabled 当 设置为 时true,将使用应用程序层的建议监控设置来配置DEFAULT应用程序的所有组件。有关这些设置和层的更多信息,请参阅 DescribeComponentConfigurationRecommendation API 参考UpdateComponentConfiguration中的 Amazon CloudWatch Application Insights 和 。

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应用程序

以下模板执行以下操作:

  • 创建Application Insights启用了CloudWatch Events通知的应用程序OpsCenter。有关更多信息,请参阅 CreateApplication API 参考中的Amazon CloudWatch Application Insights命令详细信息。

  • 使用两个标签标记应用程序,其中一个没有标签值。有关更多信息,请参阅 TagResource API 参考Amazon CloudWatch Application Insights中的 。

  • 创建两个自定义实例组组件。有关更多信息,请参阅 CreateComponent API 参考Amazon CloudWatch Application Insights中的 。

  • 创建两个日志模式集。有关更多信息,请参阅 CreateLogPattern API 参考Amazon CloudWatch Application Insights中的 。

  • AutoConfigurationEnabled 设置为 true,这会为应用程序的所有组件配置DEFAULT针对该层的建议监控设置。有关更多信息,请参阅 DescribeComponentConfigurationRecommendation API 参考Amazon CloudWatch Application Insights中的 。

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

使用Application Insights模式组件配置创建CUSTOM应用程序

以下模板执行以下操作:

  • 创建 Application Insights 应用程序。有关更多信息,请参阅 CreateApplication API 参考Amazon CloudWatch Application Insights中的 。

  • 组件my_componentComponentConfigurationMode 设置为 CUSTOM,这会导致此组件使用 中指定的配置进行配置CustomComponentConfiguration。 有关更多信息,请参阅 UpdateComponentConfiguration API 参考Amazon CloudWatch Application Insights中的 。

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" }, ... ], "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 ... WindowsEvents: - LogGroupName: my_windows_event_log_group_2 EventName: Application EventLevels: - ERROR - WARNING ... Encoding: utf-8 PatternSet: my_pattern_set_4 ...

使用Application Insights模式组件配置创建DEFAULT应用程序

以下模板执行以下操作:

  • 创建 Application Insights 应用程序。有关更多信息,请参阅 CreateApplication API 参考Amazon CloudWatch Application Insights中的 。

  • 组件my_componentComponentConfigurationMode 设置为 DEFAULT 并将 Tier 设置为 SQL_SERVER,这会导致此组件配置了 为Application Insights层SQL_Server推荐的配置设置。有关更多信息,请参阅 DescribeComponentConfiguration API 参考 UpdateComponentConfiguration 中的 Amazon CloudWatch Application Insights 和 。

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

使用Application Insights模式组件配置创建DEFAULT_WITH_OVERWRITE应用程序

以下模板执行以下操作:

  • 创建 Application Insights 应用程序。有关更多信息,请参阅 CreateApplication API 参考Amazon CloudWatch Application Insights中的 。

  • 组件my_componentComponentConfigurationMode 设置为 DEFAULT_WITH_OVERWRITE ,并将 tier 设置为 DOT_NET_CORE,这会导致此组件配置了 为Application Insights层DOT_NET_CORE推荐的配置设置。在 中指定了覆盖的配置设置DefaultOverwriteComponentConfiguration

    • 在组件级别AlarmMetrics设置将被覆盖。

    • 在子组件级别,对于 EC2_Instance 类型子组件Logs,设置将被覆盖。

    有关更多信息,请参阅 UpdateComponentConfiguration API 参考Amazon CloudWatch Application Insights中的 。

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