简体   繁体   中英

Boto3 CloudWatch - put_metric_alarm with multiple metrics and a math expression

I am trying to create an alarm with Boto3 - CloudWatch - put_metric_alarm and having difficulties.

Here are the keyword arguments being supplied to the function:

{'ActionsEnabled': False,
 'AlarmDescription': 'Monitor for Idle instances',
 'AlarmName': 'IdleComponents',
 'ComparisonOperator': 'GreaterThanThreshold',
 'DatapointsToAlarm': 6,
 'EvaluationPeriods': 6,
 'Metrics': [{'Id': 'CPU',
              'MetricStat': {'Metric': {'Dimensions': [{'Name': 'InstanceId',
                                                        'Value': 'i-XX'}],
                                        'MetricName': 'CPUUtilization',
                                        'Namespace': 'AWS/EC2'},
                             'Period': 300,
                             'Stat': 'Average',
                             'Unit': 'Percent'},
              'ReturnData': False},
             {'Id': 'Net',
              'MetricStat': {'Metric': {'Dimensions': [{'Name': 'InstanceId',
                                                        'Value': 'i-XX'}],
                                        'MetricName': 'NetworkIn',
                                        'Namespace': 'AWS/EC2'},
                             'Period': 300,
                             'Stat': 'Average',
                             'Unit': 'Megabytes'},
              'ReturnData': False},
             {'Expression': 'IF(CPU < 5, 1, 0) AND IF(Net < 5, 1, 0)',
              'Id': 'e1',
              'ReturnData': True}],
 'Threshold': 0}

From visual inspection this appears to be a valid input, and the expression works as desired when creating it manually on the CloudWatch console, but when running this through Boto3 I get:

botocore.exceptions.ClientError: An error occurred (ValidationError) when calling the PutMetricAlarm operation: Invalid metrics list

The documentation here , claims that you may define an alarm such that you may use up to 10 metrics and 10 expressions, with one of the Metric queries returning data for the alarm.

I am not sure what I am doing wrong here. Thanks

Id 必须以小写字母开头,尝试将CPUNet更改为cpunet

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM