gpt4 book ai didi

python - 具有异常检测功能的 CloudWatch 警报的 AWS-CDK 示例

转载 作者:行者123 更新时间:2023-12-05 02:08:47 32 4
gpt4 key购买 nike

有人可以提供一个基于 Python3 中使用 AWS CDK 构建的指标的异常检测的 AWS Cloudwatch 警报的通用示例吗?

我试过映射 aws cloudformation example of it aws_cdk.aws_cloudwatch.Alarmaws_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"
)

这部分基于 Cloudwatch 异常警报的 AWS Docs CloudFormation 示例 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cw-alarm.html

关于python - 具有异常检测功能的 CloudWatch 警报的 AWS-CDK 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60548344/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com