【问题标题】:getting terraform reference for AWS CloudWatch alarm获取 AWS CloudWatch 警报的 terraform 参考
【发布时间】:2020-03-11 02:06:16
【问题描述】:

以下 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"]
}

【问题讨论】:

    标签: terraform amazon-cloudwatch-metrics cloudwatch-alarms


    【解决方案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"]
    }
    

    【讨论】:

      【解决方案2】:

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

      • MountPath 更改为path
      • 删除DevicePath,改为添加device
      • 添加ImageIDInstanceType

      查看下方更新后的dimensions 字段

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

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

      【讨论】:

        【解决方案3】:

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

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

        【讨论】:

          猜你喜欢
          • 2021-05-25
          • 2019-07-14
          • 2021-10-30
          • 1970-01-01
          • 2019-08-01
          • 2022-11-30
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多