4

有了这个,我们可以为我们的自定义指标配置维度。

{
   "metrics":{
      "append_dimensions":{
         "AutoScalingGroupName":"${!aws:AutoScalingGroupName}",
         "ImageId":"${!aws:ImageId}",
         "InstanceId":"${!aws:InstanceId}",
         "InstanceType":"${!aws:InstanceType}"
      },
      "metrics_collected":{
         "mem":{
            "measurement":[
               "mem_used_percent"
            ]
         },
         "swap":{
            "measurement":[
               "swap_used_percent"
            ]
         }
      }
   }
}

这给出了类似的东西: 在此处输入图像描述

现在我尝试为维度自动缩放组创建一个警报:

  MemoryAlarmHigh:
   Type: AWS::CloudWatch::Alarm
   Properties:
     EvaluationPeriods: '1'
     Statistic: Average
     Threshold: '70'
     AlarmDescription: Go in Alarm is memory is higher than 70% for 60 seconds
     Period: '60'
     AlarmActions:
     - Ref: ScaleUpPolicy
     Namespace: CWAgent
     Dimensions:
     - Name: AutoScalingGroupName
       Value: !Ref ASG
     ComparisonOperator: GreaterThanThreshold
     MetricName: xxx

这不起作用。我得到的数据不足。现在当我使用

            {
              "metrics": {
                "append_dimensions": {
                  "AutoScalingGroupName": "${!aws:AutoScalingGroupName}"
                },
                "metrics_collected": {
                  "mem": {
                    "measurement": [
                      "mem_used_percent"
                    ]
                  }
                }
              }
            }

我得到: 在此处输入图像描述

警报现在起作用了。但我想使用多个维度,但单独使用它们(如在 EC2 命名空间中),以便我可以使用我的警报。

我怎样才能做到这一点?

4

1 回答 1

4

尝试设置aggregation_dimensions

像这样:

{
   "metrics":{
      "append_dimensions":{
         "AutoScalingGroupName":"${!aws:AutoScalingGroupName}",
         "ImageId":"${!aws:ImageId}",
         "InstanceId":"${!aws:InstanceId}",
         "InstanceType":"${!aws:InstanceType}"
      },
      "aggregation_dimensions" : [["AutoScalingGroupName"]],
      "metrics_collected":{
         "mem":{
            "measurement":[
               "mem_used_percent"
            ]
         },
         "swap":{
            "measurement":[
               "swap_used_percent"
            ]
         }
      }
   }
}

https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html#CloudWatch-Agent-Configuration-File-Metricssection

于 2019-06-05T21:55:44.617 回答