gpt4 book ai didi

amazon-web-services - 使用 Terraform 的 CloudWatch 指标警报

转载 作者:行者123 更新时间:2023-12-02 00:14:01 24 4
gpt4 key购买 nike

当出于某种原因尝试使用 Terraform 设置一些 CloudWatch 警报时,它找不到指标并且警报仍然停留在数据不足的情况下。 Terraform 不会输出任何错误,如果我在 AWS 中手动搜索,我可以找到指标。我在这里缺少什么?

示例一个指向目标组的简单健康主机警报点:

#healthy host alarm
resource "aws_cloudwatch_metric_alarm" "health" {
alarm_name = "${var.tag_app}_healthy_host"
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
metric_name = "HealthyHostCount"
namespace = "AWS/ApplicationELB"
period = "60"
statistic = "Maximum"
threshold = "1"
alarm_description = "Healthy host count for EC2 machine"
alarm_actions = ["${data.aws_sns_topic.blabla.arn}"]
ok_actions = ["${data.aws_sns_topic.blabla.arn}"]

dimensions = {
TargetGroup = "${aws_lb_target_group.alb_target.arn_suffix}"
}
}

当我选择另一个资源(EC2、RDS)和另一个指标时,我收到指向正确指标的 CloudWatch 警报,它不会停留在数据不足的状态。

最佳答案

HealthyHostCount metric仅在 TargetGroup, LoadBalancer 维度或 TargetGroup, AvailabilityZone, LoadBalancer 下可用,因此您至少还需要添加 LoadBalancer 维度访问此指标。

因此您的 Terraform 代码应该改为:

#healthy host alarm
resource "aws_cloudwatch_metric_alarm" "health" {
alarm_name = "${var.tag_app}_healthy_host"
comparison_operator = "LessThanThreshold"
evaluation_periods = "1"
metric_name = "HealthyHostCount"
namespace = "AWS/ApplicationELB"
period = "60"
statistic = "Maximum"
threshold = "1"
alarm_description = "Healthy host count for EC2 machine"
alarm_actions = ["${data.aws_sns_topic.blabla.arn}"]
ok_actions = ["${data.aws_sns_topic.blabla.arn}"]

dimensions = {
LoadBalancer = "${aws_lb.example.arn_suffix}"
TargetGroup = "${aws_lb_target_group.alb_target.arn_suffix}"
}
}

关于amazon-web-services - 使用 Terraform 的 CloudWatch 指标警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57593432/

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