寻找了一段时间,但没有成功。
我正在尝试使用 terraform 设置磁盘使用百分比的 CW 警报,但我获得的数据不足。
我已经设置了这样的警报:
resource "aws_cloudwatch_metric_alarm" "ec2_disk_space" {
for_each = local.disk_space_path
alarm_name = "ec2_disk_space_${each.key}"
comparison_operator = "GreaterThanOrEqualToThreshold"
metric_name = "disk_used_percent"
namespace = "CloudWatchCustomMetrics"
period = "600"
evaluation_periods = "1"
statistic = "Average"
threshold = "90"
alarm_description = "The disk space on path ${each.key} average percentage is over 90% for the last 10 minutes"
actions_enabled = "true"
treat_missing_data = "ignore"
alarm_actions = [aws_sns_topic.aws-notification-terraform.arn]
ok_actions = [aws_sns_topic.aws-notification-terraform.arn]
dimensions = {
InstanceId = var.instance_ids
path = each.key
}
}
其中“路径”经过我收集的有关使用 CWAgent 的指标的几条路径。 instanceID 是我的实例 ID 的变量。
我收到在 CloudWatch 警报仪表板中创建的警报,但它始终显示数据不足。 我尝试为其提供更多信息,例如“InstanceType”和“ami”。同样的错误仍然存在。
好吧,事实证明, 我只需要提供完整的维度列表以供其识别。我只提供了其中的一些。 类似的东西:
resource "aws_cloudwatch_metric_alarm" "ec2_disk_space" {
alarm_name = "ec2_disk_space"
comparison_operator = "GreaterThanOrEqualToThreshold"
metric_name = "disk_used_percent"
namespace = "CloudWatchCustomMetrics"
period = "600"
evaluation_periods = "1"
statistic = "Average"
threshold = "90"
alarm_description = "The disk space average precetage is over 90% for the last 10 minutes"
actions_enabled = "true"
treat_missing_data = "ignore"
alarm_actions = [aws_sns_topic.aws-notification-terraform.arn]
ok_actions = [aws_sns_topic.aws-notification-terraform.arn]
dimensions = {
InstanceId = var.instance_ids
ImageId = "ami-"
InstanceType = "r5.large"
device = "nvme"
fstype = "ext4"
path = "/"
}
}