如何为自定义 cloudwatch 指标使用多个单独的维度?
How to use multiple separate dimensions for custom cloudwatch metrics?
有了这个,我们可以为自定义指标配置维度。
{
"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 命名空间中)所以我可以使用我的警报。
我该怎么做?
尝试设置 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"
]
}
}
}
}
有了这个,我们可以为自定义指标配置维度。
{
"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 命名空间中)所以我可以使用我的警报。
我该怎么做?
尝试设置 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"
]
}
}
}
}