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

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

使用 CloudFormation 模板创建和配置 CloudWatch 应用洞察监控

您可以将应用程序见解监控(包括关键指标和遥测)添加到应用程序、数据库和 Web 服务器,直接从Amazon CloudFormationTemplates。

此部分提供示例Amazon CloudFormation模板,以帮助您创建和配置应用程序见解监视。

要查看 “应用程序见解” 资源和属性引用,请在Amazon CloudFormation用户指南,请参阅ApplicationInsights 资源类型参考

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

要应用以下模板,必须创建Amazon资源和一个或多个资源组,用于创建应用程序见解应用程序以监视这些资源。有关更多信息,请参阅 。开始使用Amazon资源组

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

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

以下模板部分将默认监视配置应用于应用程序见解应用程序。有关更多信息,请参阅 。CreateApplication命令详细信息Amazon CloudWatch Application Insights API 参考

何时AutoConfigurationEnabled设置为true,则应用程序的所有组件都配置为DEFAULT应用程序层。有关这些设置和层的更多信息,请参阅DescribeComponentConfigurationRecommendationUpdateComponentConfiguration中的Amazon CloudWatch Application Insights API 参考

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

以下模板执行以下操作:

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

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

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

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

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

JSON 格式的模板

{ "Type": "AWS::ApplicationInsights::Application", "Properties": { "ResourceGroupName": "my_resource_group", "CWEMonitorEnabled": true, "OpsCenterEnabled": true, "OpsItemSNSTopicArn": "arn:aws-cn:sns:cn-north-1:123456789012:my_topic", "AutoConfigurationEnabled": true, "Tags": [ { "Key": "key1", "Value": "value1" }, { "Key": "key2", "Value": "" } ], "CustomComponents": [ { "ComponentName": "test_component_1", "ResourceList": [ "arn:aws-cn:ec2:cn-north-1:123456789012:instance/i-abcd1234efgh5678i" ] }, { "ComponentName": "test_component_2", "ResourceList": [ "arn:aws-cn:ec2:cn-north-1:123456789012:instance/i-abcd1234efgh5678i", "arn:aws-cn:ec2:cn-north-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-cn:sns:cn-north-1:123456789012:my_topic AutoConfigurationEnabled: true Tags: - Key: key1 Value: value1 - Key: key2 Value: '' CustomComponents: - ComponentName: test_component_1 ResourceList: - arn:aws-cn:ec2:cn-north-1:123456789012:instance/i-abcd1234efgh5678i - ComponentName: test_component_2 ResourceList: - arn:aws-cn:ec2:cn-north-1:123456789012:instance/i-abcd1234efgh5678i - arn:aws-cn:ec2:cn-north-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中的Amazon CloudWatch Application Insights API 参考

  • 组件my_componentSELECTComponentConfigurationModeCUSTOM,这将导致使用在CustomComponentConfiguration。有关更多信息,请参阅 。UpdateComponentConfiguration中的Amazon CloudWatch Application Insights API 参考

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中的Amazon CloudWatch Application Insights API 参考

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

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中的Amazon CloudWatch Application Insights API 参考

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

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

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

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

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