我的 cloudwatch 缩小警报始终处于 INSUFFICENT_DATA 状态。 Cloudwatch 警报已附加到我的自动缩放组。在过去的三天里,我的缩小警报一直处于这种状态,所以它肯定已经完成初始化。
在我的警报中,它给出了原因
Unchecked: Initial alarm creation
这来自 aws 文档: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/AlarmThatSendsEmail.html
INSUFFICIENT_DATA—The alarm has just started, the metric is not available, or not enough data is available for the metric to determine the alarm state
这是我的 cloudformation 模板中的一个片段,它使 cloudwatch 发出警报。它采用对流层语法,但应该很容易阅读:
template.add_resource(Alarm(
"CPUUtilizationLowAlarm",
ActionsEnabled=True,
AlarmDescription="Scale down for average CPUUtilization <= 30%",
Namespace="AWS/EC2",
MetricName="CPUUtilization",
Statistic="Average",
Period="300",
EvaluationPeriods="3",
Threshold="30",
Unit="Percent",
ComparisonOperator="LessThanOrEqualToThreshold",
AlarmActions=[Ref("ScaleDownPolicy")],
Dimensions=[
MetricDimension(
Name="AutoscalingGroupName",
Value=Ref("AutoScalingGroup")
)
]
))
template.add_resource(ScalingPolicy(
"ScaleDownPolicy", #Simple reference value, nothing special
AdjustmentType="ChangeInCapacity", #Modify the asg capacity
AutoScalingGroupName=Ref("AutoScalingGroup"), #What asg to modify capacity
PolicyType="SimpleScaling", #Read about it here: https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scale-based-on-demand.html
Cooldown="1700", #How long to wait before checking status' again
ScalingAdjustment=Ref("DownscalingCount") #(Must be a negative number!!) How much to scale down
))
正如您所看到的,我正在根据 CPUUtilization <= 30% 进行缩减。据我所知,这是一个有效的指标。我已阅读此堆栈溢出答案,但它似乎不适用于这种情况: Amazon EC2 AutoScaling CPUUtilization Alarm- INSUFFICIENT DATA
我做了几乎完全相同的事情,但使用“步进缩放”而不是“简单缩放”,如上所述,但它实际上对我有用。以下是我的步数缩放警报(向上扩展)的 cloudformation 模板中的一个片段:
template.add_resource(Alarm(
"CPUUtilizationHighAlarm",
ActionsEnabled=True,
AlarmDescription="Scale up for average CPUUtilization >= 50%",
MetricName="CPUUtilization",
Namespace="AWS/EC2",
Statistic="Average",
Period="300",
EvaluationPeriods="1",
Threshold="50",
Unit="Percent",
ComparisonOperator="GreaterThanOrEqualToThreshold",
AlarmActions=[Ref("ScaleUpPolicy")],
Dimensions=[
MetricDimension(
Name="AutoScalingGroupName",
Value=Ref("AutoScalingGroup")
)
]
))
template.add_resource(ScalingPolicy(
"ScaleUpPolicy",
AdjustmentType="ChangeInCapacity",
AutoScalingGroupName=Ref("AutoScalingGroup"), #What group to attach this to
EstimatedInstanceWarmup="1700", #How long it will take before instance is ready for traffic
MetricAggregationType="Average", #Breach if average is above threshold
PolicyType="StepScaling", #Read above step scaling here: https://docs.aws.amazon.com/autoscaling/ec2/userguide/as-scale-based-on-demand.html
StepAdjustments=[
StepAdjustments(
MetricIntervalLowerBound="0", #From 50 (Defined in alarm as 50% CPU)
MetricIntervalUpperBound="20", #To 70%
ScalingAdjustment="1" #Scale up 1 instance
),
StepAdjustments(
MetricIntervalLowerBound="20", #from 70%
MetricIntervalUpperBound="40", #to 90%
ScalingAdjustment="2" #Scale up 2 instances
),
StepAdjustments(
MetricIntervalLowerBound="40", #From 90% or above (Defined in alarm)
ScalingAdjustment="3" #Scale up 2 instances
)
]
))
我不知道我在缩小警报中配置了什么错误。如果有人有任何建议或帮助,那就太好了。
最佳答案
我发现了问题...
错误在这里:
MetricDimension(
Name="AutoscalingGroupName",
Value=Ref("AutoScalingGroup")
)
名称
应该是AutoScalingGroupName
而不是AutoscalingGroupName
。它将尝试生成新维度,但无法从自动缩放组中正确拉出。所以它不会抛出错误,并且会正常运行,只是没有数据可供提取。因此将保持 INSUFFICENT_DATA
状态直到时间结束。
大写“S”...
关于amazon-web-services - AWS CloudWatch 警报,帮助解决错误 - 未选中 : Initial alarm creation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50242062/