Cloudformation ELB Cloudwatch 警报数据不足

Cloudformation ELB Cloudwatch 警报数据不足

我使用 cloudformation 为我的服务设置了一堆 cloudwatch 警报。除 ELB 警报外,我的所有警报都有效。它们总是显示数据不足。我可以进入控制台并手动设置警报,但我希望能够使用 cloudformation 模板来创建所有内容。我的警报 json 中一定有错误。以下是其中之一:

"ELBHighLatencyAlarm": {
    "Type": "AWS::CloudWatch::Alarm",
    "Properties": {
        "Namespace": "AWS/ELB",
        "AlarmName": { "Fn::Join" : ["", [ { "Ref" : "AWS::StackName"}, "-ELB-ELBHighLatencyAlarm"]]},
        "AlarmDescription":  { "Fn::Join" : ["", [ { "Ref" : "AWS::StackName"}, "-ELB-ELBHighLatencyAlarm"]]},
        "ComparisonOperator": "GreaterThanThreshold",
        "Threshold": "0.5",
        "EvaluationPeriods": "1",
        "Period": "300",
        "MetricName": "Latency",
        "Statistic": "Average",
        "OKActions": [],
        "AlarmActions": [ { "Ref": "PagerDutySNSTopicArn" } ],
        "InsufficientDataActions": [ { "Ref": "PagerDutySNSTopicArn" } ],
        "Dimensions": [ {
            "Name": "ElasticLoadBalancer",
            "Value": { "Ref": "WebServerLoadBalancer" }
        }]
    }
}

你觉得它有什么问题吗?

答案1

您的"Dimensions"部分未使用正确的"Name"值。如果您替换:

 "Dimensions": [ {
            "Name": "ElasticLoadBalancer",
            "Value": { "Ref": "WebServerLoadBalancer" }
        }]

 "Dimensions": [ {
            "Name": "LoadBalancerName",
            "Value": { "Ref": "WebServerLoadBalancer" }
        }]

你会发现你的闹钟会起作用。

答案2

我可以证实 Dojo 上面所说的话。尽管维度块描述中的措辞看起来好像它不是必需的,并且字符串/值是任意的,但对于您要为其创建警报的每种服务类型,都有一个特定的名称列表。此列表将服务类型映射到维度块中允许的值,从而使您的警报正常工作。

在我看来,dimensions 块是一种过滤事件的方式。因此,如果您想要查看集群的 CPUUtilization,则需要提供 ClusterName。如果您想要查看集群的特定服务,则需要向 Dimensions 块提供 2 个条目。ClusterName 和 ServiceName。

http://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/ecs-metricscollected.html

以下两个示例之间的唯一区别是 Dimensions.Name 字段。

例如不是工作

"CPUUtilizationScaleInAlarm": {
  "Type": "AWS::CloudWatch::Alarm",
  "Properties": {
    "ActionsEnabled": true,
    "AlarmActions": [
      {
        "Ref": "ESCServiceScaleInPolicy"
      }
    ],
    "AlarmDescription": "Scale in in response to CPUUtilization being low",
    "AlarmName": "CPUUtilizationScaleIn",
    "ComparisonOperator": "LessThanOrEqualToThreshold",
    "Dimensions": [
      {
        "Name": "ECService",
        "Value": "MyAwesomeService"
    ],
    "EvaluationPeriods": 1,
    "MetricName": "CPUUtilization",
    "Namespace": "AWS/ECS",
    "Period": 60,
    "Statistic": "Average",
    "Threshold": 25,
    "Unit": "Percent"
  }
}

例如将要工作

"CPUUtilizationScaleInAlarm": {
  "Type": "AWS::CloudWatch::Alarm",
  "Properties": {
    "ActionsEnabled": true,
    "AlarmActions": [
      {
        "Ref": "ESCServiceScaleInPolicy"
      }
    ],
    "AlarmDescription": "Scale in in response to CPUUtilization being low",
    "AlarmName": "CPUUtilizationScaleIn",
    "ComparisonOperator": "LessThanOrEqualToThreshold",
    "Dimensions": [
      {
        "Name": "ServiceName",
        "Value": "MyAwesomeService"
    ],
    "EvaluationPeriods": 1,
    "MetricName": "CPUUtilization",
    "Namespace": "AWS/ECS",
    "Period": 60,
    "Statistic": "Average",
    "Threshold": 25,
    "Unit": "Percent"
  }
}

相关内容