2024-06-06 17:20:31 发布
网友
有人能提供一个基于Python3中使用AWS CDK构建的度量异常检测的AWS Cloudwatch警报的通用示例吗
我尝试过将aws cloudformation example of it映射到aws_cdk.aws_cloudwatch.Alarm和aws_cdk.aws_cloudwatch.CfnAlarm,但几乎没有运气
aws_cdk.aws_cloudwatch.Alarm
aws_cdk.aws_cloudwatch.CfnAlarm
最终设法使异常检测与CfnAlarm一起工作
from aws_cdk import ( aws_sns as sns, aws_cloudwatch as cw, core ) anomaly_detector = cw.CfnAnomalyDetector( self, "AnomalyDetector", metric_name="my_metric", namespace="my_namespace", stat="Sum" ) slack_topic = sns.Topic(self, "AnomalySns", display_name="anomaly-sns", topic_name="anomaly-sns" ) anomaly_cfnalarm = cw.CfnAlarm(self, "AnomalyAlarm", actions_enabled=True, alarm_actions=[slack_topic.topic_arn], alarm_description="<..>", alarm_name="AnomalyAlarm", comparison_operator="LessThanLowerOrGreaterThanUpperThreshold", datapoints_to_alarm=1, evaluation_periods=1, insufficient_data_actions=[slack_topic.topic_arn], metrics=[ cw.CfnAlarm.MetricDataQueryProperty( expression="ANOMALY_DETECTION_BAND(m1, 2)", id="ad1" ), cw.CfnAlarm.MetricDataQueryProperty( id="m1", metric_stat=cw.CfnAlarm.MetricStatProperty( metric=cw.CfnAlarm.MetricProperty( metric_name=anomaly_detector.metric_name, namespace=anomaly_detector.namespace ), period=core.Duration.minutes(5).to_seconds(), stat="Sum" ) ) ], ok_actions=[slack_topic.topic_arn], threshold_metric_id="ad1", treat_missing_data="breaching" )
这部分基于AWS Docs CloudFormation的Cloudwatch异常警报https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html示例
当前的CDK(v1.27.0)中没有用于异常检测器的高级构造函数
请直接使用低级类CfnAnomalyDetector
在CloudFormation doc中有一个example usage of AbnormalDetector with Alarm。使用CDK低级Cfn*类创建相应的CFN配置
Cfn*
最终设法使异常检测与CfnAlarm一起工作
这部分基于AWS Docs CloudFormation的Cloudwatch异常警报https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html示例
当前的CDK(v1.27.0)中没有用于异常检测器的高级构造函数
请直接使用低级类CfnAnomalyDetector
在CloudFormation doc中有一个example usage of AbnormalDetector with Alarm。使用CDK低级
Cfn*
类创建相应的CFN配置相关问题 更多 >
编程相关推荐