0

以下 terraform 资源创建 AWS cloudwatch 警报,但仍处于“数据不足”状态。我相信这是由于我使用的一些维度名称(DevicePath、fstype)可能不正确。我知道名称 MountPath 和 InstanceID 是正确的,但无法验证其他两个(DevicePath、fstype)。AWS 将这些维度分别称为路径、设备、fstype 和主机,但是,找不到 terraform 所称的参考。

resource "aws_cloudwatch_metric_alarm" "Low_Disk_Space_For_root_drive" {
  alarm_name                = "Low_Disk_Space_For_root_drive"
  comparison_operator       = "GreaterThanOrEqualToThreshold"
  evaluation_periods        = "2"
  metric_name               = "disk_used_percent"
  namespace                 = "CWAgent"

  dimensions {
    MountPath = "/"
    DevicePath = "/dev/xvda2"
    fstype = "xfs"
    InstanceId = "i-xxxxxxxxxxxxxxxxx"

  }

  period                    = "60"
  statistics                = "Maximum"
  threshold                 = "90" 
  alarm_description         = "Disk usage for / is high"
  insufficient_data_actions = []
  actions_enabled           = true
  alarm_actions             = ["arn:aws:sns:xxxxxx"]
  ok_actions                = ["arn:aws:sns:xxxxxx"]
}
4

3 回答 3

1

将 TreatMissingData 添加到资源主体

resource "aws_cloudwatch_metric_alarm" "Low_Disk_Space_For_root_drive"{
  alarm_name                = "Low_Disk_Space_For_root_drive"
 comparison_operator       = "GreaterThanOrEqualToThreshold"
 evaluation_periods        = "2"
 metric_name               = "disk_used_percent"
 namespace                 = "CWAgent"

 dimensions {
   MountPath = "/"
   DevicePath = "/dev/xvda2"
   fstype = "xfs"
   InstanceId = "i-xxxxxxxxxxxxxxxxx"

  }

  period                    = "60"
  statistics                = "Maximum"
  threshold                 = "90" 
  alarm_description         = "Disk usage for / is high"
  insufficient_data_actions = []
  **TreatMissingData = "notBreaching"**
  actions_enabled           = true
  alarm_actions             = ["arn:aws:sns:xxxxxx"]
  ok_actions                = ["arn:aws:sns:xxxxxx"]
}
于 2019-11-15T15:00:58.133 回答
1

为了完成这项工作,您需要

  • 更改MountPathpath
  • 删除DevicePath并改为添加device
  • 添加ImageIDInstanceType

查看dimensions下面的更新字段

注意 - 用您自己的值替换这些值。您应该能够从CWAgentAWS 控制台上的 Cloudwatch Metrics 部分看到它们)

resource "aws_cloudwatch_metric_alarm" "Low_Disk_Space_For_root_drive" {
  alarm_name                = "Low_Disk_Space_For_root_drive"
  comparison_operator       = "GreaterThanOrEqualToThreshold"
  evaluation_periods        = "2"
  metric_name               = "disk_used_percent"
  namespace                 = "CWAgent"

  dimensions {
      InstanceId    = "i-xxxxxxxxxxxxxxxxx"
      ImageId       = "your-image-id"
      InstanceType  = "your-instance-type"
      path          = "/"
      device        = "your-device"
      fstype        = "xfs"

  }

  period                    = "60"
  statistics                = "Maximum"
  threshold                 = "90" 
  alarm_description         = "Disk usage for / is high"
  insufficient_data_actions = []
  actions_enabled           = true
  alarm_actions             = ["arn:aws:sns:xxxxxx"]
  ok_actions                = ["arn:aws:sns:xxxxxx"]
}
于 2020-03-07T19:57:29.567 回答
0

主要原因是因为你把什么作为设备

将“/dev/xvda2”更改为 AWS 的确切设备,例如 (“nvme1n1”)。您可以在 CloudWatch 指标中进行检查。

于 2021-06-17T17:40:33.690 回答