Terraform 获取AWS CloudWatch警报的地形参考

Terraform 获取AWS CloudWatch警报的地形参考,terraform,amazon-cloudwatch-metrics,cloudwatch-alarms,Terraform,Amazon Cloudwatch Metrics,Cloudwatch Alarms,以下地形资源创建AWS cloudwatch警报,但仍处于“数据不足”状态。我相信这是因为我使用的一些维度名称(DevicePath、fstype)可能不正确。我知道名称MountPath和InstanceID是正确的,但无法验证其他两个(DevicePath、fstype)。AWS分别将这些维度称为路径、设备、fstype和主机,但是,无法找到terraform所称的参考 resource "aws_cloudwatch_metric_alarm" "Low_Disk_Space_For_ro

以下地形资源创建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"]
}

将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"]
}

为了使这项工作,你需要

  • MountPath
    更改为
    path
  • 删除
    DevicePath
    ,而是添加
    device
  • 添加
    ImageID
    InstanceType
查看下面更新的
维度
字段

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


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

将“/dev/xvda2”更改为类似(“nvme1n1”)的确切设备。您可以在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"]
}