gpt4 book ai didi

aws-cloudformation - 使用对流层将 CloudWatch 警报与 MetricFilter 关联

转载 作者:行者123 更新时间:2023-12-03 07:27:27 25 4
gpt4 key购买 nike

我正在使用 Troposphere 脚本来配置 CloudWatch 指标过滤器和警报。在 CloudWatch 中,可以手动创建一个警报,该警报基于指标过滤器从日志中聚合的数据发出,但我想在对流层脚本中链接过滤器和警报,以在可能的情况下节省体力劳动。

这是我的脚本内容(注意:下面定义和引用了一些其他资源,为简洁起见,省略了这些资源):

t.add_resource(logs.MetricFilter(
"PlanReconciliationPlansStepMetricFilter",
FilterPattern="INFO generatePlanReconciliationStepKnownToMorningstarInPlans",
LogGroupName=Ref("logGroupName"),
MetricTransformations=[logs.MetricTransformation(
"planReconciliationPlansStepMetricTransformation",
MetricNamespace=Ref("metricNamespace"),
MetricName=Join("", [Ref("springProfile"), "-", "plan-reconciliation-plans-step"]),
MetricValue="1")]
))

alarmPlans = t.add_resource(
Alarm(
"PlanReconciliationPlansAlarm",
AlarmDescription="Alarm if plan reconciliation metric filter is exceeded",
Namespace="AWS/Logs",
MetricName=Join("", [Ref("springProfile"), "-", "plan-reconciliation-plans-step"]),
Statistic="Sum",
Period="60",
EvaluationPeriods="1",
Threshold="0",
ComparisonOperator="GreaterThanThreshold",
AlarmActions=[Ref(alarmTopic), ]
)
)

这会生成一个定义良好的 CloudFormation 模板,但是,当我执行更改集并观察创建的指标过滤器时,我发现我想要链接到过滤器的警报并未自动设置,我需要手动创建它:

enter image description here

我的想法是,如果 MetricTransformation 和 Alarm 共享相同的 MetricName 属性,则希望警报已链接到指标过滤器,但情况似乎并非如此。看着documentation for metric filters ,似乎只有三个属性可以使用(LogGroupName、FilterPattern 和 MetricTransformations 列表)。有没有办法将警报与对流层中的指标过滤器链接起来?

最佳答案

基于评论。

问题在于 Ref("metricNamespace") 与“AWS/Logs”不同。随后,MetricFilter 和 Alarm 使用不同的命名空间

将命名空间设置为与BATCH-ERRORS相同的值解决了问题

关于aws-cloudformation - 使用对流层将 CloudWatch 警报与 MetricFilter 关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62209984/

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