多实例cpuutilization告警,数据不足

问题描述

我使用异常检测创建了一个 cpu 利用率警报,这显示一个具有预期 cpu 利用率(异常检测带)的图表,但警报显示“数据不足”并且没有用于 cpuutilization 的图形线。

aws cloudwatch describe-alarms 给出以下输出显示配置的指标(删除了帐户 ID)

{
    "MetricAlarms": [
        {
            "AlarmName": "ec2-cpu-anomaly-detection-2","AlarmArn": "arn:aws:cloudwatch:eu-west-2:xxxx:ec2-cpu-anomaly-detection-2","AlarmDescription": "EC2 cpu usage anomaly detection,acct","AlarmConfigurationUpdatedTimestamp": "2021-05-06T13:29:08.848Z","ActionsEnabled": true,"OKActions": [],"AlarmActions": [],"InsufficientDataActions": [],"StateValue": "INSUFFICIENT_DATA","StateReason": "Unchecked: Initial alarm creation","StateUpdatedTimestamp": "2021-05-06T13:29:08.848Z","Dimensions": [],"EvaluationPeriods": 2,"Comparisonoperator": "GreaterThanUpperThreshold","TreatMissingData": "missing","Metrics": [
                {
                    "Id": "m1","MetricStat": {
                        "Metric": {
                            "Namespace": "AWS/EC2","MetricName": "cpuutilization","Dimensions": []
                        },"Period": 60,"Stat": "Average","Unit": "Count"
                    },"ReturnData": true
                },{
                    "Id": "e1","Expression": "ANOMALY_DETECTION_BAND(m1)","Label": "cpuutilization (Expected)","ReturnData": true
                }
            ],"ThresholdMetricId": "e1"
        }
    ],"Compositealarms": []
}

解决方法

维度参数是将警报连接到指标的参数。此处维度参数的输出不显示任何内容。这意味着它与度量没有联系,因此没有图形线。维度输出应如下所示:

        "Dimensions": [
            {
                "Name": "InstanceId","Value": "i-xxxxxxxxxxxxx"
            },{
                "Name": "ImageId","Value": "ami-xxxxxxx"
            },{
                "Name": "path","Value": "<partition path ie: /home>"
            },{
                "Name": "InstanceType","Value": "<instance type ie: t2.small>"
            },{
                "Name": "device","Value": "<device name ie:mapper/primary-home>"
            },{
                "Name": "fstype","Value": "<filesystem type ie:ext4"
            }
        ],

如果您查看尝试使用的指标的来源,您将看到预期值。